List:Commits« Previous MessageNext Message »
From:jonas Date:May 14 2007 3:02pm
Subject:bk commit into 5.1 tree (jonas:1.2535)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of jonas. When jonas 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

ChangeSet@stripped, 2007-05-14 17:02:18+02:00, jonas@stripped +5 -0
  ndb -
    computeHash enable "smart scan" + NdbRecord index-scan
    add testprg for smartscan (old version)

  storage/ndb/include/ndbapi/NdbOperation.hpp@stripped, 2007-05-14 17:02:16+02:00, jonas@stripped +0 -2
    remove "old" methods

  storage/ndb/src/ndbapi/NdbOperationSearch.cpp@stripped, 2007-05-14 17:02:16+02:00, jonas@stripped +21 -103
    Let smart scan use Ndb::computeHash
    remove "old" methods

  storage/ndb/src/ndbapi/NdbScanOperation.cpp@stripped, 2007-05-14 17:02:16+02:00, jonas@stripped +1 -1
    use len in bytes instead of in words

  storage/ndb/src/ndbapi/NdbTransaction.cpp@stripped, 2007-05-14 17:02:16+02:00, jonas@stripped +23 -17
    use Ndb::computeHash+setPartitionId to handle all different distribution keys

  storage/ndb/test/ndbapi/testPartitioning.cpp@stripped, 2007-05-14 17:02:16+02:00, jonas@stripped +63 -0
    add test for smart scan

# 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:	jonas
# Host:	perch.ndb.mysql.com
# Root:	/home/jonas/src/51-telco

--- 1.13/storage/ndb/test/ndbapi/testPartitioning.cpp	2007-05-14 17:02:24 +02:00
+++ 1.14/storage/ndb/test/ndbapi/testPartitioning.cpp	2007-05-14 17:02:24 +02:00
@@ -114,6 +114,41 @@
   return 0;
 }
 
+static
+int
+one_distribution_key(Ndb*, NdbDictionary::Table& tab, int when, void* arg)
+{
+  switch(when){
+  case 0: // Before
+    break;
+  case 1: // After
+    return 0;
+  default:
+    return 0;
+  }
+
+  int keys = tab.getNoOfPrimaryKeys();
+  int dist_key_no = rand()% keys;
+  
+  for(int i = 0; i<tab.getNoOfColumns(); i++)
+  {
+    if(tab.getColumn(i)->getPrimaryKey())
+    {
+      if (dist_key_no-- == 0)
+      {
+        tab.getColumn(i)->setDistributionKey(true);
+      }
+      else
+      {
+        tab.getColumn(i)->setDistributionKey(false);
+      }
+    }
+  }
+  ndbout << (NDBT_Table&)tab << endl;
+  
+  return 0;
+}
+
 static int
 run_create_table(NDBT_Context* ctx, NDBT_Step* step)
 {
@@ -134,6 +169,23 @@
 }
 
 static int
+run_create_table_smart_scan(NDBT_Context* ctx, NDBT_Step* step)
+{
+  if(NDBT_Tables::createTable(GETNDB(step), 
+			      ctx->getTab()->getName(), 
+			      false, false, 
+			      one_distribution_key) == NDBT_OK)
+  {
+    return NDBT_OK;
+  }
+
+  if(GETNDB(step)->getDictionary()->getNdbError().code == 745)
+    return NDBT_OK;
+
+  return NDBT_FAILED;
+}
+
+static int
 run_create_pk_index(NDBT_Context* ctx, NDBT_Step* step){
   bool orderedIndex = ctx->getProperty("OrderedIndex", (unsigned)0);
 
@@ -415,6 +467,17 @@
   TC_PROPERTY("OrderedIndex", (unsigned)1);
   INITIALIZER(run_drop_table);
   INITIALIZER(run_create_table);
+  INITIALIZER(run_create_pk_index);
+  INITIALIZER(run_index_dk);
+  INITIALIZER(run_create_pk_index_drop);
+  INITIALIZER(run_drop_table);
+}
+TESTCASE("smart_scan", 
+	 "Ordered index operatations with distribution key")
+{
+  TC_PROPERTY("OrderedIndex", (unsigned)1);
+  INITIALIZER(run_drop_table);
+  INITIALIZER(run_create_table_smart_scan);
   INITIALIZER(run_create_pk_index);
   INITIALIZER(run_index_dk);
   INITIALIZER(run_create_pk_index_drop);

--- 1.51/storage/ndb/include/ndbapi/NdbOperation.hpp	2007-05-14 17:02:24 +02:00
+++ 1.52/storage/ndb/include/ndbapi/NdbOperation.hpp	2007-05-14 17:02:24 +02:00
@@ -830,8 +830,6 @@
    * Set/get partition key
    */
   void setPartitionId(Uint32 id);
-  void setPartitionHash(Uint32 key);
-  void setPartitionHash(const Uint64 *, Uint32 len);
   Uint32 getPartitionId() const;
 #endif
 protected:

--- 1.85/storage/ndb/src/ndbapi/NdbTransaction.cpp	2007-05-14 17:02:24 +02:00
+++ 1.86/storage/ndb/src/ndbapi/NdbTransaction.cpp	2007-05-14 17:02:24 +02:00
@@ -2437,33 +2437,39 @@
   return 0;
 }
 
