NdbOperationSearch.cpp 20.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/* Copyright (C) 2003 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */


/******************************************************************************
Name:          NdbOperationSearch.C
Include:
Link:
Author:        UABMNST Mona Natterkvist UAB/B/SD                         
Date:          970829
Version:       0.1
Description:   Interface between TIS and NDB
Documentation:
Adjust:  971022  UABMNST   First version.
	 971206  UABRONM
 *****************************************************************************/
#include "API.hpp"

#include <NdbOperation.hpp>
#include "NdbApiSignal.hpp"
34
#include <NdbTransaction.hpp>
35 36 37 38 39 40
#include <Ndb.hpp>
#include "NdbImpl.hpp"
#include <NdbOut.hpp>

#include <AttributeHeader.hpp>
#include <signaldata/TcKeyReq.hpp>
41
#include <signaldata/KeyInfo.hpp>
42
#include "NdbDictionaryImpl.hpp"
43
#include <md5_hash.hpp>
44 45 46 47 48 49 50 51 52 53 54 55 56

/******************************************************************************
CondIdType equal(const char* anAttrName, char* aValue, Uint32 aVarKeylen);

Return Value    Return 0 : Equal was successful.
                Return -1: In all other case. 
Parameters:     anAttrName : Attribute name for search condition..
                aValue : Referense to the search value.
		aVariableKeylen : The length of key in bytes  
Remark:         Defines search condition with equality anAttrName.
******************************************************************************/
int
NdbOperation::equal_impl(const NdbColumnImpl* tAttrInfo, 
57
                         const char* aValuePassed)
