List:Internals« Previous MessageNext Message »
From:pekka Date:June 17 2005 6:07pm
Subject:bk commit into 5.1 tree (pekka:1.1911)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of pekka. When pekka does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

  storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp
    1.87 05/06/17 18:22:02 pekka@stripped +5 -3
    external vs internal attribute id

  storage/ndb/src/ndbapi/NdbDictionary.cpp
    1.45 05/06/17 18:22:02 pekka@stripped +7 -0
    external vs internal attribute id

  storage/ndb/src/ndbapi/NdbBlob.cpp
    1.24 05/06/17 18:22:02 pekka@stripped +1 -1
    external vs internal attribute id

  storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp
    1.22 05/06/17 18:22:02 pekka@stripped +1 -1
    external vs internal attribute id

  storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp
    1.33 05/06/17 18:22:02 pekka@stripped +15 -3
    external vs internal attribute id

  storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
    1.81 05/06/17 18:22:01 pekka@stripped +95 -42
    external vs internal attribute id

  storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp
    1.16 05/06/17 18:22:01 pekka@stripped +1 -1
    external vs internal attribute id

  storage/ndb/include/ndbapi/NdbDictionary.hpp
    1.45 05/06/17 18:22:01 pekka@stripped +4 -0
    external vs internal attribute id

ChangeSet
  1.1911 05/06/17 18:07:03 pekka@stripped +8 -0
  ndb - wl#1751 external vs internal attribute id

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	pekka
# Host:	tuna.ndb.mysql.com
# Root:	/orca/space/pekka/ndb/version/my51-vs

--- 1.44/storage/ndb/include/ndbapi/NdbDictionary.hpp	2005-05-24 17:30:57 +02:00
+++ 1.45/storage/ndb/include/ndbapi/NdbDictionary.hpp	2005-06-17 18:22:01 +02:00
@@ -266,6 +266,10 @@
      */
     int getColumnNo() const;
 