-static void
+void
 set_distribution_key_from_range(NdbIndexScanOperation *op,
                                 const NdbRecord *record,
                                 const char *row,
                                 Uint32 distkey_max)
 {
   Uint64 tmp[1000];
-  char *dst= (char *)(&tmp[0]);
+  Ndb::Key_part_ptr ptrs[NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY+1];
   Uint32 i;
-  Uint32 len, padded_len, total_len;
-
-  total_len= 0;
-  for (i= 0; i<record->distkey_index_length; i++)
+  for (i = 0; i<record->distkey_index_length; i++)
   {
     const NdbRecord::Attr *col= &record->columns[record->distkey_indexes[i]];
-    /* Distribution key cannot be NULL. */
-    col->get_var_length(row, len);
-    padded_len= (len+3)&~3;
-    total_len+= padded_len;
-    if (total_len > sizeof(tmp))
-      break;
-    memcpy(dst, row + col->offset, len);
-    if (padded_len != len)
-      bzero(dst + len, padded_len - len);
-    dst+= padded_len;
+    ptrs[i].ptr = row + col->offset;
+    ptrs[i].len = col->maxSize;
   }
-  op->setPartitionHash(tmp, total_len>>2);
+  ptrs[i].ptr = 0;
+  
+  Uint32 hashValue;
+  NdbError err;
+  int ret = Ndb::computeHash(&err, &hashValue, 
+                             record->base_table, 
+                             ptrs, tmp, sizeof(tmp));
+  if (ret == 0)
+  {
+    op->setPartitionId(record->base_table->getPartitionId(hashValue));
+  }
+#ifdef VM_TRACE
+  else
+  {
+    ndbout << "err: " << err.code << endl;
+    assert(false);
+  }
+#endif
 }
 
 NdbIndexScanOperation *

--- 1.36/storage/ndb/src/ndbapi/NdbOperationSearch.cpp	2007-05-14 17:02:24 +02:00
+++ 1.37/storage/ndb/src/ndbapi/NdbOperationSearch.cpp	2007-05-14 17:02:24 +02:00
@@ -525,120 +525,38 @@
   if (theDistrKeyIndicator_ == 1)
     DBUG_RETURN(0);
 
-  // this check was previously in create table
-  if (tAttrInfo->m_cs != NULL)
+  if (theNoOfTupKeyLeft > 0 || m_accessTable->m_noOfDistributionKeys > 1)
     DBUG_RETURN(0);
-
-  DBUG_PRINT("info",("theNoOfTupKeyLeft=%u m_noOfDistributionKeys=%u",
-                     theNoOfTupKeyLeft, m_accessTable->m_noOfDistributionKeys));
-
-  if (theNoOfTupKeyLeft > 0 && m_accessTable->m_noOfDistributionKeys > 1)
-    DBUG_RETURN(0);
-
-  DBUG_DUMP("value", (const char*)value, len << 2);
   