58
{
pekka@mysql.com's avatar
pekka@mysql.com committed
59
  DBUG_ENTER("NdbOperation::equal_impl");
60 61 62
  DBUG_PRINT("enter", ("col=%s op=%d val=%p",
                       tAttrInfo->m_name.c_str(), theOperationType,
                       aValuePassed));
63 64 65
  
  Uint32 tData;
  const char* aValue = aValuePassed;
66
  Uint64 tempData[512];
67 68 69 70 71 72 73 74 75 76 77 78

  if ((theStatus == OperationDefined) &&
      (aValue != NULL) &&
      (tAttrInfo != NULL )) {
/******************************************************************************
 *	Start by checking that the attribute is a tuple key. 
 *      This value is also the word order in the tuple key of this 
 *      tuple key attribute. 
 *      Then check that this tuple key has not already been defined. 
 *      Finally check if all tuple key attributes have been defined. If
 *	this is true then set Operation state to tuple key defined.
 *****************************************************************************/
79

80 81 82 83 84 85 86 87 88 89 90 91 92 93
    /*
     * For each call theTupleKeyDefined stores 3 items:
     *
     * [0] = m_column_no (external column id)
     * [1] = 1-based index of first word of accumulating keyinfo
     * [2] = number of words of keyinfo
     *
     * This is used to re-order keyinfo if not in m_attrId order.
     *
     * Note: No point to "clean up" this code.  The upcoming
     * record-based ndb api makes it obsolete.
     */

    Uint32 tAttrId = tAttrInfo->m_column_no; // not m_attrId;
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    Uint32 i = 0;
    if (tAttrInfo->m_pk) {
      Uint32 tKeyDefined = theTupleKeyDefined[0][2];
      Uint32 tKeyAttrId = theTupleKeyDefined[0][0];
      do {
	if (tKeyDefined == false) {
	  goto keyEntryFound;
	} else {
	  if (tKeyAttrId != tAttrId) {
	    /******************************************************************
	     * We read the key defined variable in advance. 
	     * It could potentially read outside its area when 
	     * i = MAXNROFTUPLEKEY - 1, 
	     * it is not a problem as long as the variable 
	     * theTupleKeyDefined is defined
	     * in the middle of the object. 
	     * Reading wrong data and not using it causes no problems.
	     *****************************************************************/
	    i++;
	    tKeyAttrId = theTupleKeyDefined[i][0];
	    tKeyDefined = theTupleKeyDefined[i][2];
	    continue;
	  } else {
	    goto equal_error2;
	  }//if
	}//if
120
      } while (i < NDB_MAX_NO_OF_ATTRIBUTES_IN_KEY);
121 122 123 124 125 126 127 128 129 130
      goto equal_error2;
    } else {
      goto equal_error1;
    }
    /*************************************************************************
     *	Now it is time to retrieve the tuple key data from the pointer supplied
     *      by the application. 
     *      We have to retrieve the size of the attribute in words and bits.
     *************************************************************************/
  keyEntryFound:
131 132 133 134 135 136 137 138
    Uint32 sizeInBytes;
    if (! tAttrInfo->get_var_length(aValue, sizeInBytes)) {
      setErrorCodeAbort(4209);
      DBUG_RETURN(-1);
    }

    Uint32 tKeyInfoPosition =
      i == 0 ? 1 : theTupleKeyDefined[i-1][1] + theTupleKeyDefined[i-1][2];
139 140
    theTupleKeyDefined[i][0] = tAttrId;
    theTupleKeyDefined[i][1] = tKeyInfoPosition; 
141
    theTupleKeyDefined[i][2] = (sizeInBytes + 3) / 4;
pekka@mysql.com's avatar
pekka@mysql.com committed
142

143
    {
144 145 146 147 148 149
      /************************************************************************
       * Check if the pointer of the value passed is aligned on a 4 byte 
       * boundary. If so only assign the pointer to the internal variable 
       * aValue. If it is not aligned then we start by copying the value to 
       * tempData and use this as aValue instead.
       ***********************************************************************/
150
      const bool tDistrKey = tAttrInfo->m_distributionKey;
151 152
      const int attributeSize = sizeInBytes;
      const int slack = sizeInBytes & 3;
153 154 155 156 157
      const int align = UintPtr(aValue) & 7;

      if (((align & 3) != 0) || (slack != 0) || (tDistrKey && (align != 0)))
      {
	((Uint32*)tempData)[attributeSize >> 2] = 0;
158 159 160 161
	memcpy(&tempData[0], aValue, attributeSize);
	aValue = (char*)&tempData[0];
      }//if
    }
162

163
    Uint32 totalSizeInWords = (sizeInBytes + 3)/4; // Inc. bits in last word
164
    theTupKeyLen += totalSizeInWords;
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
#if 0
    else {
      /************************************************************************
       * The attribute is a variable array. We need to use the length parameter
       * to know the size of this attribute in the key information and 
       * variable area. A key is however not allowed to be larger than 4 
       * kBytes and this is checked for variable array attributes
       * used as keys.
       ************************************************************************/
      Uint32 tMaxVariableKeyLenInWord = (MAXTUPLEKEYLENOFATTERIBUTEINWORD -
					 tKeyInfoPosition);
      tAttrSizeInBits = aVariableKeyLen << 3;
      tAttrSizeInWords = tAttrSizeInBits >> 5;
      tAttrBitsInLastWord = tAttrSizeInBits - (tAttrSizeInWords << 5);
      tAttrLenInWords = ((tAttrSizeInBits + 31) >> 5);
      if (tAttrLenInWords > tMaxVariableKeyLenInWord) {
	setErrorCodeAbort(4207);
	return -1;
      }//if
      theTupKeyLen = theTupKeyLen + tAttrLenInWords;
    }//if
#endif
187

188
    /**************************************************************************
189 190 191
     *	If the operation is an insert request and the attribute is stored then
     *      we also set the value in the stored part through putting the 
     *      information in the ATTRINFO signals.
192
     *************************************************************************/
193
    OperationType tOpType = theOperationType;
194 195
    if ((tOpType == InsertRequest) ||
	(tOpType == WriteRequest)) {
joreland@mysql.com's avatar
joreland@mysql.com committed
196
      Uint32 ahValue;
197

198 199 200 201 202 203
      if(m_accessTable == m_currentTable) {
	AttributeHeader::init(&ahValue, tAttrInfo->m_attrId, sizeInBytes);
      } else {
	assert(tOpType == WriteRequest && m_accessTable->m_index);
        // use attrId of primary table column
	int column_no_current_table = 
204
	  m_accessTable->m_index->m_columns[tAttrId]->m_keyInfoPos;
205 206 207
        int attr_id_current_table =
          m_currentTable->m_columns[column_no_current_table]->m_attrId;
	AttributeHeader::init(&ahValue, attr_id_current_table, sizeInBytes);
208 209
      }
      
joreland@mysql.com's avatar
joreland@mysql.com committed
210
      insertATTRINFO( ahValue );
211
      insertATTRINFOloop((Uint32*)aValue, totalSizeInWords);
212 213
    }//if
    
214
    /**************************************************************************
215
     *	Store the Key information in the TCKEYREQ and KEYINFO signals. 
216
     *************************************************************************/
217
    if (insertKEYINFO(aValue, tKeyInfoPosition, totalSizeInWords) != -1) {
218
      /************************************************************************
219 220 221 222
       * Add one to number of tuple key attributes defined. 
       * If all have been defined then set the operation state to indicate 
       * that tuple key is defined. 
       * Thereby no more search conditions are allowed in this version.
223 224
       ***********************************************************************/
      Uint32 tNoKeysDef = theNoOfTupKeyLeft - 1;
225 226
      Uint32 tErrorLine = theErrorLine;
      unsigned char tInterpretInd = theInterpretIndicator;
227
      theNoOfTupKeyLeft = tNoKeysDef;
228 229
      tErrorLine++;
      theErrorLine = tErrorLine;
230 231
      
      if (tNoKeysDef == 0) {	
232 233 234 235 236 237 238 239 240 241 242 243 244

        // re-order keyinfo if not entered in order
        if (m_accessTable->m_noOfKeys != 1) {
          for (Uint32 i = 0; i < m_accessTable->m_noOfKeys; i++) {
            Uint32 k = theTupleKeyDefined[i][0]; // column_no
            if (m_accessTable->m_columns[k]->m_keyInfoPos != i) {
              DBUG_PRINT("info", ("key disorder at %d", i));
              reorderKEYINFO();
              break;
            }
          }
        }

245 246 247 248 249 250
	if (tOpType == UpdateRequest) {
	  if (tInterpretInd == 1) {
	    theStatus = GetValue;
	  } else {
	    theStatus = SetValue;
	  }//if
pekka@mysql.com's avatar
pekka@mysql.com committed
251
	  DBUG_RETURN(0);
252 253 254
	} else if ((tOpType == ReadRequest) || (tOpType == DeleteRequest) ||
		   (tOpType == ReadExclusive)) {
	  theStatus = GetValue;
pekka@mysql.com's avatar
pekka@mysql.com committed
255 256 257 258 259 260 261
          // create blob handles automatically
          if (tOpType == DeleteRequest && m_currentTable->m_noOfBlobs != 0) {
            for (unsigned i = 0; i < m_currentTable->m_columns.size(); i++) {
              NdbColumnImpl* c = m_currentTable->m_columns[i];
              assert(c != 0);
              if (c->getBlobType()) {
                if (getBlobHandle(theNdbCon, c) == NULL)
pekka@mysql.com's avatar
pekka@mysql.com committed
262
                  DBUG_RETURN(-1);
pekka@mysql.com's avatar
pekka@mysql.com committed
263 264 265
              }
            }
          }
pekka@mysql.com's avatar
pekka@mysql.com committed
266
	  DBUG_RETURN(0);
267 268
	} else if ((tOpType == InsertRequest) || (tOpType == WriteRequest)) {
	  theStatus = SetValue;
pekka@mysql.com's avatar
pekka@mysql.com committed
269
	  DBUG_RETURN(0);
270 271
	} else {
	  setErrorCodeAbort(4005);
pekka@mysql.com's avatar
pekka@mysql.com committed
272
	  DBUG_RETURN(-1);
273
	}//if
pekka@mysql.com's avatar
pekka@mysql.com committed
274
	DBUG_RETURN(0);
275
      }//if
276
    } else {
pekka@mysql.com's avatar
pekka@mysql.com committed
277
      DBUG_RETURN(-1);
278
    }//if
pekka@mysql.com's avatar
pekka@mysql.com committed
279
    DBUG_RETURN(0);
280
  }
281
  
282 283 284
  if (aValue == NULL) {
    // NULL value in primary key
    setErrorCodeAbort(4505);
pekka@mysql.com's avatar
pekka@mysql.com committed
285
    DBUG_RETURN(-1);
286 287 288 289 290
  }//if
  
  if ( tAttrInfo == NULL ) {      
    // Attribute name not found in table
    setErrorCodeAbort(4004);
pekka@mysql.com's avatar
pekka@mysql.com committed
291
    DBUG_RETURN(-1);
292 293 294 295 296
  }//if

  if (theStatus == GetValue || theStatus == SetValue){
    // All pk's defined
    setErrorCodeAbort(4225);
pekka@mysql.com's avatar
pekka@mysql.com committed
297
    DBUG_RETURN(-1);
298
  }//if
299 300

  ndbout_c("theStatus: %d", theStatus);
301 302 303 304
  
  // If we come here, set a general errorcode
  // and exit
  setErrorCodeAbort(4200);
pekka@mysql.com's avatar
pekka@mysql.com committed
305
  DBUG_RETURN(-1);
306 307 308

 equal_error1:
  setErrorCodeAbort(4205);
pekka@mysql.com's avatar
pekka@mysql.com committed
309
  DBUG_RETURN(-1);
310 311 312

 equal_error2:
  setErrorCodeAbort(4206);
pekka@mysql.com's avatar
pekka@mysql.com committed
313
  DBUG_RETURN(-1);
314 315 316

 equal_error3:
  setErrorCodeAbort(4209);
pekka@mysql.com's avatar
pekka@mysql.com committed
317
  DBUG_RETURN(-1);
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
}