+#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
+    int getAttrId() const;
+#endif
+
     /**
      * Check if column is equal to some other column
      * @param  column  Column to compare with

--- 1.15/storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp	2005-04-29 16:30:22
+02:00
+++ 1.16/storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp	2005-06-17 18:22:01
+02:00
@@ -133,7 +133,7 @@
 void
 DictTabInfo::Attribute::init(){
   memset(AttributeName, 0, sizeof(AttributeName));//AttributeName[0] = 0;
-  AttributeId = 0;
+  AttributeId = 0xFFFF; // ZNIL
   AttributeType = ~0, // deprecated
   AttributeSize = DictTabInfo::a32Bit;
   AttributeArraySize = 1;

--- 1.80/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp	2005-05-24 17:30:58 +02:00
+++ 1.81/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp	2005-06-17 18:22:01 +02:00
@@ -1707,6 +1707,7 @@
   tablePtr.p->storedTable = true;
   tablePtr.p->tableType = DictTabInfo::UserTable;
   tablePtr.p->primaryTableId = RNIL;
+  tablePtr.p->firstAttributeIdPtrI = RNIL;
   // volatile elements
   tablePtr.p->indexState = TableRecord::IS_UNDEFINED;
   tablePtr.p->insertTriggerId = RNIL;
@@ -5016,17 +5017,19 @@
 
     Uint32 buf[2 * MAX_ATTRIBUTES_IN_INDEX];
     Uint32 sz = 0;
-    AttributeRecordPtr attrPtr;
-    LocalDLFifoList<AttributeRecord> list(c_attributeRecordPool,
-                                          tabPtr.p->m_attributes);
 
-    for(list.first(attrPtr); !attrPtr.isNull(); list.next(attrPtr))
-    {
+    // send keys in internal order
+    AttributeRecordPtr attrPtr;
+    attrPtr.i = tabPtr.p->firstAttributeIdPtrI;
+    while (attrPtr.i != RNIL) {
       jam();
+      c_attributeRecordPool.getPtr(attrPtr);
       if (attrPtr.p->tupleKey) {
         buf[sz++] = attrPtr.p->attributeDescriptor;
+        // TODO send 2nd word of AttributeDescriptor instead
         buf[sz++] = (attrPtr.p->extPrecision >> 16); // charset number
       }
+      attrPtr.i = attrPtr.p->nextAttributeIdPtrI;
     }
     ndbrequire((int)sz == 2 * tabPtr.p->noOfPrimkey);
 
@@ -5511,7 +5514,7 @@
     
     new (attrPtr.p) AttributeRecord();
     attrPtr.p->attributeDescriptor = 0x00012255; //Default value
-    attrPtr.p->attributeId = ZNIL;
+    attrPtr.p->columnNo = i;
     attrPtr.p->tupleKey = 0;
     
     /**
@@ -5571,6 +5574,7 @@
       return;
     }
     
+    // XXX old test option, remove
     if(!attrDesc.AttributeKeyFlag && 
        tablePtr.i > 1 &&
        !tablePtr.p->isIndex())
@@ -5594,10 +5598,6 @@
       defaultValue.assign(attrDesc.AttributeDefaultValue);
     }
     
-    tabRequire(parseP->requestType != DictTabInfo::CreateTableFromAPI || 
-	       attrDesc.AttributeId == i, CreateTableRef::InvalidFormat);
-    
-    attrCount ++;
     keyCount += attrDesc.AttributeKeyFlag;
     nullCount += attrDesc.AttributeNullableFlag;
     
@@ -5690,10 +5690,9 @@
     }
   } 
   
-  if(parseP->requestType == DictTabInfo::CreateTableFromAPI) 
   {
     /**
-     * Enumerate attributebut id's so that
+     * Enumerate attribute id's so that
      *   mm-fixsize
      *   mm-varsize
      *   dd-fixsize
@@ -5713,13 +5712,40 @@
       int b= AttributeDescriptor::getArrayType(attrPtr.p->attributeDescriptor);
       Uint32 pos= 2*(a ? 1 : 0) + (b == NDB_ARRAYTYPE_FIXED ? 0 : 1);
       printf("%d ", counts[pos]);
-      if(parseP->requestType == DictTabInfo::CreateTableFromAPI)
-	attrPtr.p->attributeId = counts[pos]++;
+      Uint32 attributeId;
+      if (! tablePtr.p->isOrderedIndex())
+	attributeId = counts[pos]++;
+      else
+	attributeId = attrPtr.p->columnNo;
+      if (attrPtr.p->attributeId == ZNIL)
+	attrPtr.p->attributeId = attributeId;
       else
-	ndbrequire(attrPtr.p->attributeId == counts[pos]++);
+        tabRequire(attrPtr.p->attributeId == attributeId,
+                   CreateTableRef::Inconsistency);
     }
     ndbout_c("");
   }
+  {
+    // link in internal attributeId order  XXX quadratic
+    tablePtr.p->firstAttributeIdPtrI = RNIL;
+    Uint32 lastAttributeIdPtrI = RNIL;
+    for (Uint32 i = 0; i < attrCount; i++) {
+      jam();
+      for (list.first(attrPtr); true; list.next(attrPtr)) {
+        jam();
+        if (attrPtr.p->attributeId == i) {
+          if (lastAttributeIdPtrI == RNIL)
+            tablePtr.p->firstAttributeIdPtrI = attrPtr.i;
+          else
+            c_attributeRecordPool.getPtr(lastAttributeIdPtrI)->
+              nextAttributeIdPtrI = attrPtr.i;
+          lastAttributeIdPtrI = attrPtr.i;
+          attrPtr.p->nextAttributeIdPtrI = RNIL;
+          break;
+        }
+      }
+    }
+  }
 }//handleTabInfo()
 
 
@@ -7059,8 +7085,6 @@
     char tableName[MAX_TAB_NAME_SIZE];
     char attributeName[MAX_ATTR_NAME_SIZE];
   };
-  Uint32 attrid_map[MAX_ATTRIBUTES_IN_INDEX];
-
   Uint32 k;
 
   jam();
@@ -7126,11 +7150,31 @@
     opPtr.p->m_errorLine = __LINE__;
     return;
   }
+
   if (indexPtr.p->isOrderedIndex()) {
     // tree node size in words (make configurable later)
     indexPtr.p->tupKeyLength = MAX_TTREE_NODE_SIZE;
   }
 
+  if (indexPtr.p->isHashIndex()) {
+    // put index columns in table order i.e. ascending order
+    bool disorder = true;
+    while (disorder) {
+      disorder = false;
+      for (Uint32 i = 1; i < opPtr.p->m_attrList.sz; i++) {
+        Uint32 & y = opPtr.p->m_attrList.id[i-1];
+        Uint32 & x = opPtr.p->m_attrList.id[i];
+        if (y > x) {
+          Uint32 z = x;
+          x = y;
+          y = z;
+          disorder = true;
+        }
+      }
+    }
+  }
+
+  bool hash_index_var_key = false;
   AttributeMask mask;
   mask.clear();
   for (k = 0; k < opPtr.p->m_attrList.sz; k++) {
@@ -7141,7 +7185,7 @@
     for (; tAttr != RNIL; )
     {
       aRec = c_attributeRecordPool.getPtr(tAttr);
-      if (aRec->attributeId != current_id)
+      if (aRec->columnNo != current_id)
       {
 	tAttr= aRec->nextList;
 	continue;
@@ -7174,18 +7218,16 @@
     
     mask.set(current_id);
 
-    unsigned kk= k;
     if (indexPtr.p->isHashIndex()) {
       const Uint32 s1 = AttributeDescriptor::getSize(a);
       const Uint32 s2 = AttributeDescriptor::getArraySize(a);
       indexPtr.p->tupKeyLength += ((1 << s1) * s2 + 31) >> 5;
-      // reorder the attributes according to the tableid order
-      // for unque indexes
-      for (; kk > 0 && current_id < attrid_map[kk-1]>>16; kk--)
-	attrid_map[kk]= attrid_map[kk-1];
+
+      if (AttributeDescriptor::getArrayType != NDB_ARRAYTYPE_FIXED)
+        hash_index_var_key = true;
     }
-    attrid_map[kk]= k | (current_id << 16);
   }
+
   indexPtr.p->noOfPrimkey = indexPtr.p->noOfAttributes;
   // plus concatenated primary table key attribute
   indexPtr.p->noOfAttributes += 1;
@@ -7207,25 +7249,24 @@
   AttributeRecordPtr aRecPtr;
   c_attributeRecordPool.getPtr(aRecPtr, tablePtr.p->m_attributes.firstItem);
   for (k = 0; k < opPtr.p->m_attrList.sz; k++) {
-    // insert the attributes in the order decided above in attrid_map
-    // k is new order, current_id is in previous order
-    // ToDo: make sure "current_id" is stored with the table and
-    // passed up to NdbDictionary
-    unsigned current_id= opPtr.p->m_attrList.id[attrid_map[k] & 0xffff];
+    // insert the attributes in external column number order
+    unsigned current_id= opPtr.p->m_attrList.id[k];
     jam();
     for (Uint32 tAttr = tablePtr.p->m_attributes.firstItem; tAttr != RNIL; ) {
       AttributeRecord* aRec = c_attributeRecordPool.getPtr(tAttr);
       tAttr = aRec->nextList;
-      if (aRec->attributeId != current_id)
+      if (aRec->columnNo != current_id)
         continue;
       jam();
       const Uint32 a = aRec->attributeDescriptor;
       bool isNullable = AttributeDescriptor::getNullable(a);
+      Uint32 arrayType = AttributeDescriptor::getArrayType(a);
       Rope attrName(c_rope_pool, aRec->attributeName);
       attrName.copy(attributeName);
       w.add(DictTabInfo::AttributeName, attributeName);
       Uint32 attrType = AttributeDescriptor::getType(a);
-      w.add(DictTabInfo::AttributeId, k);
+      // computed
+      w.add(DictTabInfo::AttributeId, ZNIL);
       if (indexPtr.p->isHashIndex()) {
         w.add(DictTabInfo::AttributeKeyFlag, (Uint32)true);
         w.add(DictTabInfo::AttributeNullableFlag, (Uint32)false);
@@ -7234,6 +7275,7 @@
         w.add(DictTabInfo::AttributeKeyFlag, (Uint32)false);
         w.add(DictTabInfo::AttributeNullableFlag, (Uint32)isNullable);
       }
+      w.add(DictTabInfo::AttributeArrayType, arrayType);
       w.add(DictTabInfo::AttributeExtType, attrType);
       w.add(DictTabInfo::AttributeExtPrecision, aRec->extPrecision);
       w.add(DictTabInfo::AttributeExtScale, aRec->extScale);
@@ -7243,9 +7285,11 @@
   }
   if (indexPtr.p->isHashIndex()) {
     jam();
-    // write concatenated primary table key attribute
+    // write concatenated primary table key attribute i.e. keyinfo
     w.add(DictTabInfo::AttributeName, "NDB$PK");
     w.add(DictTabInfo::AttributeId, opPtr.p->m_attrList.sz);
+    // make it sort last (ice getting thin here)
+    w.add(DictTabInfo::AttributeArrayType, (Uint32)NDB_ARRAYTYPE_MEDIUM_VAR);
     w.add(DictTabInfo::AttributeKeyFlag, (Uint32)false);
     w.add(DictTabInfo::AttributeNullableFlag, (Uint32)false);
     w.add(DictTabInfo::AttributeExtType, (Uint32)DictTabInfo::ExtUnsigned);
@@ -7257,6 +7301,8 @@
     // write index tree node as Uint32 array attribute
     w.add(DictTabInfo::AttributeName, "NDB$TNODE");
     w.add(DictTabInfo::AttributeId, opPtr.p->m_attrList.sz);
+    // should not matter but VAR crashes in TUP
+    w.add(DictTabInfo::AttributeArrayType, (Uint32)NDB_ARRAYTYPE_FIXED);
     w.add(DictTabInfo::AttributeKeyFlag, (Uint32)true);
     w.add(DictTabInfo::AttributeNullableFlag, (Uint32)false);
     w.add(DictTabInfo::AttributeExtType, (Uint32)DictTabInfo::ExtUnsigned);
@@ -12438,6 +12484,7 @@
 
 /**
  * MODULE: Support routines for index and trigger.
+ * Internal attribute ids are used.
  */
 
 void