+  DBUG_DUMP("value", (const char*)value, len << 2);
+
   if(m_accessTable->m_noOfDistributionKeys == 1)
   {
-    setPartitionHash(value, len);
-  }
-  else if(theTCREQ->readSignalNumber() == GSN_TCKEYREQ)
-  {
-    // This branch is currently dead
-
-    // No support for combined distribution key and scan
-
-    /**
-     * Copy distribution key to linear memory
-     */
-    NdbColumnImpl* const * cols = m_accessTable->m_columns.getBase();
+    Ndb::Key_part_ptr ptrs[2];
+    ptrs[0].ptr = value;
+    ptrs[0].len = len;
+    ptrs[1].ptr = 0;
+    
+    NdbError err;
     Uint64 tmp[1000];
-
-    Uint32 chunk = 8;
-    Uint32* dst = (Uint32*)tmp;
-    NdbApiSignal* tSignal = theTCREQ;
-    Uint32* src = ((TcKeyReq*)tSignal->getDataPtrSend())->keyInfo;
-    if(tSignal->readSignalNumber() == GSN_SCAN_TABREQ)
+    Uint32 hashValue;
+    int ret = Ndb::computeHash(&err, &hashValue, 
+                               m_currentTable,
+                               ptrs, tmp, sizeof(tmp));
+    
+    if (ret == 0)
     {
-      tSignal = tSignal->next();
-      src = ((KeyInfo*)tSignal->getDataPtrSend())->keyData;
-      chunk = KeyInfo::DataLength;
+      setPartitionId(m_currentTable->getPartitionId(hashValue));
     }
-
-    for(unsigned i = m_accessTable->m_columns.size(); i>0; cols++, i--)
+#ifdef VM_TRACE
+    else
     {
-      if (!(* cols)->getPrimaryKey())
-	continue;
-      
-      NdbColumnImpl* tAttrInfo = * cols;
-      Uint32 sizeInBytes;
-      switch(tAttrInfo->m_arrayType){
-      default:
-      case NDB_ARRAYTYPE_FIXED:
-	sizeInBytes = tAttrInfo->m_attrSize * tAttrInfo->m_arraySize;
-	break;
-      case NDB_ARRAYTYPE_SHORT_VAR:
-	sizeInBytes = 1 + *(char*)src;
-	break;
-      case NDB_ARRAYTYPE_MEDIUM_VAR:
-	sizeInBytes = 2 + uint2korr((char*)src);
-	break;
-      }
-      
-      Uint32 currLen = (sizeInBytes + 3) >> 2;
-      if (tAttrInfo->getDistributionKey())
-      {
-	while (currLen >= chunk)
-	{
-	  memcpy(dst, src, 4*chunk);
-	  dst += chunk;
-	  tSignal = tSignal->next();
-	  src = ((KeyInfo*)tSignal->getDataPtrSend())->keyData;
-	  currLen -= chunk;
-	  chunk = KeyInfo::DataLength;
-	}
-
-	memcpy(dst, src, 4*currLen);
-	dst += currLen;
-	src += currLen;
-	chunk -= currLen;
-      }
-      else
-      {
-	while (currLen >= chunk)
-	{
-	  tSignal = tSignal->next();
-	  src = ((KeyInfo*)tSignal->getDataPtrSend())->keyData;
-	  currLen -= chunk;
-	  chunk = KeyInfo::DataLength;
-	}
-	
-	src += currLen;
-	chunk -= currLen;
-      }
+      ndbout << "Err: " << err.code << endl;
+      assert(false);
     }
-    setPartitionHash(tmp, dst - (Uint32*)tmp);
+#endif
   }
   DBUG_RETURN(0);
-}
-
-void
-NdbOperation::setPartitionHash(Uint32 value)
-{
-  union {
-    Uint32 tmp32;
-    Uint64 tmp64;
-  };
-
-  tmp32 = value;
-  setPartitionHash(&tmp64, 1);
-}
-
-void
-NdbOperation::setPartitionHash(const Uint64* value, Uint32 len)
-{
-  Uint32 buf[4];
-  md5_hash(buf, value, len);
-  setPartitionId(buf[1]);
 }
 
 void

--- 1.117/storage/ndb/src/ndbapi/NdbScanOperation.cpp	2007-05-14 17:02:24 +02:00
+++ 1.118/storage/ndb/src/ndbapi/NdbScanOperation.cpp	2007-05-14 17:02:24 +02:00
@@ -1679,7 +1679,7 @@
     if(type == BoundEQ && tDistrKey && !m_multi_range)
     {
       theNoOfTupKeyLeft--;
-      return handle_distribution_key(tAttrInfo, valPtr, sizeInWords);
+      return handle_distribution_key(tAttrInfo, valPtr, len);
     }
     return 0;
   } else {
Thread
bk commit into 5.1 tree (jonas:1.2535)jonas14 May