/******************************************************************************
 * int insertKEYINFO(const char* aValue, aStartPosition, 
 *                   anAttrSizeInWords, Uint32 anAttrBitsInLastWord);
 *
 * Return Value:   Return 0 : insertKEYINFO was succesful.
 *                 Return -1: In all other case.   
 * Parameters:     aValue: the data to insert into KEYINFO.
 *    		   aStartPosition : Start position for Tuplekey in 
 *                                  KEYINFO (TCKEYREQ).
 *                 aKeyLenInByte : Length of tuplekey or part of tuplekey
 *                 anAttrBitsInLastWord : Nr of bits in last word. 
 * Remark:         Puts the the data into either TCKEYREQ signal 
 *                 or KEYINFO signal.
 *****************************************************************************/
int
NdbOperation::insertKEYINFO(const char* aValue,
			    register Uint32 aStartPosition,
337
			    register Uint32 anAttrSizeInWords)
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
{
  NdbApiSignal* tSignal;
  NdbApiSignal* tCurrentKEYINFO;
  //register NdbApiSignal* tTCREQ = theTCREQ;
  register Uint32 tAttrPos;
  Uint32 tPosition;
  Uint32 tEndPos;
  Uint32 tPos;
  Uint32 signalCounter;
  Uint32 tData;

/*****************************************************************************
 *	Calculate the end position of the attribute in the key information.  *
 *	Since the first attribute starts at position one we need to subtract *
 *	one to get the correct end position.				     *
 *	We must also remember the last word with only partial information.   *
 *****************************************************************************/
  tEndPos = aStartPosition + anAttrSizeInWords - 1;

357
  if ((tEndPos < 9)) {
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
    register Uint32 tkeyData = *(Uint32*)aValue;
    //TcKeyReq* tcKeyReq = CAST_PTR(TcKeyReq, tTCREQ->getDataPtrSend());
    register Uint32* tDataPtr = (Uint32*)aValue;
    tAttrPos = 1;
    register Uint32* tkeyDataPtr = theKEYINFOptr + aStartPosition - 1;
    // (Uint32*)&tcKeyReq->keyInfo[aStartPosition - 1];
    do {
      tDataPtr++;
      *tkeyDataPtr = tkeyData;
      if (tAttrPos < anAttrSizeInWords) {
        ;
      } else {
        return 0;
      }//if
      tkeyData = *tDataPtr;
      tkeyDataPtr++;
      tAttrPos++;
    } while (1);
    return 0;
  }//if
/*****************************************************************************
 *	Allocate all the KEYINFO signals needed for this key before starting *
 *	to fill the signals with data. This simplifies error handling and    *
 *      avoids duplication of code.					     *
 *****************************************************************************/
  tAttrPos = 0;
  signalCounter = 1;
  while(tEndPos > theTotalNrOfKeyWordInSignal)
  {
    tSignal = theNdb->getSignal();
    if (tSignal == NULL)
    {
      setErrorCodeAbort(4000);
      return -1;
    }
    if (tSignal->setSignal(m_keyInfoGSN) == -1)
    {
      setErrorCodeAbort(4001);
      return -1;
    }
398
    if (theTCREQ->next() != NULL)
399 400
       theLastKEYINFO->next(tSignal);
    else
401 402
      theTCREQ->next(tSignal);

403 404 405 406 407 408 409 410 411 412 413 414
    theLastKEYINFO = tSignal;
    theLastKEYINFO->next(NULL);
    theTotalNrOfKeyWordInSignal += 20;
  }

/*****************************************************************************
 *	Change to variable tPosition for more appropriate naming of rest of  *
 *	the code. We must set up current KEYINFO already here if the last    *
 *	word is a word which is set at LastWordLabel and at the same time    *
 *	this is the first word in a KEYINFO signal.			     *
 *****************************************************************************/
  tPosition = aStartPosition;
415
  tCurrentKEYINFO = theTCREQ->next();
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
 
/*****************************************************************************
 *	Start by filling up Key information in the 8 words allocated in the  *
 *	TC[KEY/INDX]REQ signal.						     *
 *****************************************************************************/
  while (tPosition < 9)
  {
    theKEYINFOptr[tPosition-1] = * (Uint32*)(aValue + (tAttrPos << 2));
    tAttrPos++;
    if (anAttrSizeInWords == tAttrPos)
      goto LastWordLabel;
    tPosition++;
  }

/*****************************************************************************
 *	We must set up the start position of the writing of Key information  *
 *	before we start the writing of KEYINFO signals. If the start is not  *
 *	the first word of the first KEYINFO signals then we must step forward*
 *	to the proper KEYINFO signal and set the signalCounter properly.     *
 *	signalCounter is set to the actual position in the signal ( = 4 for  *
 *	first key word in KEYINFO signal.				     *
 *****************************************************************************/
  tPos = 8;
  while ((tPosition - tPos) > 20)
  {
    tCurrentKEYINFO = tCurrentKEYINFO->next();
    tPos += 20;
  }
  signalCounter = tPosition - tPos + 3;    

/*****************************************************************************
 *	The loop that actually fills in the Key information into the KEYINFO *
 *	signals. Can be optimised by writing larger chunks than 4 bytes at a *
 *	time.								     *
 *****************************************************************************/
  do
  {
    if (signalCounter > 23)
    {
      tCurrentKEYINFO = tCurrentKEYINFO->next();
      signalCounter = 4;
    }
    tCurrentKEYINFO->setData(*(Uint32*)(aValue + (tAttrPos << 2)), 
			     signalCounter);
    tAttrPos++;
    if (anAttrSizeInWords == tAttrPos)
      goto LastWordLabel;
    tPosition++;
    signalCounter++;
  } while (1);

LastWordLabel:
  return 0;
}
pekka@mysql.com's avatar
pekka@mysql.com committed
470

