18 #ifndef DICT_TAB_INFO_HPP 
   19 #define DICT_TAB_INFO_HPP 
   21 #include "SignalData.hpp" 
   22 #include <AttributeDescriptor.hpp> 
   23 #include <SimpleProperties.hpp> 
   24 #include <ndb_limits.h> 
   25 #include <NdbSqlUtil.hpp> 
   26 #include <ndb_global.h> 
   33 #define DECIMAL_MAX_FIELD_SIZE ((9 * 9) - (2 * 8)) 
   35 #ifndef DECIMAL_NOT_SPECIFIED 
   36 #define DECIMAL_NOT_SPECIFIED 31 
   40 extern int decimal_bin_size(
int, 
int);
 
   43 inline int my_decimal_get_binary_size(uint precision, uint scale)
 
   45   return decimal_bin_size((
int)precision, (
int)scale);
 
   50 #define DTIMAP(x, y, z) \ 
   51   { DictTabInfo::y, my_offsetof(x, z), SimpleProperties::Uint32Value, 0, (~0), 0 } 
   53 #define DTIMAP2(x, y, z, u, v) \ 
   54   { DictTabInfo::y, my_offsetof(x, z), SimpleProperties::Uint32Value, u, v, 0 } 
   56 #define DTIMAPS(x, y, z, u, v) \ 
   57   { DictTabInfo::y, my_offsetof(x, z), SimpleProperties::StringValue, u, v, 0 } 
   59 #define DTIMAPB(x, y, z, u, v, l) \ 
   60   { DictTabInfo::y, my_offsetof(x, z), SimpleProperties::BinaryValue, u, v, \ 
   64   { DictTabInfo::x, 0, SimpleProperties::InvalidValue, 0, 0, 0 } 
   83                                const Uint32 * theData, 
 
   85                                Uint16 receiverBlockNo);
 
   89     CreateTableFromAPI  = 1,
 
   92     ReadTableFromDiskSR = 4, 
 
  110     FragmentTypeVal    = 13, 
 
  115     InsertTriggerId    = 22,
 
  116     UpdateTriggerId    = 23,
 
  117     DeleteTriggerId    = 24,
 
  118     CustomTriggerId    = 25,
 
  122     TableTemporaryFlag = 28,  
 
  123     ForceVarPartFlag   = 29,
 
  126     FragmentDataLen    = 129,
 
  129     TablespaceVersion  = 132,
 
  130     TablespaceDataLen  = 133,
 
  131     TablespaceData     = 134,
 
  132     RangeListDataLen   = 135,
 
  134     ReplicaDataLen     = 137,
 
  138     DefaultNoPartFlag  = 141,
 
  139     LinearHashFlag     = 142,
 
  144     RowChecksumFlag    = 151,
 
  146     SingleUserMode     = 152,
 
  148     HashMapObjectId    = 153,
 
  149     HashMapVersion     = 154,
 
  151     TableStorageType   = 155,
 
  153     ExtraRowGCIBits    = 156,
 
  154     ExtraRowAuthorBits = 157,
 
  158     AttributeName          = 1000, 
 
  160     AttributeType          = 1002, 
 
  161     AttributeSize          = 1003, 
 
  162     AttributeArraySize     = 1005, 
 
  163     AttributeKeyFlag       = 1006, 
 
  164     AttributeStorageType   = 1007, 
 
  165     AttributeNullableFlag  = 1008, 
 
  166     AttributeDynamic       = 1009, 
 
  167     AttributeDKey          = 1010, 
 
  168     AttributeExtType       = 1013, 
 
  169     AttributeExtPrecision  = 1014, 
 
  170     AttributeExtScale      = 1015, 
 
  171     AttributeExtLength     = 1016, 
 
  172     AttributeAutoIncrement = 1017, 
 
  173     AttributeArrayType     = 1019, 
 
  174     AttributeDefaultValueLen = 1020, 
 
  180     AttributeDefaultValue = 1021,
 
  192     AllNodesSmallTable = 0,
 
  193     AllNodesMediumTable = 1,
 
  194     AllNodesLargeTable = 2,
 
  199     DistrKeyOrderedIndex = 8, 
 
  210     UniqueOrderedIndex = 5,
 
  213     HashIndexTrigger = 11,
 
  214     SubscriptionTrigger = 16,
 
  215     ReadOnlyConstraint = 17,
 
  225     SchemaTransaction = 30
 
  230   isBlobTableName(
const char* 
name, Uint32* ptab_id = 0, Uint32* pcol_no = 0);
 
  233   isTable(
int tableType) {
 
  235       tableType == SystemTable ||
 
  236       tableType == UserTable;
 
  239   isIndex(
int tableType) {
 
  241       tableType == UniqueHashIndex ||
 
  242       tableType == HashIndex ||
 
  243       tableType == UniqueOrderedIndex ||
 
  244       tableType == OrderedIndex;
 
  247   isUniqueIndex(
int tableType) {
 
  249       tableType == UniqueHashIndex ||
 
  250       tableType == UniqueOrderedIndex;
 
  253   isNonUniqueIndex(
int tableType) {
 
  255       tableType == HashIndex ||
 
  256       tableType == OrderedIndex;
 
  259   isHashIndex(
int tableType) {
 
  261       tableType == UniqueHashIndex ||
 
  262       tableType == HashIndex;
 
  265   isOrderedIndex(
int tableType) {
 
  267       tableType == UniqueOrderedIndex ||
 
  268       tableType == OrderedIndex;
 
  271   isTrigger(
int tableType) {
 
  273       tableType == HashIndexTrigger ||
 
  274       tableType == SubscriptionTrigger ||
 
  275       tableType == ReadOnlyConstraint ||
 
  276       tableType == IndexTrigger ||
 
  277       tableType == ReorgTrigger;
 
  280   isFilegroup(
int tableType) {
 
  287   isFile(
int tableType) {
 
  294   isHashMap(
int tableType) {
 
  318   STATIC_CONST( aBit = 0 );
 
  319   STATIC_CONST( an8Bit = 3 );
 
  320   STATIC_CONST( a16Bit = 4 );
 
  321   STATIC_CONST( a32Bit = 5 );
 
  322   STATIC_CONST( a64Bit = 6 );
 
  323   STATIC_CONST( a128Bit = 7 );
 
  327     char   TableName[MAX_TAB_NAME_SIZE];
 
  329     char   PrimaryTable[MAX_TAB_NAME_SIZE]; 
 
  330     Uint32 PrimaryTableId;
 
  331     Uint32 TableLoggedFlag;
 
  332     Uint32 TableTemporaryFlag;
 
  333     Uint32 ForceVarPartFlag;
 
  335     Uint32 NoOfAttributes;
 
  339     Uint32 MinLoadFactor;
 
  340     Uint32 MaxLoadFactor;
 
  346     Uint32 InsertTriggerId;
 
  347     Uint32 UpdateTriggerId;
 
  348     Uint32 DeleteTriggerId;
 
  349     Uint32 CustomTriggerId;
 
  351     Uint32 TablespaceVersion;
 
  352     Uint32 DefaultNoPartFlag;
 
  353     Uint32 LinearHashFlag;
 
  360     char   FrmData[MAX_FRM_DATA_SIZE];
 
  361     Uint32 FragmentCount;
 
  362     Uint32 ReplicaDataLen;
 
  363     Uint16 ReplicaData[MAX_FRAGMENT_DATA_BYTES];
 
  364     Uint32 FragmentDataLen;
 
  365     Uint16 FragmentData[3*MAX_NDB_PARTITIONS];
 
  372     Uint32 TablespaceDataLen;
 
  373     Uint32 TablespaceData[2*MAX_NDB_PARTITIONS];
 
  374     Uint32 RangeListDataLen;
 
  375     Uint32 RangeListData[2*MAX_NDB_PARTITIONS*2];
 
  378     Uint32 RowChecksumFlag;
 
  380     Uint32 SingleUserMode;
 
  382     Uint32 HashMapObjectId;
 
  383     Uint32 HashMapVersion;
 
  385     Uint32 TableStorageType;
 
  387     Uint32 ExtraRowGCIBits;
 
  388     Uint32 ExtraRowAuthorBits;
 
  397   static const Uint32 TableMappingSize;
 
  401     ExtUndefined = NdbSqlUtil::Type::Undefined,
 
  402     ExtTinyint = NdbSqlUtil::Type::Tinyint,
 
  403     ExtTinyunsigned = NdbSqlUtil::Type::Tinyunsigned,
 
  404     ExtSmallint = NdbSqlUtil::Type::Smallint,
 
  405     ExtSmallunsigned = NdbSqlUtil::Type::Smallunsigned,
 
  406     ExtMediumint = NdbSqlUtil::Type::Mediumint,
 
  407     ExtMediumunsigned = NdbSqlUtil::Type::Mediumunsigned,
 
  408     ExtInt = NdbSqlUtil::Type::Int,
 
  409     ExtUnsigned = NdbSqlUtil::Type::Unsigned,
 
  410     ExtBigint = NdbSqlUtil::Type::Bigint,
 
  411     ExtBigunsigned = NdbSqlUtil::Type::Bigunsigned,
 
  412     ExtFloat = NdbSqlUtil::Type::Float,
 
  413     ExtDouble = NdbSqlUtil::Type::Double,
 
  414     ExtOlddecimal = NdbSqlUtil::Type::Olddecimal,
 
  415     ExtOlddecimalunsigned = NdbSqlUtil::Type::Olddecimalunsigned,
 
  416     ExtDecimal = NdbSqlUtil::Type::Decimal,
 
  417     ExtDecimalunsigned = NdbSqlUtil::Type::Decimalunsigned,
 
  418     ExtChar = NdbSqlUtil::Type::Char,
 
  419     ExtVarchar = NdbSqlUtil::Type::Varchar,
 
  420     ExtBinary = NdbSqlUtil::Type::Binary,
 
  421     ExtVarbinary = NdbSqlUtil::Type::Varbinary,
 
  422     ExtDatetime = NdbSqlUtil::Type::Datetime,
 
  423     ExtDate = NdbSqlUtil::Type::Date,
 
  424     ExtBlob = NdbSqlUtil::Type::Blob,
 
  425     ExtText = NdbSqlUtil::Type::Text,
 
  426     ExtBit = NdbSqlUtil::Type::Bit,
 
  427     ExtLongvarchar = NdbSqlUtil::Type::Longvarchar,
 
  428     ExtLongvarbinary = NdbSqlUtil::Type::Longvarbinary,
 
  429     ExtTime = NdbSqlUtil::Type::Time,
 
  430     ExtYear = NdbSqlUtil::Type::Year,
 
  431     ExtTimestamp = NdbSqlUtil::Type::Timestamp
 
  436     char   AttributeName[MAX_TAB_NAME_SIZE];
 
  438     Uint32 AttributeType; 
 
  439     Uint32 AttributeSize;
 
  440     Uint32 AttributeArraySize;
 
  441     Uint32 AttributeArrayType;
 
  442     Uint32 AttributeKeyFlag;
 
  443     Uint32 AttributeNullableFlag;
 
  444     Uint32 AttributeDKey;
 
  445     Uint32 AttributeExtType;
 
  446     Uint32 AttributeExtPrecision;
 
  447     Uint32 AttributeExtScale;
 
  448     Uint32 AttributeExtLength;
 
  449     Uint32 AttributeAutoIncrement;
 
  450     Uint32 AttributeStorageType;
 
  451     Uint32 AttributeDynamic;
 
  452     Uint32 AttributeDefaultValueLen;  
 
  453     Uint8  AttributeDefaultValue[MAX_ATTR_DEFAULT_VALUE_SIZE];
 
  461       return ((1 << AttributeSize) * AttributeArraySize + 31) >> 5;
 
  467       switch (AttributeExtType) {
 
  468       case DictTabInfo::ExtUndefined:
 
  470       case DictTabInfo::ExtTinyint:
 
  471       case DictTabInfo::ExtTinyunsigned:
 
  472         AttributeSize = DictTabInfo::an8Bit;
 
  473         AttributeArraySize = AttributeExtLength;
 
  475       case DictTabInfo::ExtSmallint:
 
  476       case DictTabInfo::ExtSmallunsigned:
 
  477         AttributeSize = DictTabInfo::a16Bit;
 
  478         AttributeArraySize = AttributeExtLength;
 
  480       case DictTabInfo::ExtMediumint:
 
  481       case DictTabInfo::ExtMediumunsigned:
 
  482         AttributeSize = DictTabInfo::an8Bit;
 
  483         AttributeArraySize = 3 * AttributeExtLength;
 
  485       case DictTabInfo::ExtInt: 
 
  486       case DictTabInfo::ExtUnsigned:
 
  487         AttributeSize = DictTabInfo::a32Bit;
 
  488         AttributeArraySize = AttributeExtLength;
 
  490       case DictTabInfo::ExtBigint:
 
  491       case DictTabInfo::ExtBigunsigned:
 
  492         AttributeSize = DictTabInfo::a64Bit;
 
  493         AttributeArraySize = AttributeExtLength;
 
  495       case DictTabInfo::ExtFloat:
 
  496         AttributeSize = DictTabInfo::a32Bit;
 
  497         AttributeArraySize = AttributeExtLength;
 
  499       case DictTabInfo::ExtDouble:
 
  500         AttributeSize = DictTabInfo::a64Bit;
 
  501         AttributeArraySize = AttributeExtLength;
 
  503       case DictTabInfo::ExtOlddecimal:
 
  504         AttributeSize = DictTabInfo::an8Bit;
 
  506           (1 + AttributeExtPrecision + (int(AttributeExtScale) > 0)) *
 
  509       case DictTabInfo::ExtOlddecimalunsigned:
 
  510         AttributeSize = DictTabInfo::an8Bit;
 
  512           (0 + AttributeExtPrecision + (int(AttributeExtScale) > 0)) *
 
  515       case DictTabInfo::ExtDecimal:
 
  516       case DictTabInfo::ExtDecimalunsigned:
 
  519           uint precision = AttributeExtPrecision;
 
  520           uint scale = AttributeExtScale;
 
  522               scale >= DECIMAL_NOT_SPECIFIED)
 
  524           uint bin_size = my_decimal_get_binary_size(precision, scale);
 
  525           AttributeSize = DictTabInfo::an8Bit;
 
  526           AttributeArraySize = bin_size * AttributeExtLength;
 
  529       case DictTabInfo::ExtChar:
 
  530       case DictTabInfo::ExtBinary:
 
  531         AttributeSize = DictTabInfo::an8Bit;
 
  532         AttributeArraySize = AttributeExtLength;
 
  534       case DictTabInfo::ExtVarchar:
 
  535       case DictTabInfo::ExtVarbinary:
 
  536         if (AttributeExtLength > 0xff)
 
  538         AttributeSize = DictTabInfo::an8Bit;
 
  539         AttributeArraySize = AttributeExtLength + 1;
 
  541       case DictTabInfo::ExtDatetime:
 
  543         AttributeSize = DictTabInfo::an8Bit;
 
  544         AttributeArraySize = 8 * AttributeExtLength;
 
  546       case DictTabInfo::ExtDate:
 
  548         AttributeSize = DictTabInfo::an8Bit;
 
  549         AttributeArraySize = 3 * AttributeExtLength;
 
  551       case DictTabInfo::ExtBlob:
 
  552       case DictTabInfo::ExtText:
 
  553         AttributeSize = DictTabInfo::an8Bit;
 
  554         if (unlikely(AttributeArrayType == NDB_ARRAYTYPE_FIXED)) {
 
  556           AttributeArraySize = (NDB_BLOB_V1_HEAD_SIZE << 2) +
 
  557                                (AttributeExtPrecision & 0xFFFF);
 
  559           AttributeArraySize = (NDB_BLOB_V2_HEAD_SIZE << 2) +
 
  560                                (AttributeExtPrecision & 0xFFFF);
 
  563       case DictTabInfo::ExtBit:
 
  564         AttributeSize = DictTabInfo::aBit;
 
  565         AttributeArraySize = AttributeExtLength;
 
  567       case DictTabInfo::ExtLongvarchar:
 
  568       case DictTabInfo::ExtLongvarbinary:
 
  569         if (AttributeExtLength > 0xffff)
 
  571         AttributeSize = DictTabInfo::an8Bit;
 
  572         AttributeArraySize = AttributeExtLength + 2;
 
  574       case DictTabInfo::ExtTime:
 
  575         AttributeSize = DictTabInfo::an8Bit;
 
  576         AttributeArraySize = 3 * AttributeExtLength;
 
  578       case DictTabInfo::ExtYear:
 
  579         AttributeSize = DictTabInfo::an8Bit;
 
  580         AttributeArraySize = 1 * AttributeExtLength;
 
  582       case DictTabInfo::ExtTimestamp:
 
  583         AttributeSize = DictTabInfo::an8Bit;
 
  584         AttributeArraySize = 4 * AttributeExtLength;
 
  592     inline void print(FILE *out) {
 
  593       fprintf(out, 
"AttributeId = %d\n", AttributeId);
 
  594       fprintf(out, 
"AttributeType = %d\n", AttributeType);
 
  595       fprintf(out, 
"AttributeSize = %d\n", AttributeSize);
 
  596       fprintf(out, 
"AttributeArraySize = %d\n", AttributeArraySize);
 
  597       fprintf(out, 
"AttributeArrayType = %d\n", AttributeArrayType);
 
  598       fprintf(out, 
"AttributeKeyFlag = %d\n", AttributeKeyFlag);
 
  599       fprintf(out, 
"AttributeStorageType = %d\n", AttributeStorageType);
 
  600       fprintf(out, 
"AttributeNullableFlag = %d\n", AttributeNullableFlag);
 
  601       fprintf(out, 
"AttributeDKey = %d\n", AttributeDKey);
 
  602       fprintf(out, 
"AttributeGroup = %d\n", AttributeGroup);
 
  603       fprintf(out, 
"AttributeAutoIncrement = %d\n", AttributeAutoIncrement);
 
  604       fprintf(out, 
"AttributeExtType = %d\n", AttributeExtType);
 
  605       fprintf(out, 
"AttributeExtPrecision = %d\n", AttributeExtPrecision);
 
  606       fprintf(out, 
"AttributeExtScale = %d\n", AttributeExtScale);
 
  607       fprintf(out, 
"AttributeExtLength = %d\n", AttributeExtLength);
 
  608       fprintf(out, 
"AttributeDefaultValueLen = %d\n",
 
  609               AttributeDefaultValueLen);
 
  610       fprintf(out, 
"AttributeDefaultValue: \n");
 
  611       for (
unsigned int i = 0; 
i < AttributeDefaultValueLen; 
i++)
 
  612         fprintf(out, 
"0x%x", AttributeDefaultValue[
i]);
 
  619   static const Uint32 AttributeMappingSize;
 
  622   STATIC_CONST( DataLength = 20 );
 
  623   STATIC_CONST( HeaderLength = 5 );
 
  637   Uint32 tabInfoData[DataLength];
 
  642     AttributeDGroup    = 1009, 
 
  643     AttributeStoredInd = 1011, 
 
  644     TableStorageVal    = 14, 
 
  646     FragmentKeyTypeVal = 16 
 
  652     AttributeGroup     = 1012, 
 
  657 #define DFGIMAP(x, y, z) \ 
  658   { DictFilegroupInfo::y, my_offsetof(x, z), SimpleProperties::Uint32Value, 0, (~0), 0 } 
  660 #define DFGIMAP2(x, y, z, u, v) \ 
  661   { DictFilegroupInfo::y, my_offsetof(x, z), SimpleProperties::Uint32Value, u, v, 0 } 
  663 #define DFGIMAPS(x, y, z, u, v) \ 
  664   { DictFilegroupInfo::y, my_offsetof(x, z), SimpleProperties::StringValue, u, v, 0 } 
  666 #define DFGIMAPB(x, y, z, u, v, l) \ 
  667   { DictFilegroupInfo::y, my_offsetof(x, z), SimpleProperties::BinaryValue, u, v, \ 
  670 #define DFGIBREAK(x) \ 
  671   { DictFilegroupInfo::x, 0, SimpleProperties::InvalidValue, 0, 0, 0 } 
  678     FilegroupVersion  = 4,
 
  687     FileFGroupVersion = 105,
 
  690     FileFreeExtents   = 108,
 
  698     TS_LogfileGroupId      = 1001, 
 
  699     TS_LogfileGroupVersion = 1002, 
 
  701     TS_GrowSizeHi          = 1004,
 
  702     TS_GrowSizeLo          = 1005,
 
  703     TS_GrowPattern         = 1006,
 
  704     TS_GrowMaxSize         = 1007,
 
  710     LF_UndoGrowLimit   = 2000, 
 
  711     LF_UndoGrowSizeHi  = 2001,
 
  712     LF_UndoGrowSizeLo  = 2002,
 
  713     LF_UndoGrowPattern = 2003,
 
  714     LF_UndoGrowMaxSize = 2004,
 
  715     LF_UndoFreeWordsHi = 2006,
 
  716     LF_UndoFreeWordsLo = 2007
 
  720   enum FileTypeValues {
 
  730     char   GrowPattern[PATH_MAX];
 
  736     char   FilegroupName[MAX_TAB_NAME_SIZE];
 
  737     Uint32 FilegroupType; 
 
  739     Uint32 FilegroupVersion;
 
  742       Uint32 TS_ExtentSize;
 
  743       Uint32 LF_UndoBufferSize;
 
  745     Uint32 TS_LogfileGroupId;
 
  746     Uint32 TS_LogfileGroupVersion;
 
  752     Uint32 LF_UndoFreeWordsHi;
 
  753     Uint32 LF_UndoFreeWordsLo;
 
  757   static const Uint32 MappingSize;
 
  761     char FileName[PATH_MAX];
 
  766     Uint32 FilegroupVersion;
 
  769     Uint32 FileFreeExtents;
 
  774   static const Uint32 FileMappingSize;
 
  778 #define DHMIMAP(x, y, z) \ 
  779   { DictHashMapInfo::y, my_offsetof(x, z), SimpleProperties::Uint32Value, 0, (~0), 0 } 
  781 #define DHMIMAP2(x, y, z, u, v) \ 
  782   { DictHashMapInfo::y, my_offsetof(x, z), SimpleProperties::Uint32Value, u, v, 0 } 
  784 #define DHMIMAPS(x, y, z, u, v) \ 
  785   { DictHashMapInfo::y, my_offsetof(x, z), SimpleProperties::StringValue, u, v, 0 } 
  787 #define DHMIMAPB(x, y, z, u, v, l) \ 
  788   { DictHashMapInfo::y, my_offsetof(x, z), SimpleProperties::BinaryValue, u, v, \ 
  791 #define DHMIBREAK(x) \ 
  792   { DictHashMapInfo::x, 0, SimpleProperties::InvalidValue, 0, 0, 0 } 
  803     char   HashMapName[MAX_TAB_NAME_SIZE];
 
  804     Uint32 HashMapBuckets;
 
  805     Uint16 HashMapValues[512];
 
  806     Uint32 HashMapObjectId;
 
  807     Uint32 HashMapVersion;
 
  811   static const Uint32 MappingSize;