MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NDBT_Tables.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 <NDBT.hpp>
19 #include <NDBT_Table.hpp>
20 #include <NDBT_Tables.hpp>
21 #include <NdbEnv.h>
22 
23 /* ******************************************************* */
24 // Define Ndb standard tables
25 //
26 // USE ONLY UPPERLETTERS IN TAB AND COLUMN NAMES
27 /* ******************************************************* */
28 
29 static const NdbDictionary::Column::StorageType MM=
30  NdbDictionary::Column::StorageTypeMemory;
31 static const NdbDictionary::Column::StorageType DD=
32  NdbDictionary::Column::StorageTypeDisk;
33 
34 /*
35  * These are our "official" test tables
36  *
37  */
38 /* T1 */
39 static
40 const
41 NDBT_Attribute T1Attribs[] = {
47 };
48 static
49 const
50 NDBT_Table T1("T1", sizeof(T1Attribs)/sizeof(NDBT_Attribute), T1Attribs);
51 
52 static
53 const
54 NDBT_Attribute T2Attribs[] = {
62 };
63 
64 static
65 const
66 NDBT_Table T2("T2", sizeof(T2Attribs)/sizeof(NDBT_Attribute), T2Attribs);
67 
68 static
69 const
70 NDBT_Attribute T3Attribs[] = {
122 
125 };
126 
127 static
128 const
129 NDBT_Table T3("T3", sizeof(T3Attribs)/sizeof(NDBT_Attribute), T3Attribs);
130 
131 /* T4 */
132 static
133 const
134 NDBT_Attribute T4Attribs[] = {
135  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true, false, 0, MM, true),
136  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, false, false, 0, MM, true),
137  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned, 1, false, false, 0, MM, true),
138  NDBT_Attribute("KOL4", NdbDictionary::Column::Unsigned, 1, false, true, 0, MM, true),
139  NDBT_Attribute("KOL5", NdbDictionary::Column::Unsigned, 1, false, false, 0, MM, true)
140 };
141 
142 static
143 const
144 NDBT_Table T4("T4", sizeof(T4Attribs)/sizeof(NDBT_Attribute), T4Attribs);
145 
146 
147 
148 /* T6 */
149 static
150 const
151 NDBT_Attribute T6Attribs[] = {
157  47, false, true),// Nullable
161  48, false, true),// Nullable
163  50, false, true), // Nullable
176  NDBT_Attribute("ATTR21", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
177  NDBT_Attribute("ATTR22", NdbDictionary::Column::Varbinary, 255, false, false, 0, MM, true)
178 };
179 
180 static
181 const
182 NDBT_Table T6("T6", sizeof(T6Attribs)/sizeof(NDBT_Attribute), T6Attribs);
183 
184 /* T13 - Long key table */
185 static
186 const
187 NDBT_Attribute T13Attribs[] = {
188  NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 257, true),
189  NDBT_Attribute("KOL2", NdbDictionary::Column::Char, 259, true),
190  NDBT_Attribute("KOL3", NdbDictionary::Column::Char, 113, true),
194 };
195 static
196 const
197 NDBT_Table T13("T13", sizeof(T13Attribs)/sizeof(NDBT_Attribute), T13Attribs);
198 
199 
200 /* T14 - 5 primary keys */
201 static
202 const
203 NDBT_Attribute T14Attribs[] = {
206  NDBT_Attribute("KOL3", NdbDictionary::Column::Char, 4, true),
212  NDBT_Attribute("KOL50", NdbDictionary::Column::Char, 200, false, false, 0, MM, true)
213 };
214 
215 
216 static
217 const
218 NDBT_Table T14("T14", sizeof(T14Attribs)/sizeof(NDBT_Attribute), T14Attribs);
219 
220 /*
221  T15 - Dynamic attributes.
222  Test many different combinations of attribute types, sizes, and NULLability.
223  Also exersize >32bit dynattr bitmap.
224 */
225 static
226 const
227 NDBT_Attribute T15Attribs[] = {
228  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true, false, 0, MM, true),
229  NDBT_Attribute("KOL2", NdbDictionary::Column::Varbinary, 100, false, true, 0, MM, true),
230  NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned, 1, false, true, 0, MM, true),
231  NDBT_Attribute("KOL4", NdbDictionary::Column::Int, 1, false, false, 0, MM, true),
232  NDBT_Attribute("KOL5", NdbDictionary::Column::Float, 1, false, true, 0, MM, true),
233  NDBT_Attribute("KOL6", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
234  NDBT_Attribute("KOL7", NdbDictionary::Column::Varbinary, 4, false, true, 0, MM, true),
235  NDBT_Attribute("KOL8", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
236  NDBT_Attribute("KOL9", NdbDictionary::Column::Varbinary, 4, false, true, 0, MM, true),
237  NDBT_Attribute("KOL10", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
238  NDBT_Attribute("KOL11", NdbDictionary::Column::Varbinary, 4, false, true, 0, MM, true),
239  NDBT_Attribute("KOL12", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
240  NDBT_Attribute("KOL13", NdbDictionary::Column::Varbinary, 4, false, true, 0, MM, true),
241  NDBT_Attribute("KOL14", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
242  NDBT_Attribute("KOL15", NdbDictionary::Column::Varbinary, 4, false, true, 0, MM, true),
243  NDBT_Attribute("KOL16", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
244  NDBT_Attribute("KOL17", NdbDictionary::Column::Varbinary, 4, false, true, 0, MM, true),
245  NDBT_Attribute("KOL18", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
246  NDBT_Attribute("KOL19", NdbDictionary::Column::Varbinary, 4, false, true, 0, MM, true),
247  NDBT_Attribute("KOL20", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
248  NDBT_Attribute("KOL21", NdbDictionary::Column::Varbinary, 4, false, true, 0, MM, true),
249  NDBT_Attribute("KOL22", NdbDictionary::Column::Char, 4, false, false, 0, MM, true),
250  NDBT_Attribute("KOL23", NdbDictionary::Column::Varbinary, 4, false, false, 0, MM, true),
251  NDBT_Attribute("KOL24", NdbDictionary::Column::Char, 4, false, false, 0, MM, true),
252  NDBT_Attribute("KOL25", NdbDictionary::Column::Varbinary, 4, false, false, 0, MM, true),
253  NDBT_Attribute("KOL26", NdbDictionary::Column::Char, 4, false, false, 0, MM, true),
254  NDBT_Attribute("KOL27", NdbDictionary::Column::Varbinary, 4, false, false, 0, MM, true),
255  NDBT_Attribute("KOL28", NdbDictionary::Column::Char, 4, false, false),
256  NDBT_Attribute("KOL29", NdbDictionary::Column::Varbinary, 4, false, false),
257  NDBT_Attribute("KOL30", NdbDictionary::Column::Char, 4, false, true, 0, DD),
258  NDBT_Attribute("KOL31", NdbDictionary::Column::Char, 4, false, false, 0, MM, true),
259  NDBT_Attribute("KOL32", NdbDictionary::Column::Varbinary, 4, false, false, 0, MM, true),
260  NDBT_Attribute("BIT1", NdbDictionary::Column::Bit, 27, false, true, 0, MM, true),
261  NDBT_Attribute("BIT2", NdbDictionary::Column::Bit, 1, false, false, 0, MM, true),
262  NDBT_Attribute("BIT3", NdbDictionary::Column::Bit, 1, false, true, 0, MM, true),
263  NDBT_Attribute("BIT4", NdbDictionary::Column::Bit, 8, false, false, 0, MM, true),
264  NDBT_Attribute("KOL33", NdbDictionary::Column::Char, 4, false, false, 0, MM, true),
265  NDBT_Attribute("KOL34", NdbDictionary::Column::Varbinary, 4, false, false, 0, MM, true),
266  NDBT_Attribute("KOL35", NdbDictionary::Column::Char, 4, false, false, 0, MM, true),
267  NDBT_Attribute("KOL36", NdbDictionary::Column::Varbinary, 4, false, false, 0, MM, true),
268  NDBT_Attribute("KOL37", NdbDictionary::Column::Char, 4, false, false, 0, MM, true),
269  NDBT_Attribute("KOL38", NdbDictionary::Column::Varbinary, 4, false, false, 0, MM, true),
270  NDBT_Attribute("KOL39", NdbDictionary::Column::Char, 4, false, false, 0, MM, true),
271  NDBT_Attribute("KOL40", NdbDictionary::Column::Varbinary, 4, false, false, 0, MM, true),
272  NDBT_Attribute("KOL41", NdbDictionary::Column::Char, 64, false, true, 0, MM, true),
273  NDBT_Attribute("KOL42", NdbDictionary::Column::Char, 4, false, true, 0, MM, true),
274  NDBT_Attribute("KOL43", NdbDictionary::Column::Char, 8, false, true, 0, MM, true),
275  NDBT_Attribute("KOL44", NdbDictionary::Column::Char, 27, false, true, 0, MM, true),
276  NDBT_Attribute("KOL45", NdbDictionary::Column::Char, 64, false, false, 0, MM, true),
277  NDBT_Attribute("KOL46", NdbDictionary::Column::Char, 4, false, false, 0, MM, true),
278  NDBT_Attribute("KOL47", NdbDictionary::Column::Char, 8, false, false, 0, MM, true),
279  NDBT_Attribute("KOL48", NdbDictionary::Column::Char, 27, false, false, 0, MM, true),
280  NDBT_Attribute("KOL49", NdbDictionary::Column::Varbinary, 255, false, false, 0, MM, true),
281  /* This one is for update count, needed by hugoScanUpdate. */
282  NDBT_Attribute("KOL99", NdbDictionary::Column::Unsigned, 1, false, false, 0, MM, true),
283 };
284 
285 static
286 const
287 NDBT_Table T15("T15", sizeof(T15Attribs)/sizeof(NDBT_Attribute), T15Attribs);
288 
289 /* Test dynamic bit types when no other varsize/dynamic. */
290 static
291 const
292 NDBT_Attribute T16Attribs[] = {
293  NDBT_Attribute("KOL1", NdbDictionary::Column::Unsigned, 1, true, false),
294  NDBT_Attribute("Kol2", NdbDictionary::Column::Bit, 27, false, true, 0, MM, true),
295  NDBT_Attribute("KOL99", NdbDictionary::Column::Unsigned, 1, false, false),
296 };
297 
298 static
299 const
300 NDBT_Table T16("T16", sizeof(T16Attribs)/sizeof(NDBT_Attribute), T16Attribs);
301 
302 /*
303  C2 DHCP TABLES, MAYBE THESE SHOULD BE MOVED TO THE UTIL_TABLES?
304 */
305 static
306 const
307 NDBT_Attribute I1_Cols[] = {
309  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
310  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
317 };
318 
319 static
320 const
321 char* I1_Indexes[] = {
322  "UNIQUE", "ID", "PORT", "ACCESSNODE", "POP", "PORTSTATE", 0,
323  0
324 };
325 
326 static
327 NDBT_Table I1("I1", sizeof(I1_Cols)/sizeof(NDBT_Attribute), I1_Cols
328  );// ,I1_Indexes);
329 
330 static
331 const
332 NDBT_Attribute I2_Cols[] = {
334  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16, true),
335  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16, true),
337  NDBT_Attribute("ACCESSTYPE", NdbDictionary::Column::Int, true),
342  NDBT_Attribute("LEASED_NUM_IP", NdbDictionary::Column::Int),
345  NDBT_Attribute("SUSPENDED_SERVICES", NdbDictionary::Column::Int),
347 };
348 
349 const
350 char* I2_Indexes[] = {
351  "ORDERED", "CUSTOMER_ID", 0,
352  "ORDERED", "NUM_IP", 0,
353  0
354 };
355 
356 static
357 NDBT_Table I2("I2", sizeof(I2_Cols)/sizeof(NDBT_Attribute), I2_Cols
358  );//, I2_Indexes);
359 
360 static
361 const
362 NDBT_Attribute I3_Cols[] = {
364  NDBT_Attribute("PORT", NdbDictionary::Column::Char, 16), // SI2
365  NDBT_Attribute("ACCESSNODE", NdbDictionary::Column::Char, 16), // SI2
366  NDBT_Attribute("POP", NdbDictionary::Column::Char, 64), // SI2
367  NDBT_Attribute("MAC", NdbDictionary::Column::Char, 12, true),
368  NDBT_Attribute("MAC_EXPIRE", NdbDictionary::Column::Int, 1),
379 };
380 
381 const
382 char* I3_Indexes[] = {
383  "UNIQUE", "ID", 0,
384  "ORDERED", "MAC", 0,
385  "ORDERED", "GW", 0,
386  0
387 };
388 
389 static
390 NDBT_Table I3("I3", sizeof(I3_Cols)/sizeof(NDBT_Attribute), I3_Cols
391  ); // ,I3_Indexes);
392 
393 /* D1 */
394 static
395 const
396 NDBT_Attribute D1Attribs[] = {
398  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
400  NDBT_Attribute("KOL4", NdbDictionary::Column::Char, 233, false, true, 0, NdbDictionary::Column::StorageTypeDisk),
402  NDBT_Attribute("KOL6", NdbDictionary::Column::Varbinary, 233, false, true, 0, NdbDictionary::Column::StorageTypeDisk),
403 };
404 static
405 const
406 NDBT_Table D1("D1", sizeof(D1Attribs)/sizeof(NDBT_Attribute), D1Attribs);
407 
408 static
409 const char* BigVarDefault =
410  "\x80\x1"
411  "KOL7 default in table D2"
412  "KOL7 default in table D2"
413  "KOL7 default in table D2"
414  "KOL7 default in table D2"
415  "KOL7 default in table D2"
416  "KOL7 default in table D2"
417  "KOL7 default in table D2"
418  "KOL7 default in table D2"
419  "KOL7 default in table D2"
420  "KOL7 default in table D2"
421  "KOL7 default in table D2"
422  "KOL7 default in table D2"
423  "KOL7 default in table D2"
424  "KOL7 default in table D2"
425  "KOL7 default in table D2"
426  "KOL7 default in table D2";
427 
428 static unsigned smallUintDefault = 77;
429 
430 static
431 const
432 NDBT_Attribute D2Attribs[] = {
434  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, false, false, 0, NdbDictionary::Column::StorageTypeDisk, false,
435  &smallUintDefault, sizeof(unsigned)),
437  NDBT_Attribute("KOL4", NdbDictionary::Column::Varbinary, 133, false, true, 0, MM, true,
438  "\x1E" "A default value for KOL4 in D2", 31),
439  NDBT_Attribute("KOL5", NdbDictionary::Column::Char, 199, false, true, 0, NdbDictionary::Column::StorageTypeDisk),
440  NDBT_Attribute("KOL6", NdbDictionary::Column::Bit, 21, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
441  NDBT_Attribute("KOL7", NdbDictionary::Column::Longvarbinary, 384, false, true, 0, NdbDictionary::Column::StorageTypeDisk, false,
442  BigVarDefault, 386),
443  NDBT_Attribute("KOL8", NdbDictionary::Column::Varbinary, 88, false, true, 0, NdbDictionary::Column::StorageTypeDisk, false,
444  "\x1E""A default value for KOL8 in D2", 31)
445 
446 };
447 static
448 const
449 NDBT_Table D2("D2", sizeof(D2Attribs)/sizeof(NDBT_Attribute), D2Attribs);
450 
451 
452 // Define array with pointer to all tables
453 static
454 const
455 NDBT_Table *test_tables[]=
456 {
457  &T1,
458  &T2,
459  &T3,
460  &T4,
461  &T6,
462  &T13,
463  &T14,
464  &T15,
465  &T16,
466  &I1,
467  &I2,
468  &I3,
469  &D1, &D2
470 };
471 
472 static
473 const
474 int numTestTables = sizeof(test_tables)/sizeof(NDBT_Table*);
475 
476 
481 /* F1
482  *
483  * Error: PK and column with same name
484  */
485 static
486 const
487 NDBT_Attribute F1Attribs[] = {
493 };
494 
495 static
496 const
497 NDBT_Table F1("F1", sizeof(F1Attribs)/sizeof(NDBT_Attribute), F1Attribs);
498 
499 /* F2
500  *
501  * Error: Two columns with same name
502  */
503 static
504 const
505 NDBT_Attribute F2Attribs[] = {
511 };
512 
513 static
514 const
515 NDBT_Table F2("F2", sizeof(F2Attribs)/sizeof(NDBT_Attribute), F2Attribs);
516 
517 /* F3
518  *
519  * Error: Too many primary keys defined, 32 is max
520  */
521 static
522 const
523 NDBT_Attribute F3Attribs[] = {
561 };
562 
563 static
564 const
565 NDBT_Table F3("F3", sizeof(F3Attribs)/sizeof(NDBT_Attribute), F3Attribs);
566 
567 /* F4
568  *
569  * Error: Too long key
570  */
571 static
572 const
573 NDBT_Attribute F4Attribs[] = {
575  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 9999999, true),
579 };
580 
581 static
582 const
583 NDBT_Table F4("F4", sizeof(F4Attribs)/sizeof(NDBT_Attribute), F4Attribs);
584 
585 /* F5
586  *
587  * Error: Too long attr name
588  */
589 static
590 const
591 NDBT_Attribute F5Attribs[] = {
592  NDBT_Attribute("KOL1WITHVERRYLONGNAME_ISITTOLONG", NdbDictionary::Column::Unsigned, true),
596 };
597 
598 static
599 const
600 NDBT_Table F5("F5", sizeof(F5Attribs)/sizeof(NDBT_Attribute), F5Attribs);
601 
602 /* F6
603  *
604  * Error: Zero length of pk attribute
605  */
606 static
607 const
608 NDBT_Attribute F6Attribs[] = {
609  NDBT_Attribute("KOL1", NdbDictionary::Column::Char, 0, true, false),
611 };
612 
613 static
614 const
615 NDBT_Table F6("F6", sizeof(F6Attribs)/sizeof(NDBT_Attribute), F6Attribs);
616 
617 /* F7
618  *
619  * Error: Table without primary key
620  */
621 static
622 const
623 NDBT_Attribute F7Attribs[] = {
627 };
628 
629 NDBT_Table F7("F7", sizeof(F7Attribs)/sizeof(NDBT_Attribute), F7Attribs);
630 
631 /* F8
632  *
633  * Error: Table without nullable primary key
634  */
635 static
636 const
637 NDBT_Attribute F8Attribs[] = {
638  NDBT_Attribute("KOL3", NdbDictionary::Column::Int, 1, true, true),
641 };
642 
643 NDBT_Table F8("F8", sizeof(F8Attribs)/sizeof(NDBT_Attribute), F8Attribs);
644 
645 
646 /* F15 - 2-node crash in v20x */
647 static
648 const
649 NDBT_Attribute F15Attribs[] = {
651 };
652 static
653 const
654 NDBT_Table F15("F15", sizeof(F15Attribs)/sizeof(NDBT_Attribute), F15Attribs);
655 
656 // Define array with pointer to tables that we should not be able to create
657 static
658 const
659 NDBT_Table *fail_tables[]=
660 {
661  &F1,
662  &F2,
663  &F3,
664  &F4,
665  &F5,
666  &F6,
667  &F7,
668  &F8,
669  &F15
670 };
671 
672 static
673 const
674 int numFailTables = sizeof(fail_tables)/sizeof(NDBT_Table*);
675 
676 
682 /* GL
683  * General ledger table for bank application
684  */
685 static
686 const
687 NDBT_Attribute GL_Attribs[] = {
689  NDBT_Attribute("ACCOUNT_TYPE", NdbDictionary::Column::Unsigned, 1, true),
693  NDBT_Attribute("WITHDRAWAL_COUNT", NdbDictionary::Column::Unsigned),
696 };
697 
698 static
699 NDBT_Table GL("GL", sizeof(GL_Attribs)/sizeof(NDBT_Attribute), GL_Attribs);
700 
701 /* ACCOUNT
702  * Account table for bank application
703  */
704 static
705 const
706 NDBT_Attribute ACCOUNT_Attribs[] = {
707  NDBT_Attribute("ACCOUNT_ID", NdbDictionary::Column::Unsigned, 1, true),
711 };
712 
713 static
714 NDBT_Table ACCOUNT("ACCOUNT", sizeof(ACCOUNT_Attribs)/sizeof(NDBT_Attribute), ACCOUNT_Attribs);
715 
716 /* TRANSACTION
717  * Transaction table for bank application
718  */
719 static
720 const
721 NDBT_Attribute TRANSACTION_Attribs[] = {
722  NDBT_Attribute("TRANSACTION_ID", NdbDictionary::Column::Bigunsigned, 1, true),
723  NDBT_Attribute("ACCOUNT", NdbDictionary::Column::Unsigned, 1, true),
726  NDBT_Attribute("TRANSACTION_TYPE", NdbDictionary::Column::Unsigned),
729 };
730 
731 static
732 NDBT_Table TRANSACTION("TRANSACTION", sizeof(TRANSACTION_Attribs)/sizeof(NDBT_Attribute), TRANSACTION_Attribs);
733 
734 /* SYSTEM_VALUES
735  * System values table for bank application
736  */
737 static
738 const
739 NDBT_Attribute SYSTEM_VALUES_Attribs[] = {
740  NDBT_Attribute("SYSTEM_VALUES_ID", NdbDictionary::Column::Unsigned, 1, true),
742 };
743 
744 static
745 NDBT_Table SYSTEM_VALUES("SYSTEM_VALUES", sizeof(SYSTEM_VALUES_Attribs)/sizeof(NDBT_Attribute), SYSTEM_VALUES_Attribs);
746 
747 /* ACCOUNT_TYPES
748  * Account types table for bank application
749  */
750 static
751 const
752 NDBT_Attribute ACCOUNT_TYPES_Attribs[] = {
753  NDBT_Attribute("ACCOUNT_TYPE_ID", NdbDictionary::Column::Unsigned, 1, true),
754  NDBT_Attribute("DESCRIPTION", NdbDictionary::Column::Char, 64, false, false, &my_charset_latin1_bin)
755 };
756 
757 static
758 NDBT_Table ACCOUNT_TYPES("ACCOUNT_TYPE", sizeof(ACCOUNT_TYPES_Attribs)/sizeof(NDBT_Attribute), ACCOUNT_TYPES_Attribs);
759 
760 
761 // Define array with pointer to util tables
762 static
763 const
764 NDBT_Table *util_tables[]=
765 {
766  &GL,
767  &ACCOUNT,
768  &TRANSACTION,
769  &SYSTEM_VALUES,
770  &ACCOUNT_TYPES
771 };
772 
773 static
774 const
775 int numUtilTables = sizeof(util_tables)/sizeof(NDBT_Table*);
776 
777 
782 /* WIDE_2COL
783  * Single var length key going up to max size of key
784  * Single var length attribute using remaining row space
785  */
786 static
787 const
788 NDBT_Attribute WIDE_2COL_ATTRIBS[] = {
789  /* Note that we can't have any index on this table as it
790  * has no space for the extra FRAGID the index requires!
791  */
793  NDBT_Tables::MaxVarTypeKeyBytes, true),
795  NDBT_Tables::MaxKeyMaxVarTypeAttrBytes, false)
796 };
797 
798 
799 static
800 NDBT_Table WIDE_2COL("WIDE_2COL", sizeof(WIDE_2COL_ATTRIBS)/
801  sizeof(NDBT_Attribute), WIDE_2COL_ATTRIBS);
802 
803 /* WIDE_2COL_IX
804  * Single var length key going up to max size of key
805  * Single var length attribute using most of remaining row space,
806  * but not all as we need space in the index for FragId
807  */
808 static
809 const
810 NDBT_Attribute WIDE_2COL_IX_ATTRIBS[] = {
812  NDBT_Tables::MaxVarTypeKeyBytes, true),
814  NDBT_Tables::MaxKeyMaxVarTypeAttrBytesIndex , false)
815 };
816 
817 static
818 NDBT_Table WIDE_2COL_IX("WIDE_2COL_IX", sizeof(WIDE_2COL_IX_ATTRIBS)/
819  sizeof(NDBT_Attribute), WIDE_2COL_IX_ATTRIBS);
820 
821 static
822 const char* WIDE_2COL_IX_Indexes[] = {
823  "UNIQUE", "ATTR", 0,
824  0};
825 
826 /* WIDE_MAXKEY_HUGO
827  * Single var length key going up to max size of key
828  * Var length attr going using up remaining space
829  * Two unsigned int columns required by Hugo tools
830  */
831 static
832 const
833 NDBT_Attribute WIDE_MAXKEY_HUGO_ATTRIBS[] = {
834  /* Note that we can't have any index on this table as it
835  * has no space for the extra FRAGID the index requires!
836  */
838  NDBT_Tables::MaxVarTypeKeyBytes, true),
840  NDBT_Tables::MaxKeyMaxVarTypeAttrBytes -
841  NDBT_Tables::HugoOverheadBytes, false),
843  1, false),
845  1, false)
846 };
847 
848 static
849 NDBT_Table WIDE_MAXKEY_HUGO("WIDE_MAXKEY_HUGO", sizeof(WIDE_MAXKEY_HUGO_ATTRIBS)/
850  sizeof(NDBT_Attribute), WIDE_MAXKEY_HUGO_ATTRIBS);
851 
852 /* WIDE_MAXATTR_HUGO
853  * Single unsigned int key
854  * Var length attr using up remaining space
855  * Two unsigned int columns required by Hugo tools
856  */
857 static
858 const
859 NDBT_Attribute WIDE_MAXATTR_HUGO_ATTRIBS[] = {
861  1, true),
863  NDBT_Tables::MinKeyMaxVarTypeAttrBytes -
864  NDBT_Tables::HugoOverheadBytes, false),
866  1, false),
868  1, false)
869 };
870 
871 static
872 NDBT_Table WIDE_MAXATTR_HUGO("WIDE_MAXATTR_HUGO", sizeof(WIDE_MAXATTR_HUGO_ATTRIBS)/
873  sizeof(NDBT_Attribute), WIDE_MAXATTR_HUGO_ATTRIBS);
874 
875 typedef NDBT_Table* (*TableGenerator)(const char* name);
876 
877 static NDBT_Table* WIDE_MAXKEYMAXCOLS_HUGO= NULL;
878 
879 static
880 NDBT_Table* createMaxKeyMaxColsHugoTabDef(const char* name)
881 {
882  if (WIDE_MAXKEYMAXCOLS_HUGO == NULL)
883  {
884  /* Create a wide table with the max num of keys
885  * and the max num of attrs
886  */
887  NdbDictionary::Column* attrs[NDB_MAX_ATTRIBUTES_IN_TABLE];
888  const int buffsize=100;
889  char namebuff[buffsize];
890  Uint32 attrNum=0;
891 
892  /* Keys */
893  for (;attrNum < (NDB_MAX_ATTRIBUTES_IN_INDEX - 1); attrNum ++)
894  {
895  BaseString::snprintf(namebuff, buffsize, "K%d", attrNum);
896  attrs[attrNum]= new NDBT_Attribute(namebuff,
898  1, true);
899  }
900  /* Last key uses remaining key space */
901  BaseString::snprintf(namebuff, buffsize, "K%d", attrNum);
902  attrs[attrNum]= new NDBT_Attribute(namebuff,
904  (NDB_MAX_KEYSIZE_IN_WORDS -
905  (NDB_MAX_ATTRIBUTES_IN_INDEX -1)) * 4,
906  true);
907 
908  attrNum ++;
909 
910  /* Attributes */
911  for (;attrNum < (NDB_MAX_ATTRIBUTES_IN_TABLE - 1); attrNum ++)
912  {
913  BaseString::snprintf(namebuff, buffsize, "A%d", attrNum);
914  attrs[attrNum]= new NDBT_Attribute(namebuff,
916  1, false);
917  }
918 
919  /* Last attr uses remaining attr space */
920  BaseString::snprintf(namebuff, buffsize, "A%d", attrNum);
921  Uint32 sz32 = NDB_MAX_TUPLE_SIZE_IN_WORDS;
922  sz32 -= NDB_MAX_KEYSIZE_IN_WORDS;
923  sz32 -= NDB_MAX_ATTRIBUTES_IN_INDEX;
924  sz32 -= 2 * NDB_MAX_ATTRIBUTES_IN_TABLE;
925  attrs[attrNum]= new NDBT_Attribute(namebuff,
926  NdbDictionary::Column::Char, 4 * sz32,
927  false);
928 
929  WIDE_MAXKEYMAXCOLS_HUGO= new NDBT_Table(name, NDB_MAX_ATTRIBUTES_IN_TABLE,
930  attrs);
931 
932  /* Free attributes, table will remain until program exit */
933  for (attrNum=0; attrNum < NDB_MAX_ATTRIBUTES_IN_TABLE; attrNum++)
934  delete attrs[attrNum];
935 
936  }
937 
938  return WIDE_MAXKEYMAXCOLS_HUGO;
939 }
940 
941 static NDBT_Table* WIDE_MINKEYMAXCOLS_HUGO= NULL;
942 
943 static
944 NDBT_Table* createMinKeyMaxColsHugoTabDef(const char* name)
945 {
946  if (WIDE_MINKEYMAXCOLS_HUGO == NULL)
947  {
948  /* Create a wide table with one key and the max number
949  * of attributes
950  */
951  NdbDictionary::Column* attrs[NDB_MAX_ATTRIBUTES_IN_TABLE];
952  const int buffsize=100;
953  char namebuff[buffsize];
954  Uint32 attrNum=0;
955  attrs[attrNum]= new NDBT_Attribute("K1",
957  1, true);
958  attrNum ++;
959 
960  /* Attributes */
961  for (;attrNum < (NDB_MAX_ATTRIBUTES_IN_TABLE - 1); attrNum ++)
962  {
963  BaseString::snprintf(namebuff, buffsize, "A%d", attrNum);
964  attrs[attrNum]= new NDBT_Attribute(namebuff,
966  1, false);
967  }
968 
969  /* Last attr uses remaining attr space */
970  BaseString::snprintf(namebuff, buffsize, "A%d", attrNum);
971  attrs[attrNum]= new NDBT_Attribute(namebuff,
973  (NDB_MAX_TUPLE_SIZE_IN_WORDS -
974  (NDB_MAX_ATTRIBUTES_IN_TABLE - 1)) * 4,
975  false);
976 
977  WIDE_MINKEYMAXCOLS_HUGO= new NDBT_Table(name, NDB_MAX_ATTRIBUTES_IN_TABLE,
978  attrs);
979 
980  /* Free attributes, table will remain until program exit */
981  for (attrNum=0; attrNum < NDB_MAX_ATTRIBUTES_IN_TABLE; attrNum++)
982  delete attrs[attrNum];
983 
984 
985  }
986 
987  return WIDE_MINKEYMAXCOLS_HUGO;
988 }
989 
990 // Define array with pointer to other test tables
991 
993 {
994  const char* name;
995  NDBT_Table* tab;
996  TableGenerator tabGen;
997 };
998 
999 static
1000 const
1001 OtherTable other_tables[]=
1002 {
1003  {"WIDE_2COL", &WIDE_2COL, NULL},
1004  {"WIDE_2COL_IX", &WIDE_2COL_IX, NULL},
1005  {"WIDE_MAXKEY_HUGO", &WIDE_MAXKEY_HUGO, NULL},
1006  {"WIDE_MAXATTR_HUGO", &WIDE_MAXATTR_HUGO, NULL},
1007  {"WIDE_MAXKEYMAXCOLS_HUGO", NULL, createMaxKeyMaxColsHugoTabDef},
1008  {"WIDE_MINKEYMAXCOLS_HUGO", NULL, createMinKeyMaxColsHugoTabDef}
1009 };
1010 
1011 static
1012 const
1013 int numOtherTables = sizeof(other_tables)/sizeof(OtherTable);
1014 
1015 
1016 /* Secondary indexes for our tables */
1018  const char * m_table;
1019  const char ** m_indexes;
1020 };
1021 
1022 static
1023 const
1024 NDBT_IndexList indexes[] = {
1025  { "I1", I1_Indexes },
1026  { "I2", I2_Indexes },
1027  { "I3", I3_Indexes },
1028  { "WIDE_2COL_IX", WIDE_2COL_IX_Indexes },
1029  { 0, 0 }
1030 };
1031 
1032 const
1034 NDBT_Tables::getTable(const char* _nam){
1035  // Search tables list to find a table
1036  NDBT_Table* tab = NULL;
1037  int i;
1038  for (i=0; i<numTestTables; i++){
1039  if (strcmp(test_tables[i]->getName(), _nam) == 0){
1040  return test_tables[i];
1041  }
1042  }
1043  for (i=0; i<numFailTables; i++){
1044  if (strcmp(fail_tables[i]->getName(), _nam) == 0){
1045  return fail_tables[i];
1046  }
1047  }
1048  for (i=0; i<numUtilTables; i++){
1049  if (strcmp(util_tables[i]->getName(), _nam) == 0){
1050  return util_tables[i];
1051  }
1052  }
1053  for(i=0; i<numOtherTables; i++){
1054  if (strcmp(other_tables[i].name, _nam) == 0){
1055  return (other_tables[i].tab != NULL)?
1056  other_tables[i].tab :
1057  (*other_tables[i].tabGen)(other_tables[i].name);
1058  }
1059  }
1060 
1061  // TPK_no tables
1062  // Dynamcially create table vith primary key size
1063  // set to no
1064  // Useful for testing key sizes 1 - max
1065  int pkSizeOfTable;
1066  if(sscanf(_nam, "TPK_%d", &pkSizeOfTable) == 1){
1067  return tableWithPkSize(_nam, pkSizeOfTable);
1068  }
1069  return tab;
1070 }
1071 
1072 const NdbDictionary::Table*
1073 NDBT_Tables::tableWithPkSize(const char* _nam, Uint32 pkSize){
1074  NdbDictionary::Table* tab = new NdbDictionary::Table(_nam);
1075 
1076  // Add one PK of the desired length
1077  tab->addColumn(NDBT_Attribute("PK1",
1079  pkSize,
1080  true));
1081 
1082  // Add 4 attributes
1083  tab->addColumn(NDBT_Attribute("ATTR1",
1085  21));
1086 
1087  tab->addColumn(NDBT_Attribute("ATTR2",
1089  124));
1090 
1091  tab->addColumn(NDBT_Attribute("ATTR3",
1093 
1094  tab->addColumn(NDBT_Attribute("ATTR4",
1096 
1097  return tab;
1098 }
1099 
1100 const NdbDictionary::Table*
1101 NDBT_Tables::getTable(int _num){
1102  // Get table at pos _num
1103  assert(_num < numTestTables);
1104  return test_tables[_num];
1105 }
1106 
1107 int
1108 NDBT_Tables::getNumTables(){
1109  return numTestTables;
1110 }
1111 
1112 const char**
1113 NDBT_Tables::getIndexes(const char* table)
1114 {
1115  Uint32 i = 0;
1116  for (i = 0; indexes[i].m_table != 0; i++) {
1117  if (strcmp(indexes[i].m_table, table) == 0)
1118  return indexes[i].m_indexes;
1119  }
1120  return 0;
1121 }
1122 
1123 int
1124 NDBT_Tables::createAllTables(Ndb* pNdb, bool _temp, bool existsOk){
1125 
1126  for (int i=0; i < NDBT_Tables::getNumTables(); i++){
1127  pNdb->getDictionary()->dropTable(NDBT_Tables::getTable(i)->getName());
1128  int ret= createTable(pNdb,
1129  NDBT_Tables::getTable(i)->getName(), _temp, existsOk);
1130  if(ret){
1131  return ret;
1132  }
1133  }
1134  return NDBT_OK;
1135 }
1136 
1137 int
1138 NDBT_Tables::createAllTables(Ndb* pNdb){
1139  return createAllTables(pNdb, false);
1140 }
1141 
1142 int
1143 NDBT_Tables::create_default_tablespace(Ndb* pNdb)
1144 {
1145  NdbDictionary::Dictionary* pDict = pNdb->getDictionary();
1146 
1147  int res;
1148  Uint32 mb = 8;
1149  {
1150  char buf[256];
1151  if (NdbEnv_GetEnv("UNDOBUFFER", buf, sizeof(buf)))
1152  {
1153  mb = atoi(buf);
1154  ndbout_c("Using %umb dd-undo-buffer", mb);
1155  }
1156  }
1157 
1158  NdbDictionary::LogfileGroup lg = pDict->getLogfileGroup("DEFAULT-LG");
1159  if (strcmp(lg.getName(), "DEFAULT-LG") != 0)
1160  {
1161  lg.setName("DEFAULT-LG");
1162  lg.setUndoBufferSize(mb*1024*1024);
1163  res = pDict->createLogfileGroup(lg);
1164  if(res != 0){
1165  g_err << "Failed to create logfilegroup:"
1166  << endl << pDict->getNdbError() << endl;
1167  return NDBT_FAILED;
1168  }
1169  }
1170 
1171  mb = 96;
1172  Uint32 files = 13;
1173 
1174  {
1175  char buf[256];
1176  if (NdbEnv_GetEnv("UNDOSIZE", buf, sizeof(buf)))
1177  {
1178  mb = atoi(buf);
1179  ndbout_c("Using %umb dd-undo", mb);
1180  }
1181  }
1182 
1183  {
1184  char buf[256];
1185  if (NdbEnv_GetEnv("UNDOFILES", buf, sizeof(buf)))
1186  {
1187  files = atoi(buf);
1188  ndbout_c("Using max %u dd-undo files", files);
1189  }
1190  }
1191 
1192  Uint32 sz = 32;
1193  while (mb > files * sz)
1194  sz += 32;
1195 
1196  for (Uint32 i = 0; i * sz < mb; i++)
1197  {
1198  char tmp[256];
1199  BaseString::snprintf(tmp, sizeof(tmp), "undofile%u.dat", i);
1200  NdbDictionary::Undofile uf = pDict->getUndofile(0, tmp);
1201  if (strcmp(uf.getPath(), tmp) != 0)
1202  {
1203  uf.setPath(tmp);
1204  uf.setSize(Uint64(sz)*1024*1024);
1205  uf.setLogfileGroup("DEFAULT-LG");
1206 
1207  res = pDict->createUndofile(uf, true);
1208  if(res != 0){
1209  g_err << "Failed to create undofile:"
1210  << endl << pDict->getNdbError() << endl;
1211  return NDBT_FAILED;
1212  }
1213  }
1214  }
1215 
1216  NdbDictionary::Tablespace ts = pDict->getTablespace("DEFAULT-TS");
1217  if (strcmp(ts.getName(), "DEFAULT-TS") != 0)
1218  {
1219  ts.setName("DEFAULT-TS");
1220  ts.setExtentSize(1024*1024);
1221  ts.setDefaultLogfileGroup("DEFAULT-LG");
1222 
1223  res = pDict->createTablespace(ts);
1224  if(res != 0){
1225  g_err << "Failed to create tablespace:"
1226  << endl << pDict->getNdbError() << endl;
1227  return NDBT_FAILED;
1228  }
1229  }
1230 
1231  mb = 128;
1232  {
1233  char buf[256];
1234  if (NdbEnv_GetEnv("DATASIZE", buf, sizeof(buf)))
1235  {
1236  mb = atoi(buf);
1237  ndbout_c("Using %umb dd-data", mb);
1238  }
1239  }
1240 
1241  sz = 64;
1242  files = 13;
1243  {
1244  char buf[256];
1245  if (NdbEnv_GetEnv("DATAFILES", buf, sizeof(buf)))
1246  {
1247  files = atoi(buf);
1248  ndbout_c("Using max %u dd-data files", files);
1249  }
1250  }
1251 
1252  while (mb > files * sz)
1253  sz += 32;
1254  for (Uint32 i = 0; i * sz < mb; i++)
1255  {
1256  char tmp[256];
1257  BaseString::snprintf(tmp, sizeof(tmp), "datafile%u.dat", i);
1258  NdbDictionary::Datafile df = pDict->getDatafile(0, tmp);
1259  if (strcmp(df.getPath(), tmp) != 0)
1260  {
1261  df.setPath(tmp);
1262  df.setSize(Uint64(sz)*1024*1024);
1263  df.setTablespace("DEFAULT-TS");
1264 
1265  res = pDict->createDatafile(df, true);
1266  if(res != 0){
1267  g_err << "Failed to create datafile:"
1268  << endl << pDict->getNdbError() << endl;
1269  return NDBT_FAILED;
1270  }
1271  }
1272  }
1273 
1274  return NDBT_OK;
1275 }
1276 
1277 int
1278 NDBT_Tables::createTable(Ndb* pNdb, const char* _name, bool _temp,
1279  bool existsOk, NDBT_CreateTableHook f, void* arg)
1280 {
1281  const NdbDictionary::Table* tab = NDBT_Tables::getTable(_name);
1282  if (tab == NULL){
1283  ndbout << "Could not create table " << _name
1284  << ", it doesn't exist in list of tables "\
1285  "that NDBT_Tables can create!" << endl;
1286  return NDBT_WRONGARGS;
1287  }
1288 
1289  Uint32 sum = 0;
1290  for (Uint32 i = 0; i<strlen(_name); i++)
1291  sum += 33 * sum + (Uint32)_name[i];
1292 
1293  bool forceVarPart = (sum & 1);
1294 
1295  int r = 0;
1296  do {
1297  NdbDictionary::Table tmpTab(* tab);
1298  tmpTab.setStoredTable(_temp ? 0 : 1);
1299  tmpTab.setForceVarPart(forceVarPart);
1300 
1301  {
1302  NdbError error;
1303  int ret = tmpTab.validate(error);
1304  assert(ret == 0);
1305  }
1306  if(f != 0 && f(pNdb, tmpTab, 0, arg))
1307  {
1308  ndbout << "Failed to create table" << endl;
1309  return NDBT_FAILED;
1310  }
1311 loop:
1312  r = pNdb->getDictionary()->createTable(tmpTab);
1313  if(r == -1){
1314  if(pNdb->getDictionary()->getNdbError().code == 755)
1315  {
1316  ndbout << "Error: " << pNdb->getDictionary()->getNdbError() << endl;
1317  if (create_default_tablespace(pNdb) == 0)
1318  {
1319  goto loop;
1320  }
1321  }
1322  if(!existsOk){
1323  ndbout << "Error0: " << pNdb->getDictionary()->getNdbError() << endl;
1324 
1325  break;
1326  }
1327  if(pNdb->getDictionary()->getNdbError().code != 721){
1328  ndbout << "Error: " << pNdb->getDictionary()->getNdbError() << endl;
1329  break;
1330  }
1331 
1332  r = 0;
1333  }
1334 
1335  Uint32 i = 0;
1336  for(i = 0; indexes[i].m_table != 0; i++){
1337  if(strcmp(indexes[i].m_table, _name) != 0)
1338  continue;
1339  Uint32 j = 0;
1340  while(indexes[i].m_indexes[j] != 0){
1341  NdbDictionary::Index tmpIndx;
1342  BaseString name;
1343  name.assfmt("%s$NDBT_IDX%d", _name, j);
1344  tmpIndx.setName(name.c_str());
1345  tmpIndx.setTable(_name);
1346  bool logging = !_temp;
1347  if(strcmp(indexes[i].m_indexes[j], "ORDERED") == 0){
1348  logging = false;
1350  } else if(strcmp(indexes[i].m_indexes[j], "UNIQUE") == 0){
1352  } else {
1353  ndbout << "Unknown index type";
1354  abort();
1355  }
1356  tmpIndx.setLogging(logging);
1357 
1358  j++;
1359  while(indexes[i].m_indexes[j] != 0){
1360  tmpIndx.addIndexColumn(indexes[i].m_indexes[j]);
1361  j++;
1362  }
1363  j++;
1364  if (tmpTab.getTemporary())
1365  {
1366  tmpIndx.setTemporary(true);
1367  tmpIndx.setLogging(false);
1368  }
1369  if(pNdb->getDictionary()->createIndex(tmpIndx) != 0){
1370  ndbout << pNdb->getDictionary()->getNdbError() << endl;
1371  return NDBT_FAILED;
1372  }
1373  }
1374  }
1375  if(f != 0 && f(pNdb, tmpTab, 1, arg))
1376  {
1377  ndbout << "Failed to create table" << endl;
1378  return NDBT_FAILED;
1379  }
1380  } while(false);
1381 
1382  return r;
1383 }
1384 
1385 int
1386 NDBT_Tables::dropAllTables(Ndb* pNdb){
1387 
1388  for (int i=0; i < NDBT_Tables::getNumTables(); i++){
1389 
1390  const NdbDictionary::Table* tab = NDBT_Tables::getTable(i);
1391  if (tab == NULL){
1392  return NDBT_ProgramExit(NDBT_FAILED);
1393  }
1394 
1395  if(pNdb->getDictionary()->dropTable(tab->getName()) == -1){
1396  return NDBT_FAILED;
1397  }
1398  }
1399  return NDBT_OK;
1400 }
1401 
1402 
1403 int
1404 NDBT_Tables::print(const char * _name){
1405 
1406  const NDBT_Table * tab = (const NDBT_Table*)NDBT_Tables::getTable(_name);
1407  if (tab == NULL){
1408  ndbout << "Could not print table " << _name
1409  << ", it doesn't exist in list of tables "
1410  << "that NDBT_Tables can create!" << endl;
1411  return NDBT_WRONGARGS;
1412  }
1413  ndbout << (* tab) << endl;
1414  return NDBT_OK;
1415 }
1416 
1417 int
1418 NDBT_Tables::printAll(){
1419 
1420  for (int i=0; i < getNumTables(); i++){
1421 
1422  const NdbDictionary::Table* tab = getTable(i);
1423  if (tab == NULL){
1424  abort();
1425  }
1426  ndbout << (* (NDBT_Table*)tab) << endl;
1427  }
1428 
1429  return NDBT_OK;
1430 }