471 472 473 474
void
NdbOperation::reorderKEYINFO()
{
  Uint32 data[4000];
475 476
  Uint32 size = 4000;
  getKeyFromTCREQ(data, size);
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
  Uint32 pos = 1;
  Uint32 k;
  for (k = 0; k < m_accessTable->m_noOfKeys; k++) {
    Uint32 i;
    for (i = 0; i < m_accessTable->m_columns.size(); i++) {
      NdbColumnImpl* col = m_accessTable->m_columns[i];
      if (col->m_pk && col->m_keyInfoPos == k) {
        Uint32 j;
        for (j = 0; j < m_accessTable->m_noOfKeys; j++) {
          if (theTupleKeyDefined[j][0] == i) {
            Uint32 off = theTupleKeyDefined[j][1] - 1;
            Uint32 len = theTupleKeyDefined[j][2];
            assert(off < 4000 && off + len <= 4000);
            int ret = insertKEYINFO((char*)&data[off], pos, len);
            assert(ret == 0);
            pos += len;
            break;
          }
        }
        assert(j < m_accessTable->m_columns.size());
        break;
      }
    }
    assert(i < m_accessTable->m_columns.size());
  }
}

pekka@mysql.com's avatar
pekka@mysql.com committed
504
int
505
NdbOperation::getKeyFromTCREQ(Uint32* data, Uint32 & size)
pekka@mysql.com's avatar
pekka@mysql.com committed
506
{
507 508
  assert(size >= theTupKeyLen && theTupKeyLen > 0);
  size = theTupKeyLen;
pekka@mysql.com's avatar
pekka@mysql.com committed
509 510
  unsigned pos = 0;
  while (pos < 8 && pos < size) {
pekka@mysql.com's avatar
pekka@mysql.com committed
511 512
    data[pos] = theKEYINFOptr[pos];
    pos++;
pekka@mysql.com's avatar
pekka@mysql.com committed
513
  }
514
  NdbApiSignal* tSignal = theTCREQ->next();
pekka@mysql.com's avatar
pekka@mysql.com committed
515 516 517 518 519 520 521 522 523 524
  unsigned n = 0;
  while (pos < size) {
    if (n == 20) {
      tSignal = tSignal->next();
      n = 0;
    }
    data[pos++] = tSignal->getDataPtrSend()[3 + n++];
  }
  return 0;
}
525 526 527 528

