MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DictTabInfo.cpp
1 /*
2  Copyright (c) 2003, 2010, 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 as published by
6  the Free Software Foundation; version 2 of the License.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #include <signaldata/DictTabInfo.hpp>
19 #include <ndb_limits.h>
20 
21 //static
22 const
24 DictTabInfo::TableMapping[] = {
25  DTIMAPS(Table, TableName, TableName, 0, MAX_TAB_NAME_SIZE),
26  DTIMAP(Table, TableId, TableId),
27  DTIMAPS(Table, PrimaryTable, PrimaryTable, 0, MAX_TAB_NAME_SIZE),
28  DTIMAP(Table, PrimaryTableId, PrimaryTableId),
29  DTIMAP2(Table, TableLoggedFlag, TableLoggedFlag, 0, 1),
30  DTIMAP2(Table, TableTemporaryFlag, TableTemporaryFlag, 0, 1),
31  DTIMAP2(Table, ForceVarPartFlag, ForceVarPartFlag, 0, 1),
32  DTIMAP2(Table, TableKValue, TableKValue, 6, 6),
33  DTIMAP2(Table, MinLoadFactor, MinLoadFactor, 0, 90),
34  DTIMAP2(Table, MaxLoadFactor, MaxLoadFactor, 25, 110),
35  DTIMAP2(Table, FragmentTypeVal, FragmentType, 0, 3),
36  DTIMAP2(Table, TableTypeVal, TableType, 1, 3),
37  DTIMAP(Table, NoOfKeyAttr, NoOfKeyAttr),
38  DTIMAP2(Table, NoOfAttributes, NoOfAttributes, 1, MAX_ATTRIBUTES_IN_TABLE),
39  DTIMAP(Table, NoOfNullable, NoOfNullable),
40  DTIMAP2(Table, NoOfVariable, NoOfVariable, 0, 0),
41  DTIMAP(Table, KeyLength, KeyLength),
42  DTIMAP(Table, TableVersion, TableVersion),
43  DTIMAP(Table, IndexState, IndexState),
44  DTIMAP(Table, InsertTriggerId, InsertTriggerId),
45  DTIMAP(Table, UpdateTriggerId, UpdateTriggerId),
46  DTIMAP(Table, DeleteTriggerId, DeleteTriggerId),
47  DTIMAP(Table, CustomTriggerId, CustomTriggerId),
48  DTIMAP2(Table, FrmLen, FrmLen, 0, MAX_FRM_DATA_SIZE),
49  DTIMAPB(Table, FrmData, FrmData, 0, MAX_FRM_DATA_SIZE, FrmLen),
50  DTIMAP2(Table, FragmentCount, FragmentCount, 0, MAX_NDB_PARTITIONS),
51  DTIMAP2(Table, ReplicaDataLen, ReplicaDataLen, 0, 2*MAX_FRAGMENT_DATA_BYTES),
52  DTIMAPB(Table, ReplicaData, ReplicaData, 0, 2*MAX_FRAGMENT_DATA_BYTES, ReplicaDataLen),
53  DTIMAP2(Table, FragmentDataLen, FragmentDataLen, 0, 6*MAX_NDB_PARTITIONS),
54  DTIMAPB(Table, FragmentData, FragmentData, 0, 6*MAX_NDB_PARTITIONS, FragmentDataLen),
55  DTIMAP2(Table, TablespaceDataLen, TablespaceDataLen, 0, 8*MAX_NDB_PARTITIONS),
56  DTIMAPB(Table, TablespaceData, TablespaceData, 0, 8*MAX_NDB_PARTITIONS, TablespaceDataLen),
57  DTIMAP2(Table, RangeListDataLen, RangeListDataLen, 0, 8*MAX_NDB_PARTITIONS),
58  DTIMAPB(Table, RangeListData, RangeListData, 0, 8*MAX_NDB_PARTITIONS, RangeListDataLen),
59  DTIMAP(Table, TablespaceId, TablespaceId),
60  DTIMAP(Table, TablespaceVersion, TablespaceVersion),
61  DTIMAP(Table, MaxRowsLow, MaxRowsLow),
62  DTIMAP(Table, MaxRowsHigh, MaxRowsHigh),
63  DTIMAP(Table, DefaultNoPartFlag, DefaultNoPartFlag),
64  DTIMAP(Table, LinearHashFlag, LinearHashFlag),
65  DTIMAP(Table, TablespaceVersion, TablespaceVersion),
66  DTIMAP(Table, RowGCIFlag, RowGCIFlag),
67  DTIMAP(Table, RowChecksumFlag, RowChecksumFlag),
68  DTIMAP(Table, MaxRowsLow, MaxRowsLow),
69  DTIMAP(Table, MaxRowsHigh, MaxRowsHigh),
70  DTIMAP(Table, MinRowsLow, MinRowsLow),
71  DTIMAP(Table, MinRowsHigh, MinRowsHigh),
72  DTIMAP(Table, SingleUserMode, SingleUserMode),
73  DTIMAP(Table, HashMapObjectId, HashMapObjectId),
74  DTIMAP(Table, HashMapVersion, HashMapVersion),
75  DTIMAP(Table, TableStorageType, TableStorageType),
76  DTIMAP(Table, ExtraRowGCIBits, ExtraRowGCIBits),
77  DTIMAP(Table, ExtraRowAuthorBits, ExtraRowAuthorBits),
78  DTIBREAK(AttributeName)
79 };
80 
81 //static
82 const Uint32 DictTabInfo::TableMappingSize =
83 sizeof(DictTabInfo::TableMapping) / sizeof(SimpleProperties::SP2StructMapping);
84 
85 //static
86 const
88 DictTabInfo::AttributeMapping[] = {
89  DTIMAPS(Attribute, AttributeName, AttributeName, 0, MAX_ATTR_NAME_SIZE),
90  DTIMAP(Attribute, AttributeId, AttributeId),
91  DTIMAP(Attribute, AttributeType, AttributeType),
92  DTIMAP2(Attribute, AttributeSize, AttributeSize, 3, 7),
93  DTIMAP2(Attribute, AttributeArraySize, AttributeArraySize, 0, 65535),
94  DTIMAP2(Attribute, AttributeArrayType, AttributeArrayType, 0, 3),
95  DTIMAP2(Attribute, AttributeKeyFlag, AttributeKeyFlag, 0, 1),
96  DTIMAP2(Attribute, AttributeNullableFlag, AttributeNullableFlag, 0, 1),
97  DTIMAP2(Attribute, AttributeDKey, AttributeDKey, 0, 1),
98  DTIMAP2(Attribute, AttributeStorageType, AttributeStorageType, 0, 1),
99  DTIMAP2(Attribute, AttributeDynamic, AttributeDynamic, 0, 1),
100  DTIMAP(Attribute, AttributeExtType, AttributeExtType),
101  DTIMAP(Attribute, AttributeExtPrecision, AttributeExtPrecision),
102  DTIMAP(Attribute, AttributeExtScale, AttributeExtScale),
103  DTIMAP(Attribute, AttributeExtLength, AttributeExtLength),
104  DTIMAP2(Attribute, AttributeAutoIncrement, AttributeAutoIncrement, 0, 1),
105 
106  DTIMAP2(Attribute, AttributeDefaultValueLen, AttributeDefaultValueLen,
107  0, MAX_ATTR_DEFAULT_VALUE_SIZE),
108  DTIMAPB(Attribute, AttributeDefaultValue, AttributeDefaultValue,
109  0, MAX_ATTR_DEFAULT_VALUE_SIZE, AttributeDefaultValueLen),
110 
111  DTIBREAK(AttributeEnd)
112 };
113 
114 //static
115 const Uint32 DictTabInfo::AttributeMappingSize =
116 sizeof(DictTabInfo::AttributeMapping) /
118 
119 bool printDICTTABINFO(FILE * output, const Uint32 * theData,
120  Uint32 len, Uint16 receiverBlockNo)
121 {
122 // const DictTabInfo * const sig = (DictTabInfo *) theData;
123 
124  fprintf(output, "Signal data: ");
125  Uint32 i = 0;
126  while (i < len)
127  fprintf(output, "H\'%.8x ", theData[i++]);
128  fprintf(output,"\n");
129  return true;
130 }
131 
132 void
133 DictTabInfo::Table::init(){
134  memset(TableName, 0, sizeof(TableName));//TableName[0] = 0;
135  TableId = ~0;
136  memset(PrimaryTable, 0, sizeof(PrimaryTable));//PrimaryTable[0] = 0; // Only used when "index"
137  PrimaryTableId = RNIL;
138  TableLoggedFlag = 1;
139  TableTemporaryFlag = 0;
140  ForceVarPartFlag = 0;
141  NoOfKeyAttr = 0;
142  NoOfAttributes = 0;
143  NoOfNullable = 0;
144  NoOfVariable = 0;
145  TableKValue = 6;
146  MinLoadFactor = 78;
147  MaxLoadFactor = 80;
148  KeyLength = 0;
149  FragmentType = DictTabInfo::HashMapPartition;
150  TableType = DictTabInfo::UndefTableType;
151  TableVersion = 0;
152  IndexState = ~0;
153  InsertTriggerId = RNIL;
154  UpdateTriggerId = RNIL;
155  DeleteTriggerId = RNIL;
156  CustomTriggerId = RNIL;
157  FrmLen = 0;
158  FragmentDataLen = 0;
159  ReplicaDataLen = 0;
160  RangeListDataLen = 0;
161  TablespaceDataLen = 0;
162  memset(FrmData, 0, sizeof(FrmData));
163  memset(FragmentData, 0, sizeof(FragmentData));
164  memset(ReplicaData, 0, sizeof(ReplicaData));
165  memset(RangeListData, 0, sizeof(RangeListData));
166  memset(TablespaceData, 0, sizeof(TablespaceData));
167  FragmentCount = 0;
168  TablespaceId = RNIL;
169  TablespaceVersion = ~0;
170  MaxRowsLow = 0;
171  MaxRowsHigh = 0;
172  DefaultNoPartFlag = 1;
173  LinearHashFlag = 1;
174 
175  RowGCIFlag = ~0;
176  RowChecksumFlag = ~0;
177 
178  MaxRowsLow = 0;
179  MaxRowsHigh = 0;
180  MinRowsLow = 0;
181  MinRowsHigh = 0;
182 
183  SingleUserMode = 0;
184 
185  HashMapObjectId = RNIL;
186  HashMapVersion = RNIL;
187 
188  TableStorageType = NDB_STORAGETYPE_DEFAULT;
189 
190  ExtraRowGCIBits = 0;
191  ExtraRowAuthorBits = 0;
192 }
193 
194 void
195 DictTabInfo::Attribute::init(){
196  memset(AttributeName, 0, sizeof(AttributeName));//AttributeName[0] = 0;
197  AttributeId = 0xFFFF; // ZNIL
198  AttributeType = ~0, // deprecated
199  AttributeSize = DictTabInfo::a32Bit;
200  AttributeArraySize = 1;
201  AttributeArrayType = NDB_ARRAYTYPE_FIXED;
202  AttributeKeyFlag = 0;
203  AttributeNullableFlag = 0;
204  AttributeDKey = 0;
205  AttributeExtType = DictTabInfo::ExtUnsigned,
206  AttributeExtPrecision = 0,
207  AttributeExtScale = 0,
208  AttributeExtLength = 0,
209  AttributeAutoIncrement = false;
210  AttributeStorageType = 0;
211  AttributeDynamic = 0; // Default is not dynamic
212  AttributeDefaultValueLen = 0; //Default byte sizes of binary default value is 0
213  memset(AttributeDefaultValue, 0, sizeof(AttributeDefaultValue));
214 }
215 
216 //static
217 const
219 DictFilegroupInfo::Mapping[] = {
220  DFGIMAPS(Filegroup, FilegroupName, FilegroupName, 0, MAX_TAB_NAME_SIZE),
221  DFGIMAP2(Filegroup, FilegroupType, FilegroupType, 0, 1),
222  DFGIMAP(Filegroup, FilegroupId, FilegroupId),
223  DFGIMAP(Filegroup, FilegroupVersion, FilegroupVersion),
224 
225  DFGIMAP(Filegroup, TS_ExtentSize, TS_ExtentSize),
226  DFGIMAP(Filegroup, TS_LogfileGroupId, TS_LogfileGroupId),
227  DFGIMAP(Filegroup, TS_LogfileGroupVersion, TS_LogfileGroupVersion),
228  DFGIMAP(Filegroup, TS_GrowLimit, TS_DataGrow.GrowLimit),
229  DFGIMAP(Filegroup, TS_GrowSizeHi, TS_DataGrow.GrowSizeHi),
230  DFGIMAP(Filegroup, TS_GrowSizeLo, TS_DataGrow.GrowSizeLo),
231  DFGIMAPS(Filegroup, TS_GrowPattern, TS_DataGrow.GrowPattern, 0, PATH_MAX),
232  DFGIMAP(Filegroup, TS_GrowMaxSize, TS_DataGrow.GrowMaxSize),
233 
234  DFGIMAP(Filegroup, LF_UndoBufferSize, LF_UndoBufferSize),
235  DFGIMAP(Filegroup, LF_UndoGrowLimit, LF_UndoGrow.GrowLimit),
236  DFGIMAP(Filegroup, LF_UndoGrowSizeHi, LF_UndoGrow.GrowSizeHi),
237  DFGIMAP(Filegroup, LF_UndoGrowSizeLo, LF_UndoGrow.GrowSizeLo),
238  DFGIMAPS(Filegroup, LF_UndoGrowPattern, LF_UndoGrow.GrowPattern, 0,PATH_MAX),
239  DFGIMAP(Filegroup, LF_UndoGrowMaxSize, LF_UndoGrow.GrowMaxSize),
240  DFGIMAP(Filegroup, LF_UndoFreeWordsHi, LF_UndoFreeWordsHi),
241  DFGIMAP(Filegroup, LF_UndoFreeWordsLo, LF_UndoFreeWordsLo),
242 
243  DFGIBREAK(FileName)
244 };
245 
246 //static
247 const Uint32 DictFilegroupInfo::MappingSize =
248 sizeof(DictFilegroupInfo::Mapping) / sizeof(SimpleProperties::SP2StructMapping);
249 
250 //static
251 const
253 DictFilegroupInfo::FileMapping[] = {
254  DFGIMAPS(File, FileName, FileName, 0, PATH_MAX),
255  DFGIMAP2(File, FileType, FileType, 0, 1),
256  DFGIMAP(File, FileId, FileId),
257  DFGIMAP(File, FileVersion, FileVersion),
258  DFGIMAP(File, FileFGroupId, FilegroupId),
259  DFGIMAP(File, FileFGroupVersion, FilegroupVersion),
260  DFGIMAP(File, FileSizeHi, FileSizeHi),
261  DFGIMAP(File, FileSizeLo, FileSizeLo),
262  DFGIMAP(File, FileFreeExtents, FileFreeExtents),
263  DFGIBREAK(FileEnd)
264 };
265 
266 //static
267 const Uint32 DictFilegroupInfo::FileMappingSize =
268 sizeof(DictFilegroupInfo::FileMapping) /
270 
271 void
272 DictFilegroupInfo::Filegroup::init(){
273  memset(FilegroupName, 0, sizeof(FilegroupName));
274  FilegroupType = ~0;
275  FilegroupId = ~0;
276  FilegroupVersion = ~0;
277 
278  TS_ExtentSize = 0;
279  TS_LogfileGroupId = ~0;
280  TS_LogfileGroupVersion = ~0;
281  TS_DataGrow.GrowLimit = 0;
282  TS_DataGrow.GrowSizeHi = 0;
283  TS_DataGrow.GrowSizeLo = 0;
284  memset(TS_DataGrow.GrowPattern, 0, sizeof(TS_DataGrow.GrowPattern));
285  TS_DataGrow.GrowMaxSize = 0;
286  LF_UndoFreeWordsHi= 0;
287  LF_UndoFreeWordsLo= 0;
288 }
289 
290 void
291 DictFilegroupInfo::File::init(){
292  memset(FileName, 0, sizeof(FileName));
293  FileType = ~0;
294  FileId = ~0;
295  FileVersion = ~0;
296  FilegroupId = ~0;
297  FilegroupVersion = ~0;
298  FileSizeHi = 0;
299  FileSizeLo = 0;
300  FileFreeExtents = 0;
301 }
302 
303 // blob table name hack
304 
305 bool
306 DictTabInfo::isBlobTableName(const char* name, Uint32* ptab_id, Uint32* pcol_no)
307 {
308  const char* const prefix = "NDB$BLOB_";
309  const char* s = strrchr(name, table_name_separator);
310  s = (s == NULL ? name : s + 1);
311  if (strncmp(s, prefix, strlen(prefix)) != 0)
312  return false;
313  s += strlen(prefix);
314  uint i, n;
315  for (i = 0, n = 0; '0' <= s[i] && s[i] <= '9'; i++)
316  n = 10 * n + (s[i] - '0');
317  if (i == 0 || s[i] != '_')
318  return false;
319  const uint tab_id = n;
320  s = &s[i + 1];
321  for (i = 0, n = 0; '0' <= s[i] && s[i] <= '9'; i++)
322  n = 10 * n + (s[i] - '0');
323  if (i == 0 || s[i] != 0)
324  return false;
325  const uint col_no = n;
326  if (ptab_id)
327  *ptab_id = tab_id;
328  if (pcol_no)
329  *pcol_no = col_no;
330  return true;
331 }
332 
336 const
339  DHMIMAPS(HashMap, HashMapName, HashMapName, 0, MAX_TAB_NAME_SIZE),
340  DHMIMAP2(HashMap, HashMapBuckets, HashMapBuckets, 0, 256),
341  DTIMAP(HashMap, HashMapObjectId, HashMapObjectId),
342  DTIMAP(HashMap, HashMapVersion, HashMapVersion),
343 
347  DHMIMAPB(HashMap, HashMapValues, HashMapValues, 0, 256*2, HashMapBuckets)
348 };
349 
350 //static
351 const Uint32 DictHashMapInfo::MappingSize =
352  sizeof(DictHashMapInfo::Mapping) / sizeof(SimpleProperties::SP2StructMapping);
353 
354 
355 void
356 DictHashMapInfo::HashMap::init()
357 {
358  bzero(this, sizeof(* this));
359 }