@@ -12446,13 +12493,15 @@
   jam();
   list.sz = 0;
   AttributeRecordPtr attrPtr;
-  LocalDLFifoList<AttributeRecord> l(c_attributeRecordPool, 
-				     tablePtr.p->m_attributes);
-  for (l.first(attrPtr); !attrPtr.isNull(); l.next(attrPtr)){
-    if (attrPtr.p->tupleKey){
+  attrPtr.i = tablePtr.p->firstAttributeIdPtrI;
+  while (attrPtr.i != RNIL) {
+    c_attributeRecordPool.getPtr(attrPtr);
+    if (attrPtr.p->tupleKey) {
       list.id[list.sz++] = attrPtr.p->attributeId;
     }
+    attrPtr.i = attrPtr.p->nextAttributeIdPtrI;
   }
+  ndbrequire(list.sz == tablePtr.p->noOfPrimkey);
 }
 
 // XXX should store the primary attribute id
@@ -12493,13 +12542,17 @@
   memset(list.id, 0, sizeof(list.id));
   ndbrequire(indexPtr.p->noOfAttributes >= 2);
 
-  AttributeRecordPtr attrPtr, currPtr;
-  LocalDLFifoList<AttributeRecord> l(c_attributeRecordPool, 
-				     indexPtr.p->m_attributes);
-  
-  for (l.first(attrPtr); currPtr = attrPtr, l.next(attrPtr); ){
-    getIndexAttr(indexPtr, currPtr.i, &list.id[list.sz++]);
+  AttributeRecordPtr attrPtr;
+  attrPtr.i = indexPtr.p->firstAttributeIdPtrI;
+  while (attrPtr.i != RNIL) {
+    c_attributeRecordPool.getPtr(attrPtr);
+    // skip last
+    if (attrPtr.p->nextAttributeIdPtrI == RNIL)
+      break;
+    getIndexAttr(indexPtr, attrPtr.i, &list.id[list.sz++]);
+    attrPtr.i = attrPtr.p->nextAttributeIdPtrI;
   }
+  ndbrequire(indexPtr.p->noOfAttributes == list.sz + 1);
 }
 
 void

--- 1.32/storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp	2005-05-24 17:30:58 +02:00
+++ 1.33/storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp	2005-06-17 18:22:02 +02:00
@@ -136,7 +136,11 @@
    */
   struct AttributeRecord {
     AttributeRecord(){}
-    /* Attribute id within table (counted from 0) */
+
+    /* External attribute id as defined by client */
+    Uint16 columnNo;
+
+    /* Internal attribute id ordered MM-fixed MM-var DD-fixed DD-var */
     Uint16 attributeId;
 
     /* Attribute number within tuple key (counted from 1) */
@@ -166,6 +170,7 @@
       RopePool * m_pool;
     } m_key;
 
+    /** Doubly linked in external (columnNo) order */
     union {
       Uint32 nextPool;
       Uint32 nextList;
@@ -182,6 +187,10 @@
       }
       return false;
     }