int
NdbOperation::handle_distribution_key(const Uint64* value, Uint32 len)
{
529 530
  if(theDistrKeyIndicator_ == 1 || 
     (theNoOfTupKeyLeft > 0 && m_accessTable->m_noOfDistributionKeys > 1))
531 532 533 534 535 536 537 538
  {
    return 0;
  }
  
  if(m_accessTable->m_noOfDistributionKeys == 1)
  {
    setPartitionHash(value, len);
  }
joreland@mysql.com's avatar
joreland@mysql.com committed
539
  else if(theTCREQ->readSignalNumber() == GSN_TCKEYREQ)
540
  {
541 542
    // No support for combined distribution key and scan

543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
    /**
     * Copy distribution key to linear memory
     */
    NdbColumnImpl* const * cols = m_accessTable->m_columns.getBase();
    Uint32 len = 0;
    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)
    {
      tSignal = tSignal->next();
      src = ((KeyInfo*)tSignal->getDataPtrSend())->keyData;
558
      chunk = KeyInfo::DataLength;
559 560 561 562 563 564 565 566
    }

    for(unsigned i = m_accessTable->m_columns.size(); i>0; cols++, i--)
    {
      if (!(* cols)->getPrimaryKey())
	continue;
      
      NdbColumnImpl* tAttrInfo = * cols;
567 568 569 570 571 572 573 574 575 576 577 578 579 580
      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;
      }
      
581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
      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;
      }
    }
613
    setPartitionHash(tmp, dst - (Uint32*)tmp);
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
  }
  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
NdbOperation::setPartitionId(Uint32 value)
{
  theDistributionKey = value;
  theDistrKeyIndicator_ = 1;
}

Uint32
NdbOperation::getPartitionId() const 
{
  return theDistributionKey;
}