1 /*
2 Copyright (c) 2003, 2021, Oracle and/or its affiliates.
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_HEADER
26 #define ATTRIBUTE_HEADER
27
28 #define JAM_FILE_ID 6
29
30
31 /**
32 * @class AttributeHeader
33 * @brief Header passed in front of every attribute value in AttrInfo signal
34 */
35 class AttributeHeader {
36 friend class Dbtup;
37 friend class Backup;
38 friend class NdbOperation;
39 friend class DbUtil;
40 friend class Suma;
41
42 public:
43 /**
44 * Pseudo columns
45 */
46 STATIC_CONST( PSEUDO = 0x8000 );
47 STATIC_CONST( FRAGMENT = 0xFFFE ); // Read fragment no
48 STATIC_CONST( ROW_COUNT = 0xFFFD ); // Read row count (committed)
49 STATIC_CONST( COMMIT_COUNT = 0xFFFC ); // Read commit count
50 STATIC_CONST( RANGE_NO = 0xFFFB ); // Read range no (when batched ranges)
51
52 STATIC_CONST( ROW_SIZE = 0xFFFA );
53 STATIC_CONST( FRAGMENT_FIXED_MEMORY= 0xFFF9 );
54
55 STATIC_CONST( RECORDS_IN_RANGE = 0xFFF8 );
56 STATIC_CONST( DISK_REF = 0xFFF7 );
57 STATIC_CONST( ROWID = 0xFFF6 );
58 STATIC_CONST( ROW_GCI = 0xFFF5 );
59 STATIC_CONST( FRAGMENT_VARSIZED_MEMORY = 0xFFF4 );
60 STATIC_CONST( READ_PACKED = 0xFFF3 );
61 STATIC_CONST( ANY_VALUE = 0xFFF2 );
62 STATIC_CONST( COPY_ROWID = 0xFFF1 );
63 STATIC_CONST( READ_ALL = 0xFFF0 );
64 STATIC_CONST( READ_LCP = 0xFFEF );
65 STATIC_CONST( LOCK_REF = 0xFFEE ); // Operation lock reference
66 STATIC_CONST( OP_ID = 0xFFED ); // Operation runtime identity
67
68 // Extents * sizeof(Extent) allocated to fragment
69 STATIC_CONST( FRAGMENT_EXTENT_SPACE = 0xFFEC );
70
71 // Free but allocated DD extent space
72 STATIC_CONST( FRAGMENT_FREE_EXTENT_SPACE = 0xFFEB );
73
74 STATIC_CONST( FLUSH_AI = 0xFFEA );
75 STATIC_CONST( CORR_FACTOR32 = 0xFFE9 ); // excluding root-frag
76 STATIC_CONST( CORR_FACTOR64 = 0xFFE8 ); // including root-frag
77
78 /**
79 * 64-bit row gci (extending lower if not sufficient bits)
80 * read-only
81 */
82 STATIC_CONST( ROW_GCI64 = 0xFFE7);
83
84 /**
85 * Row author... autoset to 0, can be over written
86 */
87 STATIC_CONST( ROW_AUTHOR = 0xFFE6);
88
89 /**
90 * Optimize pseudo column and optimization options
91 */
92 STATIC_CONST( OPTIMIZE = 0xFFE0 ); //pseudo column id to optimize
93 STATIC_CONST( OPTIMIZE_OPTIONS_MASK = 0xFFFF ); //bitmask AND column value
94 STATIC_CONST( OPTIMIZE_MOVE_VARPART = 0x0001 ); //option to move varpart
95 STATIC_CONST( OPTIMIZE_MOVE_FIXPART = 0x0002 ); //option to move fixpart
96
97 // index stats pseudo columns
98 STATIC_CONST( INDEX_STAT_KEY = 0xFFD0 );
99 STATIC_CONST( INDEX_STAT_VALUE = 0xFFD1 );
100
101 // NOTE: in 5.1 ctors and init take size in bytes
102
103 /** Initialize AttributeHeader at location aHeaderPtr */
104 static void init(Uint32* aHeaderPtr, Uint32 anAttributeId, Uint32 aByteSize);
105
106 /** Returns size of AttributeHeader (usually one or two words) */
107 Uint32 getHeaderSize() const; // In 32-bit words
108
109 /** Store AttributeHeader in location given as argument */
110 void insertHeader(Uint32*);
111
112 /** Get next attribute header (if there is one) */
113 AttributeHeader* getNext() const;
114
115 /** Get location of attribute value */
116 Uint32* getDataPtr() const;
117
118 /** Getters and Setters */
119 Uint32 getAttributeId() const;
120 void setAttributeId(Uint32);
121 Uint32 getByteSize() const;
122 void setByteSize(Uint32);
123 Uint32 getDataSize() const; // In 32-bit words, rounded up
124 void setDataSize(Uint32); // Set size to multiple of word size
125 bool isNULL() const;
126 void setNULL();
127
128 /** Print **/
129 //void print(NdbOut&);
130 void print(FILE*);
131
132 static Uint32 getByteSize(Uint32);
133 static Uint32 getDataSize(Uint32);
134 static Uint32 getAttributeId(Uint32 id);
135
136 public:
137 AttributeHeader(Uint32 = 0);
138 AttributeHeader(Uint32 anAttributeId, Uint32 aByteSize);
139 ~AttributeHeader();
140
141 Uint32 m_value;
142 };
143
144 /**
145 * 1111111111222222222233
146 * 01234567890123456789012345678901
147 * ssssssssssssssssiiiiiiiiiiiiiiii
148 *
149 * i = Attribute Id
150 * s = Size of current "chunk" in bytes - 16 bits.
151 * To allow round up to word, max value is 0xFFFC (not checked).
152 * e - [ obsolete future ]
153 * Element data/Blob, read element of array
154 * If == 0 next data word contains attribute value.
155 * If == 1 next data word contains:
156 * For Array of Fixed size Elements
157 * Start Index (16 bit), Stop Index(16 bit)
158 * For Blob
159 * Start offset (32 bit) (length is defined in previous word)
160 *
161 * An attribute value equal to "null" is represented by setting s == 0.
162 */
163
164 inline
init(Uint32 * aHeaderPtr,Uint32 anAttributeId,Uint32 aByteSize)165 void AttributeHeader::init(Uint32* aHeaderPtr, Uint32 anAttributeId,
166 Uint32 aByteSize)
167 {
168 AttributeHeader ah(anAttributeId, aByteSize);
169 *aHeaderPtr = ah.m_value;
170 }
171
172 inline
AttributeHeader(Uint32 aHeader)173 AttributeHeader::AttributeHeader(Uint32 aHeader)
174 {
175 m_value = aHeader;
176 }
177
178 inline
AttributeHeader(Uint32 anAttributeId,Uint32 aByteSize)179 AttributeHeader::AttributeHeader(Uint32 anAttributeId, Uint32 aByteSize)
180 {
181 m_value = 0;
182 this->setAttributeId(anAttributeId);
183 this->setByteSize(aByteSize);
184 }
185
186 inline
~AttributeHeader()187 AttributeHeader::~AttributeHeader()
188 {}
189
190 inline
getHeaderSize() const191 Uint32 AttributeHeader::getHeaderSize() const
192 {
193 // Should check 'e' bit here
194 return 1;
195 }
196
197 inline
getAttributeId() const198 Uint32 AttributeHeader::getAttributeId() const
199 {
200 return (m_value & 0xFFFF0000) >> 16;
201 }
202
203 inline
setAttributeId(Uint32 anAttributeId)204 void AttributeHeader::setAttributeId(Uint32 anAttributeId)
205 {
206 m_value &= 0x0000FFFF; // Clear attribute id
207 m_value |= (anAttributeId << 16);
208 }
209
210 inline
getByteSize() const211 Uint32 AttributeHeader::getByteSize() const
212 {
213 return (m_value & 0xFFFF);
214 }
215
216 inline
setByteSize(Uint32 aByteSize)217 void AttributeHeader::setByteSize(Uint32 aByteSize)
218 {
219 m_value &= (~0xFFFF);
220 m_value |= aByteSize;
221 }
222
223 inline
getDataSize() const224 Uint32 AttributeHeader::getDataSize() const
225 {
226 return (((m_value & 0xFFFF) + 3) >> 2);
227 }
228
229 inline
setDataSize(Uint32 aDataSize)230 void AttributeHeader::setDataSize(Uint32 aDataSize)
231 {
232 m_value &= (~0xFFFF);
233 m_value |= (aDataSize << 2);
234 }
235
236 inline
isNULL() const237 bool AttributeHeader::isNULL() const
238 {
239 return (getDataSize() == 0);
240 }
241
242 inline
setNULL()243 void AttributeHeader::setNULL()
244 {
245 setDataSize(0);
246 }
247
248 inline
getDataPtr() const249 Uint32* AttributeHeader::getDataPtr() const
250 {
251 return (Uint32*)&m_value + getHeaderSize();
252 }
253
254 inline
insertHeader(Uint32 * target)255 void AttributeHeader::insertHeader(Uint32* target)
256 {
257 *target = m_value;
258 }
259
260 inline
261 AttributeHeader*
getNext() const262 AttributeHeader::getNext() const {
263 return (AttributeHeader*)(getDataPtr() + getDataSize());
264 }
265
266 inline
267 void
268 //AttributeHeader::print(NdbOut& output) {
print(FILE * output)269 AttributeHeader::print(FILE* output) {
270 fprintf(output, "AttributeId: H\'%.8x (D\'%d), DataSize: H\'%.8x (D\'%d), "
271 "isNULL: %d\n",
272 getAttributeId(), getAttributeId(),
273 getDataSize(), getDataSize(),
274 isNULL());
275 }
276
277 inline
278 Uint32
getByteSize(Uint32 m_value)279 AttributeHeader::getByteSize(Uint32 m_value){
280 return (m_value & 0xFFFF);
281 }
282
283 inline
284 Uint32
getDataSize(Uint32 m_value)285 AttributeHeader::getDataSize(Uint32 m_value){
286 return (((m_value & 0xFFFF) + 3) >> 2);
287 }
288
289 inline
290 Uint32
getAttributeId(Uint32 m_value)291 AttributeHeader::getAttributeId(Uint32 m_value)
292 {
293 return m_value >> 16;
294 }
295
296
297 #undef JAM_FILE_ID
298
299 #endif
300
301
302
303
304
305
306
307