+
+    /** Singly linked in internal (attributeId) order */
+    // TODO use DL template when possible to have more than 1
+    Uint32 nextAttributeIdPtrI;
   };
   typedef Ptr<AttributeRecord> AttributeRecordPtr;
   ArrayPool<AttributeRecord> c_attributeRecordPool;
@@ -277,9 +286,12 @@
     /**    File pointer received from disk   */
     Uint32 filePtr[2];
 
-    /**    Pointer to first attribute in table */
+    /**    Pointer to first attribute in table in columnNo order */
     DLFifoList<AttributeRecord>::Head m_attributes;
-    
+
+    /**    Pointer to first attribute in table in attributeId order */
+    Uint32 firstAttributeIdPtrI;
+
     /*    Pointer to first page of table description */
     Uint32 firstPage;
 

--- 1.21/storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp	2005-04-29 16:30:27 +02:00
+++ 1.22/storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp	2005-06-17 18:22:02 +02:00
@@ -1578,7 +1578,7 @@
     const SysColumn& column = table.columnList[i];
     ndbassert(column.pos == i);
     w.add(DictTabInfo::AttributeName, column.name);
-    w.add(DictTabInfo::AttributeId, (Uint32)column.pos);
+    w.add(DictTabInfo::AttributeId, (Uint32)ZNIL);
     w.add(DictTabInfo::AttributeKeyFlag, (Uint32)column.keyFlag);
     w.add(DictTabInfo::AttributeStorageType, 
 	  (Uint32)NDB_STORAGETYPE_MEMORY);

