1 /*
2 Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is also distributed with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have included with MySQL.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #ifndef ATTRIBUTE_DESCRIPTOR_HPP
26 #define ATTRIBUTE_DESCRIPTOR_HPP
27
28 #define JAM_FILE_ID 5
29
30
31 class AttributeDescriptor {
32 friend class Dbdict;
33 friend class Dbtc;
34 friend class Dbacc;
35 friend class Dbtup;
36 friend class Dbtux;
37 friend class Dblqh;
38 friend class SimulatedBlock;
39
40 public:
41 static void setType(Uint32 &, Uint32 type);
42 static void setSize(Uint32 &, Uint32 size);
43 static void setArrayType(Uint32 &, Uint32 arrayType);
44 static void setArraySize(Uint32 &, Uint32 arraySize);
45 static void setNullable(Uint32 &, Uint32 nullable);
46 static void setDKey(Uint32 &, Uint32 dkey);
47 static void setPrimaryKey(Uint32 &, Uint32 dkey);
48 static void setDynamic(Uint32 &, Uint32 dynamicInd);
49 static void setDiskBased(Uint32 &, Uint32 val);
50
51 static Uint32 getType(const Uint32 &);
52 static Uint32 getSize(const Uint32 &);
53 static Uint32 getSizeInBytes(const Uint32 &);
54 static Uint32 getSizeInWords(const Uint32 &);
55 static Uint32 getArrayType(const Uint32 &);
56 static Uint32 getArraySize(const Uint32 &);
57 static Uint32 getNullable(const Uint32 &);
58 static Uint32 getDKey(const Uint32 &);
59 static Uint32 getPrimaryKey(const Uint32 &);
60 static Uint32 getDynamic(const Uint32 &);
61 static Uint32 getDiskBased(const Uint32 &);
62
63 static void clearArrayType(Uint32 &);
64
65 Uint32 m_data;
66 };
67
68 /**
69 *
70 * a = Array type - 2 Bits -> Max 3 (Bit 0-1)
71 * t = Attribute type - 6 Bits -> Max 63 (Bit 2-7)
72 * s = Attribute size - 3 Bits -> Max 7 (Bit 8-10)
73 * 0 is for bit types, stored in bitmap
74 * 1-2 unused
75 * 3 for byte-sized (char...)
76 * 4 for 16-bit sized
77 * etc.
78 * d = Disk based - 1 Bit 11
79 * n = Nullable - 1 Bit 12
80 * k = Distribution Key Ind - 1 Bit 13
81 * p = Primary key attribute - 1 Bit 14
82 * y = Dynamic attribute - 1 Bit 15
83 * z = Array size - 16 Bits -> Max 65535 (Bit 16-31)
84 * Element size is determined by attribute size
85 *
86 * 1111111111222222222233
87 * 01234567890123456789012345678901
88 * aattttttsssdnkpyzzzzzzzzzzzzzzzz
89 * aattsss n d k pyzzzzzzzzzzzzzzzz [ old format ]
90 *
91 */
92
93 #define AD_ARRAY_TYPE_SHIFT (0)
94 #define AD_ARRAY_TYPE_MASK (3)
95
96 #define AD_TYPE_SHIFT (2)
97 #define AD_TYPE_MASK (63)
98
99 #define AD_SIZE_SHIFT (8)
100 #define AD_SIZE_MASK (7)
101
102 #define AD_SIZE_IN_BYTES_SHIFT (3)
103 #define AD_SIZE_IN_WORDS_OFFSET (31)
104 #define AD_SIZE_IN_WORDS_SHIFT (5)
105
106 #define AD_DISK_SHIFT (11)
107 #define AD_NULLABLE_SHIFT (12)
108 #define AD_DISTR_KEY_SHIFT (13)
109 #define AD_PRIMARY_KEY (14)
110 #define AD_DYNAMIC (15)
111
112 #define AD_ARRAY_SIZE_SHIFT (16)
113 #define AD_ARRAY_SIZE_MASK (65535)
114
115 inline
116 void
setType(Uint32 & desc,Uint32 type)117 AttributeDescriptor::setType(Uint32 & desc, Uint32 type){
118 assert(type <= AD_TYPE_MASK);
119 desc |= (type << AD_TYPE_SHIFT);
120 }
121
122 inline
123 void
setSize(Uint32 & desc,Uint32 size)124 AttributeDescriptor::setSize(Uint32 & desc, Uint32 size){
125 assert(size <= AD_SIZE_MASK);
126 desc |= (size << AD_SIZE_SHIFT);
127 }
128
129 inline
130 void
setArrayType(Uint32 & desc,Uint32 arrayType)131 AttributeDescriptor::setArrayType(Uint32 & desc, Uint32 arrayType){
132 assert(arrayType <= AD_ARRAY_TYPE_MASK);
133 desc |= (arrayType << AD_ARRAY_TYPE_SHIFT);
134 }
135
136 inline
137 void
clearArrayType(Uint32 & desc)138 AttributeDescriptor::clearArrayType(Uint32 & desc)
139 {
140 desc &= ~Uint32(AD_ARRAY_TYPE_MASK << AD_ARRAY_TYPE_SHIFT);
141 }
142
143 inline
144 void
setArraySize(Uint32 & desc,Uint32 arraySize)145 AttributeDescriptor::setArraySize(Uint32 & desc, Uint32 arraySize){
146 assert(arraySize <= AD_ARRAY_SIZE_MASK);
147 desc |= (arraySize << AD_ARRAY_SIZE_SHIFT);
148 }
149
150 inline
151 void
setNullable(Uint32 & desc,Uint32 nullable)152 AttributeDescriptor::setNullable(Uint32 & desc, Uint32 nullable){
153 assert(nullable <= 1);
154 desc |= (nullable << AD_NULLABLE_SHIFT);
155 }
156
157 inline
158 void
setDKey(Uint32 & desc,Uint32 dkey)159 AttributeDescriptor::setDKey(Uint32 & desc, Uint32 dkey){
160 assert(dkey <= 1);
161 desc |= (dkey << AD_DISTR_KEY_SHIFT);
162 }
163
164 inline
165 void
setPrimaryKey(Uint32 & desc,Uint32 dkey)166 AttributeDescriptor::setPrimaryKey(Uint32 & desc, Uint32 dkey){
167 assert(dkey <= 1);
168 desc |= (dkey << AD_PRIMARY_KEY);
169 }
170
171 inline
172 void
setDynamic(Uint32 & desc,Uint32 dynamic)173 AttributeDescriptor::setDynamic(Uint32 & desc, Uint32 dynamic){
174 assert(dynamic <= 1);
175 desc |= (dynamic << AD_DYNAMIC);
176 }
177
178 inline
179 void
setDiskBased(Uint32 & desc,Uint32 val)180 AttributeDescriptor::setDiskBased(Uint32 & desc, Uint32 val)
181 {
182 assert(val <= 1);
183 desc |= (val << AD_DISK_SHIFT);
184 }
185
186 /**
187 * Getters
188 */
189 inline
190 Uint32
getType(const Uint32 & desc)191 AttributeDescriptor::getType(const Uint32 & desc){
192 return (desc >> AD_TYPE_SHIFT) & AD_TYPE_MASK;
193 }
194
195 inline
196 Uint32
getSize(const Uint32 & desc)197 AttributeDescriptor::getSize(const Uint32 & desc){
198 return (desc >> AD_SIZE_SHIFT) & AD_SIZE_MASK;
199 }
200
201 inline
202 Uint32
getSizeInBytes(const Uint32 & desc)203 AttributeDescriptor::getSizeInBytes(const Uint32 & desc){
204 return (getArraySize(desc) << getSize(desc))
205 >> AD_SIZE_IN_BYTES_SHIFT;
206 }
207
208 inline
209 Uint32
getSizeInWords(const Uint32 & desc)210 AttributeDescriptor::getSizeInWords(const Uint32 & desc){
211 return ((getArraySize(desc) << getSize(desc))
212 + AD_SIZE_IN_WORDS_OFFSET)
213 >> AD_SIZE_IN_WORDS_SHIFT;
214 }
215
216 inline
217 Uint32
getArrayType(const Uint32 & desc)218 AttributeDescriptor::getArrayType(const Uint32 & desc){
219 return (desc >> AD_ARRAY_TYPE_SHIFT) & AD_ARRAY_TYPE_MASK;
220 }
221
222 inline
223 Uint32
getArraySize(const Uint32 & desc)224 AttributeDescriptor::getArraySize(const Uint32 & desc){
225 return (desc >> AD_ARRAY_SIZE_SHIFT) & AD_ARRAY_SIZE_MASK;
226 }
227
228 inline
229 Uint32
getNullable(const Uint32 & desc)230 AttributeDescriptor::getNullable(const Uint32 & desc){
231 return (desc >> AD_NULLABLE_SHIFT) & 1;
232 }
233
234 inline
235 Uint32
getDKey(const Uint32 & desc)236 AttributeDescriptor::getDKey(const Uint32 & desc){
237 return (desc >> AD_DISTR_KEY_SHIFT) & 1;
238 }
239
240 inline
241 Uint32
getPrimaryKey(const Uint32 & desc)242 AttributeDescriptor::getPrimaryKey(const Uint32 & desc){
243 return (desc >> AD_PRIMARY_KEY) & 1;
244 }
245
246 inline
247 Uint32
getDynamic(const Uint32 & desc)248 AttributeDescriptor::getDynamic(const Uint32 & desc){
249 return (desc >> AD_DYNAMIC) & 1;
250 }
251
252 inline
253 Uint32
getDiskBased(const Uint32 & desc)254 AttributeDescriptor::getDiskBased(const Uint32 & desc)
255 {
256 return (desc >> AD_DISK_SHIFT) & 1;
257 }
258
259 class NdbOut&
260 operator<<(class NdbOut&, const AttributeDescriptor&);
261
262
263 #undef JAM_FILE_ID
264
265 #endif
266