1 /*
2    Copyright (C) 2003-2006, 2008 MySQL AB
3     Use is subject to license terms.
4 
5    This program is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License, version 2.0,
7    as published by the Free Software Foundation.
8 
9    This program is also distributed with certain software (including
10    but not limited to OpenSSL) that is licensed under separate terms,
11    as designated in a particular file or component or in included license
12    documentation.  The authors of MySQL hereby grant you an additional
13    permission to link the program and your derivative works with the
14    separately licensed software that they have included with MySQL.
15 
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License, version 2.0, for more details.
20 
21    You should have received a copy of the GNU General Public License
22    along with this program; if not, write to the Free Software
23    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
24 */
25 
26 #ifndef NDBT_TABLES_HPP
27 #define NDBT_TABLES_HPP
28 
29 
30 #include <NDBT.hpp>
31 #include <Ndb.hpp>
32 #include <NdbDictionary.hpp>
33 #include <NDBT_Table.hpp>
34 
35 typedef int (* NDBT_CreateTableHook)(Ndb*, NdbDictionary::Table&, int when,
36                                     void* arg);
37 
38 class NDBT_Tables {
39 public:
40   /* Some constants for the maximum sizes of keys and attributes
41    * in various cases
42    */
43   STATIC_CONST(MaxRowBytes= NDB_MAX_TUPLE_SIZE_IN_WORDS * 4);
44   STATIC_CONST(MaxKeyBytes= NDB_MAX_KEYSIZE_IN_WORDS * 4);
45   STATIC_CONST(MinKeyBytes= 4); // Single Unsigned key
46 
47   STATIC_CONST(MaxVarTypeKeyBytes= MaxKeyBytes - 2); // 2 length bytes
48 
49   STATIC_CONST(MaxKeyMaxAttrBytes= MaxRowBytes - MaxKeyBytes);
50   STATIC_CONST(MaxKeyMaxVarTypeAttrBytes= MaxKeyMaxAttrBytes - 2);
51 
52   STATIC_CONST(MinKeyMaxAttrBytes= MaxRowBytes - MinKeyBytes);
53   STATIC_CONST(MinKeyMaxVarTypeAttrBytes= MinKeyMaxAttrBytes - 2);
54 
55   STATIC_CONST(UniqueIndexOverheadBytes= 4); // For FragId
56 
57   // Note that since we'll put an unique index on this...it can't be bigger
58   // than MaxKeyBytes
59   STATIC_CONST(MaxKeyMaxVarTypeAttrBytesIndex =
60                ((MaxKeyMaxVarTypeAttrBytes <= MaxKeyBytes) ?
61                 MaxKeyMaxVarTypeAttrBytes : MaxKeyBytes) - UniqueIndexOverheadBytes);
62 
63   /* Hugo requires 2 unsigned int columns somewhere in the table
64    * and these also counts towards #attributes relation
65    */
66   STATIC_CONST(HugoOverheadBytes= 2 * (4 + 4));
67 
68   static int createTable(Ndb* pNdb, const char* _name, bool _temp = false,
69 			 bool existsOK = false, NDBT_CreateTableHook = 0,
70                          void* arg = 0);
71   static int createAllTables(Ndb* pNdb, bool _temp, bool existsOK = false);
72   static int createAllTables(Ndb* pNdb);
73 
74   static int dropAllTables(Ndb* pNdb);
75 
76   static int print(const char * name);
77   static int printAll();
78 
79   static const NdbDictionary::Table* getTable(const char* _nam);
80   static const NdbDictionary::Table* getTable(int _num);
81   static int getNumTables();
82 
83   static const char** getIndexes(const char* table);
84 
85   static int create_default_tablespace(Ndb* pNdb);
86 
87 private:
88   static const NdbDictionary::Table* tableWithPkSize(const char* _nam, Uint32 pkSize);
89 };
90 #endif
91 
92 
93