--- 1.44/storage/ndb/src/ndbapi/NdbDictionary.cpp	2005-06-15 19:06:39 +02:00
+++ 1.45/storage/ndb/src/ndbapi/NdbDictionary.cpp	2005-06-17 18:22:02 +02:00
@@ -226,6 +226,11 @@
   return m_impl.m_column_no;
 }
 
+int
+NdbDictionary::Column::getAttrId() const {
+  return m_impl.m_attrId;;
+}
+
 bool
 NdbDictionary::Column::equal(const NdbDictionary::Column & col) const {
   return m_impl.equal(col.m_impl);
@@ -1391,6 +1396,8 @@
     out << " ST=" << col.getStorageType() << "?";
     break;
   }
+
+  out << " AI=" << col.getAttrId();
 
   return out;
 }

--- 1.86/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp	2005-06-15 19:06:39 +02:00
+++ 1.87/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp	2005-06-17 18:22:02 +02:00
@@ -1784,7 +1784,8 @@
     DictTabInfo::Attribute tmpAttr; tmpAttr.init();
     BaseString::snprintf(tmpAttr.AttributeName, sizeof(tmpAttr.AttributeName), 
 	     col->m_name.c_str());
-    tmpAttr.AttributeId = i;
+    // pass internal attribute id as ZNIL if not known (create table)
+    tmpAttr.AttributeId = col->m_attrId == -1 ? 0xFFFF : col->m_attrId;
     tmpAttr.AttributeKeyFlag = col->m_pk;
     tmpAttr.AttributeNullableFlag = col->m_nullable;
     tmpAttr.AttributeDKey = distKeys ? (bool)col->m_distributionKey : 0;
@@ -2286,7 +2287,7 @@
       m_error.code = 4247;
       return -1;
     }
-    // Copy column definition
+    // Copy column definition  XXX must be wrong, overwrites
     *impl.m_columns[i] = *col;
 
     // index key type check
@@ -2297,7 +2298,8 @@
       m_error.code = 743;
       return -1;
     }
-    attributeList.id[i] = col->m_attrId;
+    // API uses external column number to talk to DICT
+    attributeList.id[i] = col->m_column_no;
   }
   LinearSectionPtr ptr[2];
   ptr[0].p = (Uint32*)&attributeList;

--- 1.23/storage/ndb/src/ndbapi/NdbBlob.cpp	2005-06-14 10:41:57 +02:00
+++ 1.24/storage/ndb/src/ndbapi/NdbBlob.cpp	2005-06-17 18:22:02 +02:00
@@ -61,7 +61,7 @@
 {
   assert(t != 0 && c != 0 && c->getBlobType());
   memset(btname, 0, NdbBlobImpl::BlobTableNameSize);
-  sprintf(btname, "NDB$BLOB_%d_%d", (int)t->m_id, (int)c->m_attrId);
+  sprintf(btname, "NDB$BLOB_%d_%d", (int)t->m_id, (int)c->m_column_no);
 }
 
 void
Thread
bk commit into 5.1 tree (pekka:1.1911)pekka17 Jun