18 #include <NdbDictionary.hpp>
19 #include "NdbIndexScanOperation.hpp"
20 #include "NdbQueryBuilder.hpp"
21 #include "NdbQueryBuilderImpl.hpp"
22 #include <ndb_global.h>
24 #include "signaldata/QueryTree.hpp"
26 #include "NdbDictionaryImpl.hpp"
27 #include <NdbRecord.hpp>
28 #include "AttributeHeader.hpp"
30 #include <NdbInterpretedCode.hpp>
52 static const bool doPrintQueryTree =
false;
55 static const int Err_MemoryAlloc = 4000;
56 static const int Err_FinaliseNotCalled = 4519;
59 setErrorCode(NdbQueryBuilderImpl* qb,
int aErrorCode)
60 { qb->setErrorCode(aErrorCode);
65 { qb->getImpl().setErrorCode(aErrorCode);
73 #define returnErrIf(cond,err) \
74 if (unlikely((cond))) \
75 { ::setErrorCode(this,err); \
98 NdbConstOperandImpl(),
120 NdbConstOperandImpl(),
127 const double m_value;
134 NdbConstOperandImpl(), m_value(value) {}
141 const char*
const m_value;
149 : NdbConstOperandImpl(),
155 int convert2ColumnType();
157 const void*
const m_value;
173 virtual const NdbQueryOperandImpl*
const* getKeyOperands()
const
181 const NdbQueryOptionsImpl& options,
187 {
return m_interface; }
192 virtual bool isScanOperation()
const
197 NdbQueryOperandImpl* m_keys[MAX_ATTRIBUTES_IN_INDEX+1];
213 const NdbQueryOptionsImpl& options,
242 const NdbQueryOptionsImpl& options,
264 virtual int serializeOperation(Uint32Buffer& serializedDef);
267 {
return m_interface; }
276 const NdbQueryOptionsImpl& options,
280 : NdbQueryScanOperationDefImpl(table,options,ident,ix,error),
295 NdbQueryDef::NdbQueryDef(NdbQueryDefImpl& impl) : m_impl(impl)
297 NdbQueryDef::~NdbQueryDef()
301 NdbQueryDef::getNoOfOperations()
const
302 {
return m_impl.getNoOfOperations();
306 NdbQueryDef::getQueryOperation(Uint32
index)
const
307 {
return &m_impl.getQueryOperation(index).getInterface();
311 NdbQueryDef::getQueryOperation(
const char* ident)
const
312 {
const NdbQueryOperationDefImpl *opDef = m_impl.getQueryOperation(ident);
313 return (opDef!=NULL) ? &opDef->getInterface() : NULL;
317 NdbQueryDef::isScanQuery()
const
318 {
return m_impl.isScanQuery();
322 NdbQueryDef::getQueryType()
const
323 {
return m_impl.getQueryType();
327 NdbQueryDef::getImpl()
const{
340 m_impl.getQueryOperation(0
U).printTree(0,
Bitmask<(NDB_SPJ_MAX_TREE_NODES+31)/32>());
347 NdbQueryOperand::NdbQueryOperand(NdbQueryOperandImpl& impl) : m_impl(impl)
349 NdbConstOperand::NdbConstOperand(NdbQueryOperandImpl& impl) :
NdbQueryOperand(impl)
351 NdbParamOperand::NdbParamOperand(NdbQueryOperandImpl& impl) :
NdbQueryOperand(impl)
353 NdbLinkedOperand::NdbLinkedOperand(NdbQueryOperandImpl& impl) :
NdbQueryOperand(impl)
357 NdbQueryOperand::~NdbQueryOperand()
359 NdbConstOperand::~NdbConstOperand()
361 NdbParamOperand::~NdbParamOperand()
363 NdbLinkedOperand::~NdbLinkedOperand()
371 inline NdbQueryOperandImpl&
381 {
return static_cast<NdbConstOperandImpl&
>(op.
getImpl());
385 {
return static_cast<NdbParamOperandImpl&
>(op.
getImpl());
389 {
return static_cast<NdbLinkedOperandImpl&
>(op.
getImpl());
402 NdbParamOperand::getName()
const
408 NdbParamOperand::getEnum()
const
419 static NdbQueryOptionsImpl defaultOptions;
421 NdbQueryOptions::NdbQueryOptions()
422 : m_pimpl(&defaultOptions)
425 NdbQueryOptions::~NdbQueryOptions()
427 if (m_pimpl!=&defaultOptions)
431 const NdbQueryOptionsImpl&
432 NdbQueryOptions::getImpl()
const
440 if (m_pimpl==&defaultOptions)
442 m_pimpl =
new NdbQueryOptionsImpl;
443 if (unlikely(m_pimpl==0))
445 return Err_MemoryAlloc;
448 m_pimpl->m_scanOrder = ordering;
455 if (m_pimpl==&defaultOptions)
457 m_pimpl =
new NdbQueryOptionsImpl;
458 if (unlikely(m_pimpl==0))
460 return Err_MemoryAlloc;
463 m_pimpl->m_matchType = matchType;
470 if (m_pimpl==&defaultOptions)
472 m_pimpl =
new NdbQueryOptionsImpl;
473 if (unlikely(m_pimpl==0))
475 return Err_MemoryAlloc;
478 m_pimpl->m_parent = &parent->
getImpl();
485 if (m_pimpl==&defaultOptions)
487 m_pimpl =
new NdbQueryOptionsImpl;
488 if (unlikely(m_pimpl==0))
490 return Err_MemoryAlloc;
493 return m_pimpl->copyInterpretedCode(code);
497 NdbQueryOptionsImpl::~NdbQueryOptionsImpl()
499 delete m_interpretedCode;
502 NdbQueryOptionsImpl::NdbQueryOptionsImpl(
const NdbQueryOptionsImpl& src)
503 : m_matchType(src.m_matchType),
504 m_scanOrder(src.m_scanOrder),
505 m_parent(src.m_parent),
506 m_interpretedCode(NULL)
508 if (src.m_interpretedCode)
510 copyInterpretedCode(*src.m_interpretedCode);
522 if (unlikely(!(src.m_flags & NdbInterpretedCode::Finalised)))
524 return Err_FinaliseNotCalled;
526 if (src.m_instructions_length == 0)
532 if (unlikely(interpretedCode==NULL))
534 return Err_MemoryAlloc;
537 const int error = interpretedCode->
copy(src);
540 delete interpretedCode;
545 if (m_interpretedCode)
546 delete m_interpretedCode;
548 m_interpretedCode = interpretedCode;
556 NdbQueryOperationDef::NdbQueryOperationDef(NdbQueryOperationDefImpl& impl) : m_impl(impl)
558 NdbQueryLookupOperationDef::NdbQueryLookupOperationDef(NdbQueryOperationDefImpl& impl) :
NdbQueryOperationDef(impl)
560 NdbQueryScanOperationDef::NdbQueryScanOperationDef(NdbQueryOperationDefImpl& impl) :
NdbQueryOperationDef(impl)
562 NdbQueryTableScanOperationDef::NdbQueryTableScanOperationDef(NdbQueryOperationDefImpl& impl) :
NdbQueryScanOperationDef(impl)
564 NdbQueryIndexScanOperationDef::NdbQueryIndexScanOperationDef(NdbQueryOperationDefImpl& impl) :
NdbQueryScanOperationDef(impl)
569 NdbQueryOperationDef::~NdbQueryOperationDef()
571 NdbQueryLookupOperationDef::~NdbQueryLookupOperationDef()
573 NdbQueryScanOperationDef::~NdbQueryScanOperationDef()
575 NdbQueryTableScanOperationDef::~NdbQueryTableScanOperationDef()
577 NdbQueryIndexScanOperationDef::~NdbQueryIndexScanOperationDef()
580 NdbQueryOperationDefImpl::~NdbQueryOperationDefImpl()
583 if (m_parent != NULL)
585 m_parent->removeChild(
this);
587 for (Uint32
i = 0;
i<m_children.size();
i++)
589 assert(m_children[
i]->m_parent ==
this);
590 m_children[
i]->m_parent = NULL;
599 NdbQueryOperationDefImpl&
617 {
return static_cast<NdbQueryIndexScanOperationDefImpl&
>(op.
getImpl());
628 NdbQueryOperationDef::getNoOfParentOperations()
const
634 NdbQueryOperationDef::getParentOperation(Uint32
i)
const
636 return &
::getImpl(*this).getParentOperation(i).getInterface();
640 NdbQueryOperationDef::getNoOfChildOperations()
const
646 NdbQueryOperationDef::getChildOperation(Uint32 i)
const
648 return &
::getImpl(*this).getChildOperation(i).getInterface();
652 NdbQueryOperationDef::getTypeName(Type
type)
657 return "PrimaryKeyAccess";
659 return "UniqueIndexAccess";
663 return "OrderedIndexScan";
665 return "<Invalid NdbQueryOperationDef::Type value>";
671 NdbQueryOperationDef::getType()
const
694 NdbQueryBuilderImpl*
const impl =
new NdbQueryBuilderImpl();
695 if (likely (impl != NULL))
697 if (likely(impl->getNdbError().code == 0))
699 return &impl->m_interface;
704 assert(impl->getNdbError().code == Err_MemoryAlloc);
720 NdbQueryBuilder::NdbQueryBuilder(NdbQueryBuilderImpl& impl)
724 NdbQueryBuilder::~NdbQueryBuilder()
727 inline NdbQueryBuilderImpl&
728 NdbQueryBuilder::getImpl()
const
735 return m_impl.getNdbError();
743 NdbQueryBuilder::constValue(
const char* value)
745 returnErrIf(value==0,QRY_REQ_ARG_IS_NULL);
751 NdbQueryBuilder::constValue(
const void* value, Uint32 len)
753 returnErrIf(value == 0, QRY_REQ_ARG_IS_NULL);
759 NdbQueryBuilder::constValue(Int32 value)
766 NdbQueryBuilder::constValue(Uint32 value)
773 NdbQueryBuilder::constValue(Int64 value)
780 NdbQueryBuilder::constValue(Uint64 value)
787 NdbQueryBuilder::constValue(
double value)
794 NdbQueryBuilder::paramValue(
const char*
name)
797 (m_impl.addOperand(
new NdbParamOperandImpl(name,getImpl().m_paramCnt++)));
804 returnErrIf(parent==0 || attr==0, QRY_REQ_ARG_IS_NULL);
805 NdbQueryOperationDefImpl& parentImpl = parent->
getImpl();
808 returnErrIf(!m_impl.contains(&parentImpl), QRY_UNKONWN_PARENT);
811 const NdbColumnImpl* column = parentImpl.getTable().getColumn(attr);
812 returnErrIf(column==0, QRY_UNKNOWN_COLUMN);
817 Uint32 colIx = parentImpl.addColumnRef(column, error);
818 if (unlikely(error != 0))
820 m_impl.setErrorCode(error);
825 (m_impl.addOperand(
new NdbLinkedOperandImpl(parentImpl,colIx)));
835 if (m_impl.hasError())
838 returnErrIf(table==0 || keys==0, QRY_REQ_ARG_IS_NULL);
840 const NdbTableImpl& tableImpl = NdbTableImpl::getImpl(*table);
847 for (i=0; i<keyfields; ++
i)
850 returnErrIf(keys[i]==NULL, QRY_TOO_FEW_KEY_VALUES);
853 returnErrIf(keys[keyfields]!=NULL, QRY_TOO_MANY_KEY_VALUES);
859 options ? options->getImpl() : defaultOptions,
861 m_impl.m_operations.size(),
864 returnErrIf(m_impl.takeOwnership(op)!=0, Err_MemoryAlloc);
865 returnErrIf(error!=0, error);
868 for (i=0; i<colcount; ++
i)
873 assert (keyindex==col->m_keyInfoPos);
874 int error = op->m_keys[col->m_keyInfoPos]->bindOperand(*col,*op);
875 returnErrIf(error!=0, error);
878 if (keyindex >= static_cast<Uint32>(keyfields))
883 return &op->m_interface;
896 if (m_impl.hasError())
898 returnErrIf(table==0 || index==0 || keys==0, QRY_REQ_ARG_IS_NULL);
900 const NdbIndexImpl& indexImpl = NdbIndexImpl::getImpl(*index);
901 const NdbTableImpl& tableImpl = NdbTableImpl::getImpl(*table);
904 returnErrIf(indexImpl.m_table_id
906 indexImpl.m_table_version
908 QRY_UNRELATED_INDEX);
912 QRY_WRONG_INDEX_TYPE);
916 for (i=0; i<inxfields; ++
i)
919 returnErrIf(keys[i]==NULL, QRY_TOO_FEW_KEY_VALUES);
922 returnErrIf(keys[inxfields]!=NULL, QRY_TOO_MANY_KEY_VALUES);
928 options ? options->getImpl() : defaultOptions,
930 m_impl.m_operations.size(),
933 returnErrIf(m_impl.takeOwnership(op)!=0, Err_MemoryAlloc);
934 returnErrIf(error!=0, error);
937 for (i=0; i<inxfields; ++
i)
942 error = keys[
i]->
getImpl().bindOperand(col,*op);
943 returnErrIf(error!=0, error);
946 return &op->m_interface;
955 if (m_impl.hasError())
957 returnErrIf(table==0, QRY_REQ_ARG_IS_NULL);
962 options ? options->getImpl() : defaultOptions,
964 m_impl.m_operations.size(),
967 returnErrIf(m_impl.takeOwnership(op)!=0, Err_MemoryAlloc);
968 returnErrIf(error!=0, error);
970 return &op->m_interface;
981 if (m_impl.hasError())
984 returnErrIf(table==0 || index==0, QRY_REQ_ARG_IS_NULL);
986 const NdbIndexImpl& indexImpl = NdbIndexImpl::getImpl(*index);
987 const NdbTableImpl& tableImpl = NdbTableImpl::getImpl(*table);
990 returnErrIf(indexImpl.m_table_id
992 indexImpl.m_table_version
994 QRY_UNRELATED_INDEX);
998 QRY_WRONG_INDEX_TYPE);
1001 NdbQueryIndexScanOperationDefImpl* op =
1002 new NdbQueryIndexScanOperationDefImpl(indexImpl, tableImpl,
1004 options ? options->getImpl() : defaultOptions,
1006 m_impl.m_operations.size(),
1009 returnErrIf(m_impl.takeOwnership(op)!=0, Err_MemoryAlloc);
1010 returnErrIf(error!=0, error);
1014 QRY_TOO_MANY_KEY_VALUES);
1018 for (i=0; i<op->m_bound.lowKeys; ++
i)
1022 const int error = (i<op->m_bound.highKeys && op->m_bound.high[
i]!=op->m_bound.low[
i])
1023 ? op->m_bound.low[i]->bindOperand(col,*op) || op->m_bound.high[
i]->bindOperand(col,*op)
1024 : op->m_bound.low[
i]->bindOperand(col,*op);
1026 returnErrIf(error!=0, error);
1030 for (; i<op->m_bound.highKeys; ++
i)
1033 error = op->m_bound.high[
i]->bindOperand(col,*op);
1034 returnErrIf(error!=0, error);
1037 return &op->m_interface;
1041 NdbQueryBuilder::prepare()
1043 const NdbQueryDefImpl* def = m_impl.prepare();
1044 return (def) ? &def->getInterface() : NULL;
1051 NdbQueryBuilderImpl::NdbQueryBuilderImpl()
1052 : m_interface(*this),
1059 if (errno == ENOMEM)
1062 setErrorCode(Err_MemoryAlloc);
1066 NdbQueryBuilderImpl::~NdbQueryBuilderImpl()
1069 for (Uint32 i=0; i<m_operations.size(); ++
i)
1071 delete m_operations[
i];
1073 for (Uint32 i=0; i<m_operands.size(); ++
i)
1075 delete m_operands[
i];
1079 void NdbQueryBuilderImpl::setErrorCode(
int aErrorCode)
1081 DBUG_ASSERT(aErrorCode != 0);
1082 m_error.code = aErrorCode;
1083 if (aErrorCode == Err_MemoryAlloc)
1090 NdbQueryBuilderImpl::contains(
const NdbQueryOperationDefImpl* opDef)
1092 for (Uint32 i=0; i<m_operations.size(); ++
i)
1093 {
if (m_operations[i] == opDef)
1100 const NdbQueryDefImpl*
1101 NdbQueryBuilderImpl::prepare()
1104 m_operations.size() > 0 &&
1109 NdbQueryDefImpl* def =
new NdbQueryDefImpl(m_operations, m_operands, error);
1110 m_operations.clear();
1114 returnErrIf(def==0, Err_MemoryAlloc);
1115 if(unlikely(error!=0)){
1117 setErrorCode(error);
1127 setErrorCode(QRY_MULTIPLE_SCAN_SORTED);
1131 if (doPrintQueryTree)
1133 ndbout <<
"Query tree:" << endl;
1134 def->getQueryOperation(0
U).printTree(0,
Bitmask<(NDB_SPJ_MAX_TREE_NODES+31)/32>());
1141 NdbQueryBuilderImpl::takeOwnership(NdbQueryOperandImpl* operand)
1143 if (unlikely(operand == NULL))
1145 return Err_MemoryAlloc;
1147 else if (unlikely(m_operands.push_back(operand) != 0))
1149 assert(errno == ENOMEM);
1151 return Err_MemoryAlloc;
1157 NdbQueryBuilderImpl::takeOwnership(NdbQueryOperationDefImpl* operation)
1159 if (unlikely(operation == NULL))
1161 return Err_MemoryAlloc;
1163 else if (unlikely(m_operations.push_back(operation) != 0))
1165 assert(errno == ENOMEM);
1167 return Err_MemoryAlloc;
1173 NdbQueryBuilderImpl::addOperand(NdbQueryOperandImpl* operand)
1175 returnErrIf(takeOwnership(operand)!=0, Err_MemoryAlloc);
1176 return &operand->getInterface();
1186 : m_interface(*this),
1187 m_operations(operations),
1188 m_operands(operands)
1190 if (errno == ENOMEM)
1193 error = Err_MemoryAlloc;
1202 m_serializedDef.append(0);
1203 for(Uint32 i = 0; i<m_operations.size(); i++){
1204 NdbQueryOperationDefImpl* op = m_operations[
i];
1205 op->assignQueryOperationId(nodeId);
1206 error = op->serializeOperation(m_serializedDef);
1207 if(unlikely(error != 0)){
1211 assert (nodeId >= m_operations.size());
1215 QueryTree::setCntLen(cntLen,
1217 m_serializedDef.getSize());
1218 m_serializedDef.put(0,cntLen);
1220 #ifdef __TRACE_SERIALIZATION
1221 ndbout <<
"Serialized tree : ";
1222 for(Uint32 i = 0; i < m_serializedDef.getSize(); i++){
1224 sprintf(buf,
"%.8x", m_serializedDef.get(i));
1225 ndbout << buf <<
" ";
1231 NdbQueryDefImpl::~NdbQueryDefImpl()
1234 for (Uint32 i=0; i<m_operations.size(); ++
i)
1236 delete m_operations[
i];
1238 for (Uint32 i=0; i<m_operands.size(); ++
i)
1240 delete m_operands[
i];
1244 const NdbQueryOperationDefImpl*
1245 NdbQueryDefImpl::getQueryOperation(
const char* ident)
const
1250 Uint32 sz = m_operations.size();
1251 const NdbQueryOperationDefImpl*
const* opDefs = m_operations.getBase();
1252 for(Uint32 i = 0; i<sz; i++, opDefs++){
1253 const char* opName = (*opDefs)->getName();
1254 if(opName!=NULL && strcmp(opName, ident) == 0)
1261 NdbQueryDefImpl::getQueryType()
const
1263 if (!m_operations[0]->isScanOperation())
1266 for (Uint32 i=1; i<m_operations.size(); ++
i)
1268 if (m_operations[i]->isScanOperation())
1279 int NdbInt64ConstOperandImpl::convertUint8()
1281 if (unlikely(m_value < 0 || m_value > 0xFF))
1282 return QRY_NUM_OPERAND_RANGE;
1283 m_converted.val.uint8 = (Uint8)m_value;
1284 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.uint8));
1287 int NdbInt64ConstOperandImpl::convertInt8()
1289 if (unlikely(m_value < -0x80L || m_value > 0x7F))
1290 return QRY_NUM_OPERAND_RANGE;
1291 m_converted.val.int8 = (Int8)m_value;
1292 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.int8));
1295 int NdbInt64ConstOperandImpl::convertUint16()
1297 if (unlikely(m_value < 0 || m_value > 0xFFFF))
1298 return QRY_NUM_OPERAND_RANGE;
1299 m_converted.val.uint16 = (Uint16)m_value;
1300 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.uint16));
1303 int NdbInt64ConstOperandImpl::convertInt16()
1305 if (unlikely(m_value < -0x8000L || m_value > 0x7FFF))
1306 return QRY_NUM_OPERAND_RANGE;
1307 m_converted.val.int16 = (Int16)m_value;
1308 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.int16));
1311 int NdbInt64ConstOperandImpl::convertUint24()
1313 if (unlikely(m_value < 0 || m_value > 0xFFFFFF))
1314 return QRY_NUM_OPERAND_RANGE;
1315 m_converted.val.uint32 = (Uint32)m_value;
1316 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.uint32));
1319 int NdbInt64ConstOperandImpl::convertInt24()
1321 if (unlikely(m_value < -0x800000L || m_value > 0x7FFFFF))
1322 return QRY_NUM_OPERAND_RANGE;
1323 m_converted.val.int32 = (Int32)m_value;
1324 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.int32));
1327 int NdbInt64ConstOperandImpl::convertUint32()
1329 if (unlikely(m_value < 0 || m_value > 0xFFFFFFFF))
1330 return QRY_NUM_OPERAND_RANGE;
1331 m_converted.val.uint32 = (Uint32)m_value;
1332 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.uint32));
1335 int NdbInt64ConstOperandImpl::convertInt32()
1337 if (unlikely(m_value < -((Int64)0x80000000L) || m_value > 0x7FFFFFFF))
1338 return QRY_NUM_OPERAND_RANGE;
1339 m_converted.val.int32 = (Int32)m_value;
1340 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.int32));
1343 int NdbInt64ConstOperandImpl::convertInt64()
1345 m_converted.val.int64 = m_value;
1346 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.int64));
1349 int NdbInt64ConstOperandImpl::convertUint64()
1351 m_converted.val.uint64 = (Uint64)m_value;
1352 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.uint64));
1356 int NdbDoubleConstOperandImpl::convertFloat()
1358 m_converted.val.flt = (float)m_value;
1359 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.flt));
1362 int NdbDoubleConstOperandImpl::convertDouble()
1364 m_converted.val.dbl = m_value;
1365 m_converted.len =
static_cast<Uint32
>(
sizeof(m_converted.val.dbl));
1369 int NdbCharConstOperandImpl::convertChar()
1371 Uint32 len = m_column->getLength();
1372 Uint32 srclen = (m_value) ? static_cast<Uint32>(strlen(m_value)) : 0;
1373 if (unlikely(srclen > len)) {
1375 return QRY_CHAR_OPERAND_TRUNCATED;
1379 char* dst = m_converted.getCharBuffer(len);
1380 if (unlikely(dst==NULL))
1381 return Err_MemoryAlloc;
1383 memcpy (dst, m_value, srclen);
1384 if (unlikely(srclen < len)) {
1385 memset (dst+srclen,
' ', len-srclen);
1391 int NdbCharConstOperandImpl::convertVChar()
1393 Uint32 maxlen = m_column->getLength();
1394 Uint32 len = (m_value) ? static_cast<Uint32>(strlen(m_value)) : 0;
1395 if (unlikely(len > maxlen)) {
1397 return QRY_CHAR_OPERAND_TRUNCATED;
1401 char* dst = m_converted.getCharBuffer(len);
1402 if (unlikely(dst==NULL))
1403 return Err_MemoryAlloc;
1405 memcpy (dst, m_value, len);
1414 NdbGenericConstOperandImpl::convert2ColumnType()
1417 Uint32 maxSize = m_column->getSizeInBytes();
1421 if (likely(m_column->m_arrayType == NDB_ARRAYTYPE_FIXED))
1423 if (unlikely(len != maxSize))
1424 return QRY_OPERAND_HAS_WRONG_TYPE;
1426 dst = m_converted.getCharBuffer(len);
1427 if (unlikely(dst==NULL))
1428 return Err_MemoryAlloc;
1430 else if (m_column->m_arrayType == NDB_ARRAYTYPE_SHORT_VAR)
1432 if (unlikely(len+1 > maxSize))
1433 return QRY_CHAR_OPERAND_TRUNCATED;
1435 dst = m_converted.getCharBuffer(len+1);
1436 if (unlikely(dst==NULL))
1437 return Err_MemoryAlloc;
1439 *(Uint8*)dst++ = (Uint8)len;
1441 else if (m_column->m_arrayType == NDB_ARRAYTYPE_MEDIUM_VAR)
1443 if (unlikely(len+2 > maxSize))
1444 return QRY_CHAR_OPERAND_TRUNCATED;
1446 dst = m_converted.getCharBuffer(len+2);
1447 if (unlikely(dst==NULL))
1448 return Err_MemoryAlloc;
1450 *(Uint8*)dst++ = (Uint8)(len & 0xFF);
1451 *(Uint8*)dst++ = (Uint8)(len >> 8);
1458 memcpy (dst, m_value, len);
1464 NdbConstOperandImpl::convert2ColumnType()
1466 switch(m_column->getType()) {
1481 case NdbDictionary::Column::Decimalunsigned:
return convertUDec();
1499 case NdbDictionary::Column::Olddecimalunsigned:
1513 NdbConstOperandImpl::bindOperand(
1515 NdbQueryOperationDefImpl& operation)
1517 const int error = NdbQueryOperandImpl::bindOperand(column,operation);
1518 if (unlikely(error))
1521 return convert2ColumnType();
1526 NdbLinkedOperandImpl::bindOperand(
1528 NdbQueryOperationDefImpl& operation)
1532 if (unlikely(column.m_type != parentColumn.m_type ||
1533 column.m_precision != parentColumn.m_precision ||
1534 column.m_scale != parentColumn.m_scale ||
1535 column.m_length != parentColumn.m_length ||
1536 column.m_cs != parentColumn.m_cs))
1537 return QRY_OPERAND_HAS_WRONG_TYPE;
1541 return QRY_OPERAND_HAS_WRONG_TYPE;
1546 const int error = operation.linkWithParent(&this->m_parentOperation);
1547 if (unlikely(error))
1550 return NdbQueryOperandImpl::bindOperand(column,operation);
1555 NdbParamOperandImpl::bindOperand(
1557 NdbQueryOperationDefImpl& operation)
1561 return QRY_OPERAND_HAS_WRONG_TYPE;
1563 const int res = operation.addParamRef(
this);
1564 if (unlikely(res != 0))
1568 return NdbQueryOperandImpl::bindOperand(column,operation);
1576 NdbQueryLookupOperationDefImpl::NdbQueryLookupOperationDefImpl (
1579 const NdbQueryOptionsImpl& options,
1583 : NdbQueryOperationDefImpl(table,options,ident,ix,error),
1587 for (i=0; i<MAX_ATTRIBUTES_IN_INDEX; ++
i)
1588 {
if (keys[i] == NULL)
1593 assert (keys[i] == NULL);
1597 NdbQueryIndexScanOperationDefImpl::NdbQueryIndexScanOperationDefImpl (
1601 const NdbQueryOptionsImpl& options,
1605 : NdbQueryScanOperationDefImpl(table,options,ident,ix,error),
1609 memset(&m_bound, 0,
sizeof m_bound);
1612 if (bound->m_low!=NULL) {
1614 for (i=0; bound->m_low[
i] != NULL; ++
i)
1615 { assert (i<MAX_ATTRIBUTES_IN_INDEX);
1616 m_bound.low[
i] = &bound->m_low[
i]->
getImpl();
1618 m_bound.lowKeys =
i;
1620 m_bound.lowKeys = 0;
1623 if (bound->m_high!=NULL) {
1625 for (i=0; bound->m_high[
i] != NULL; ++
i)
1626 { assert (i<MAX_ATTRIBUTES_IN_INDEX);
1627 m_bound.high[
i] = &bound->m_high[
i]->
getImpl();
1629 m_bound.highKeys =
i;
1631 m_bound.highKeys = 0;
1634 m_bound.lowIncl = bound->m_lowInclusive;
1635 m_bound.highIncl = bound->m_highInclusive;
1638 m_bound.lowKeys = m_bound.highKeys = 0;
1639 m_bound.lowIncl = m_bound.highIncl =
true;
1644 NdbQueryIndexScanOperationDefImpl::checkPrunable(
1645 const Uint32Buffer& keyInfo,
1646 Uint32 shortestBound,
1648 Uint32& hashValue)
const
1655 const NdbRecord*
const indexRecord = m_index.getDefaultRecord();
1660 const Uint32 prefixLength = indexRecord->m_min_distkey_prefix_length;
1666 else if (shortestBound < prefixLength)
1672 assert( (m_bound.lowKeys+m_bound.highKeys==0) ||
1673 (m_bound.lowKeys >= prefixLength && m_bound.highKeys >= prefixLength));
1684 while (keyPos < keyInfo.getSize())
1686 const Uint32 keyEnd = keyPos + (keyInfo.get(keyPos) >> 16);
1691 Uint32 keyPartNo = 0;
1692 Uint32 distKeyPartNo = 0;
1693 while (keyPos < keyEnd)
1697 (keyInfo.get(keyPos) & 0xF);
1700 attHead1.getByteSize() };
1702 keyPos += 1+1+attHead1.getDataSize();
1705 = NdbColumnImpl::getImpl(*m_index.getColumn(keyPartNo));
1724 if (keyPos == keyEnd ||
1738 attHeadHigh.getByteSize() };
1740 keyPos += 1+1+attHeadHigh.getDataSize();
1756 assert(column.m_keyInfoPos < tableRecord->noOfColumns);
1757 const NdbRecord::Attr& recAttr = tableRecord->columns[column.m_keyInfoPos];
1763 assert((recAttr.flags & NdbRecord::IsMysqldShrinkVarchar) == 0);
1765 (*recAttr.compare_function)(recAttr.charset_info,
1766 keyPart1.ptr, keyPart1.len,
1767 highKeyPart.ptr, highKeyPart.len);
1780 if (getTable().m_columns[column.m_keyInfoPos]->m_distributionKey)
1784 for (Uint32 i = 0; i < column.m_keyInfoPos; i++)
1786 if (getTable().m_columns[i]->m_distributionKey)
1792 assert(distKeyPtr->len == 0 && distKeyPtr->ptr == NULL);
1793 *distKeyPtr = keyPart1;
1798 if (keyPartNo == prefixLength)
1811 Uint32 newHashValue = 0;
1814 if (unlikely(error))
1819 hashValue = newHashValue;
1821 else if (hashValue != newHashValue)
1839 NdbQueryOperationDefImpl::NdbQueryOperationDefImpl (
1841 const NdbQueryOptionsImpl& options,
1845 :m_isPrepared(false),
1846 m_diskInChildProjection(false),
1856 if (unlikely(errno == ENOMEM))
1859 error = Err_MemoryAlloc;
1862 if (m_options.m_parent != NULL)
1864 m_parent = m_options.m_parent;
1865 const int res = m_parent->addChild(
this);
1866 if (unlikely(res != 0))
1876 NdbQueryOperationDefImpl::addChild(NdbQueryOperationDefImpl* childOp)
1878 for (Uint32 i=0; i<m_children.size(); ++
i)
1879 {
if (m_children[i] == childOp)
1882 if (likely(m_children.push_back(childOp) == 0))
1888 assert(errno == ENOMEM);
1889 return Err_MemoryAlloc;
1894 NdbQueryOperationDefImpl::removeChild(
const NdbQueryOperationDefImpl* childOp)
1896 for (
unsigned i=0; i<m_children.size(); ++
i)
1898 if (m_children[i] == childOp)
1900 m_children.erase(i);
1907 NdbQueryOperationDefImpl::isChildOf(
const NdbQueryOperationDefImpl* parentOp)
const
1909 if (m_parent != NULL)
1910 {
if (this->m_parent == parentOp)
1914 for (Uint32 j=0; j<parentOp->getNoOfChildOperations(); j++)
1915 {
if (&parentOp->getChildOperation(j) ==
this)
1922 else if (m_parent->isChildOf(parentOp))
1931 NdbQueryOperationDefImpl::linkWithParent(NdbQueryOperationDefImpl* parentOp)
1933 if (this->isChildOf(parentOp))
1939 if (m_parent != NULL)
1948 if (parentOp->isChildOf(m_parent))
1950 m_parent->removeChild(
this);
1955 return QRY_MULTIPLE_PARENTS;
1958 m_parent = parentOp;
1959 parentOp->addChild(
this);
1966 NdbQueryOperationDefImpl::addColumnRef(
const NdbColumnImpl* column,
1970 for (spjRef=0; spjRef<m_spjProjection.size(); ++spjRef)
1971 {
if (m_spjProjection[spjRef] == column)
1976 if (unlikely(m_spjProjection.push_back(column) != 0))
1978 assert(errno == ENOMEM);
1979 error = Err_MemoryAlloc;
1982 if (column->getStorageType() == NDB_STORAGETYPE_DISK)
1984 m_diskInChildProjection =
true;
1989 int NdbQueryOperationDefImpl::addParamRef(
const NdbParamOperandImpl* param)
1991 if (unlikely(m_params.push_back(param) != 0))
1993 assert(errno == ENOMEM);
1994 return Err_MemoryAlloc;
2010 m_seq = buffer.alloc(1 + size/2);
2011 assert (size <= 0xFFFF);
2016 { assert(m_finished);
2021 assert(m_pos < m_size);
2024 if ((m_pos & 1) == 1) {
2025 m_seq[m_pos/2] |= (value<<16);
2027 m_seq[m_pos/2] = value;
2034 assert(m_pos == m_size);
2035 assert(!m_finished);
2038 if ((m_pos & 1) == 0) {
2039 m_seq[m_pos/2] |= (0xBABE<<16);
2051 const Uint32 m_size;
2058 NdbQueryOperationDefImpl::appendParentList(Uint32Buffer& serializedDef)
const
2060 if (getParentOperation() != NULL)
2063 assert (getParentOperation()->getQueryOperationId() < getQueryOperationId());
2064 parentSeq.append(getParentOperation()->getQueryOperationId());
2066 return DABits::NI_HAS_PARENT;
2076 NdbQueryOperationDefImpl::appendChildProjection(Uint32Buffer& serializedDef)
const
2078 Uint32 requestInfo = 0;
2079 if (m_spjProjection.size() > 0 || getNoOfChildOperations() > 0)
2081 requestInfo |= DABits::NI_LINKED_ATTR;
2082 Uint16Sequence spjProjSeq(serializedDef, m_spjProjection.size());
2083 for (Uint32 i = 0; i<m_spjProjection.size(); i++)
2085 spjProjSeq.
append(m_spjProjection[i]->getColumnNo());
2087 spjProjSeq.finish();
2089 if (m_diskInChildProjection)
2100 static void printMargin(Uint32 depth,
2101 Bitmask<(NDB_SPJ_MAX_TREE_NODES+31)/32> hasMoreSiblingsMask,
2107 for (Uint32 i = 0; i<depth-1; i++)
2109 if (hasMoreSiblingsMask.get(i+1))
2122 else if (hasMoreSiblingsMask.get(depth))
2134 NdbQueryOperationDefImpl::printTree(Uint32 depth,
2135 Bitmask<(NDB_SPJ_MAX_TREE_NODES+31)/32>
2136 hasMoreSiblingsMask)
const
2139 Bitmask<(NDB_SPJ_MAX_TREE_NODES+31)/32> firstLineMask = hasMoreSiblingsMask;
2140 firstLineMask.
set(depth);
2141 printMargin(depth, firstLineMask,
false);
2144 printMargin(depth, hasMoreSiblingsMask,
true);
2145 ndbout << NdbQueryOperationDef::getTypeName(getType()) << endl;
2146 printMargin(depth, hasMoreSiblingsMask,
false);
2148 ndbout <<
" opNo: " << getQueryOperationIx() << endl;
2149 printMargin(depth, hasMoreSiblingsMask,
false);
2150 ndbout <<
" table: " << getTable().
getName() << endl;
2151 if (getIndex() != NULL)
2153 printMargin(depth, hasMoreSiblingsMask,
false);
2154 ndbout <<
" index: " << getIndex()->getName() << endl;
2159 hasMoreSiblingsMask.set(depth+1);
2160 for (
int childNo = 0;
2161 childNo < static_cast<int>(getNoOfChildOperations()) - 1;
2164 getChildOperation(childNo).printTree(depth+1, hasMoreSiblingsMask);
2166 if (getNoOfChildOperations() > 0)
2169 hasMoreSiblingsMask.clear(depth+1);
2170 getChildOperation(getNoOfChildOperations() - 1)
2171 .printTree(depth+1, hasMoreSiblingsMask);
2179 Uint32 appendedPattern = 0;
2185 if (getQueryOperationIx() == 0)
2188 if (m_keys[0]!=NULL)
2190 Uint32 startPos = serializedDef.getSize();
2191 serializedDef.append(0);
2194 const NdbQueryOperandImpl* key = m_keys[0];
2197 switch(key->getKind()){
2198 case NdbQueryOperandImpl::Linked:
2200 appendedPattern |= DABits::NI_KEY_LINKED;
2201 const NdbLinkedOperandImpl& linkedOp = *
static_cast<const NdbLinkedOperandImpl*
>(key);
2202 const NdbQueryOperationDefImpl* parent = getParentOperation();
2204 while (parent != &linkedOp.getParentOperation())
2210 parent = parent->getParentOperation();
2211 assert(parent != NULL);
2217 serializedDef.append(QueryPattern::col(linkedOp.getLinkedColumnIx()));
2220 case NdbQueryOperandImpl::Const:
2222 appendedPattern |= DABits::NI_KEY_CONSTS;
2223 const NdbConstOperandImpl& constOp = *
static_cast<const NdbConstOperandImpl*
>(key);
2226 const Uint32 wordCount = AttributeHeader::getDataSize(constOp.getSizeInBytes());
2228 serializedDef.append(QueryPattern::data(wordCount));
2229 serializedDef.appendBytes(constOp.getAddr(),constOp.getSizeInBytes());
2232 case NdbQueryOperandImpl::Param:
2234 appendedPattern |= DABits::NI_KEY_PARAMS;
2235 serializedDef.append(QueryPattern::param(paramCnt++));
2241 key = m_keys[++keyNo];
2242 }
while (key!=NULL);
2245 Uint32 len = serializedDef.getSize() - startPos -1;
2246 serializedDef.put(startPos, (paramCnt << 16) | (len));
2249 return appendedPattern;
2254 NdbQueryIndexScanOperationDefImpl::appendPrunePattern(Uint32Buffer& serializedDef)
const
2256 Uint32 appendedPattern = 0;
2262 if (getQueryOperationIx() == 0)
2265 if (m_bound.lowKeys>0 || m_bound.highKeys>0)
2268 const NdbRecord*
const indexRecord = m_index.getDefaultRecord();
2279 Uint32 distKeys = indexRecord->m_min_distkey_prefix_length;
2280 if (m_bound.lowKeys < distKeys || m_bound.highKeys < distKeys)
2287 for (
unsigned keyNo = 0; keyNo < distKeys; keyNo++)
2289 if (m_bound.low[keyNo] != m_bound.high[keyNo])
2295 Uint32 startPos = serializedDef.getSize();
2296 serializedDef.append(0);
2298 for (
unsigned i = 0; i < indexRecord->distkey_index_length; i++)
2300 const unsigned keyNo = indexRecord->distkey_indexes[
i];
2301 assert(keyNo<indexRecord->noOfColumns);
2303 assert(indexAttr.flags & NdbRecord::IsDistributionKey);
2304 assert(indexAttr.index_attrId<m_bound.lowKeys);
2305 const NdbQueryOperandImpl* key = m_bound.low[indexAttr.index_attrId];
2307 switch(key->getKind())
2309 case NdbQueryOperandImpl::Linked:
2311 appendedPattern |= QN_ScanIndexNode::SI_PRUNE_LINKED;
2312 const NdbLinkedOperandImpl& linkedOp = *
static_cast<const NdbLinkedOperandImpl*
>(key);
2313 const NdbQueryOperationDefImpl* parent = getParentOperation();
2315 while (parent != &linkedOp.getParentOperation())
2321 parent = parent->getParentOperation();
2322 assert(parent != NULL);
2328 serializedDef.append(QueryPattern::col(linkedOp.getLinkedColumnIx()));
2331 case NdbQueryOperandImpl::Const:
2334 const NdbConstOperandImpl& constOp = *
static_cast<const NdbConstOperandImpl*
>(key);
2337 const Uint32 wordCount = AttributeHeader::getDataSize(constOp.getSizeInBytes());
2339 serializedDef.append(QueryPattern::data(wordCount));
2340 serializedDef.appendBytes(constOp.getAddr(),
2341 constOp.getSizeInBytes());
2344 case NdbQueryOperandImpl::Param:
2345 appendedPattern |= QN_ScanIndexNode::SI_PRUNE_PARAMS;
2346 serializedDef.append(QueryPattern::param(paramCnt++));
2354 Uint32 len = serializedDef.getSize() - startPos -1;
2355 serializedDef.put(startPos, (paramCnt << 16) | (len));
2359 return appendedPattern;
2364 NdbQueryIndexScanOperationDefImpl::appendBoundValue(
2365 Uint32Buffer& serializedDef,
2367 const NdbQueryOperandImpl* value,
2368 int& paramCnt)
const
2370 Uint32 appendedPattern = 0;
2373 serializedDef.append(QueryPattern::data(1));
2374 serializedDef.append(type);
2376 switch(value->getKind())
2378 case NdbQueryOperandImpl::Linked:
2380 appendedPattern |= DABits::NI_KEY_LINKED;
2381 const NdbLinkedOperandImpl& linkedOp = *
static_cast<const NdbLinkedOperandImpl*
>(value);
2382 const NdbQueryOperationDefImpl* parent = getParentOperation();
2384 while (parent != &linkedOp.getParentOperation())
2390 parent = parent->getParentOperation();
2391 assert(parent != NULL);
2401 case NdbQueryOperandImpl::Const:
2403 appendedPattern |= DABits::NI_KEY_CONSTS;
2404 const NdbConstOperandImpl& constOp = *
static_cast<const NdbConstOperandImpl*
>(value);
2411 serializedDef.append(QueryPattern::data(1+ah.getDataSize()));
2412 serializedDef.append(ah.m_value);
2413 serializedDef.appendBytes(constOp.getAddr(),constOp.getSizeInBytes());
2416 case NdbQueryOperandImpl::Param:
2418 appendedPattern |= DABits::NI_KEY_PARAMS;
2420 serializedDef.append(QueryPattern::paramHeader(paramCnt++));
2427 return appendedPattern;
2437 NdbQueryIndexScanOperationDefImpl::appendBoundPattern(Uint32Buffer& serializedDef)
const
2439 Uint32 appendedPattern = 0;
2445 if (getQueryOperationIx() == 0)
2448 if (m_bound.lowKeys>0 || m_bound.highKeys>0)
2451 Uint32 startPos = serializedDef.getSize();
2452 serializedDef.append(0);
2454 const uint key_count =
2455 (m_bound.lowKeys >= m_bound.highKeys) ? m_bound.lowKeys : m_bound.highKeys;
2457 for (uint keyNo=0; keyNo<key_count; ++keyNo)
2462 if (keyNo < m_bound.lowKeys &&
2463 keyNo < m_bound.highKeys &&
2464 m_bound.low[keyNo] == m_bound.high[keyNo])
2470 appendBoundValue(serializedDef, bound_type, m_bound.low[keyNo], paramCnt);
2475 if (keyNo < m_bound.lowKeys)
2478 bound_type= m_bound.lowIncl || keyNo+1 < m_bound.lowKeys ?
2482 appendBoundValue(serializedDef, bound_type, m_bound.low[keyNo], paramCnt);
2486 if (keyNo < m_bound.highKeys)
2489 bound_type= m_bound.highIncl || keyNo+1 < m_bound.highKeys ?
2493 appendBoundValue(serializedDef, bound_type, m_bound.high[keyNo], paramCnt);
2499 Uint32 len = serializedDef.getSize() - startPos -1;
2500 serializedDef.put(startPos, (paramCnt << 16) | (len));
2503 return appendedPattern;
2511 assert (m_keys[0]!=NULL);
2513 assert (!m_isPrepared);
2514 m_isPrepared =
true;
2518 Uint32 startPos = serializedDef.getSize();
2519 serializedDef.alloc(QN_LookupNode::NodeSize);
2520 Uint32 requestInfo = 0;
2530 requestInfo |= appendParentList (serializedDef);
2533 requestInfo |= appendKeyPattern(serializedDef);
2536 requestInfo |= appendChildProjection(serializedDef);
2540 if (unlikely(node==NULL)) {
2541 return Err_MemoryAlloc;
2545 node->requestInfo = requestInfo;
2546 const Uint32 length = serializedDef.getSize() - startPos;
2547 if (unlikely(length > 0xFFFF)) {
2548 return QRY_DEFINITION_TOO_LARGE;
2550 QueryNode::setOpLen(node->len, QueryNode::QN_LOOKUP, length);
2553 #ifdef __TRACE_SERIALIZATION
2554 ndbout <<
"Serialized node " << getQueryOperationId() <<
" : ";
2555 for (Uint32 i = startPos; i < serializedDef.getSize(); i++) {
2557 sprintf(buf,
"%.8x", serializedDef.get(i));
2558 ndbout << buf <<
" ";
2571 assert (m_keys[0]!=NULL);
2573 assert (!m_isPrepared);
2574 m_isPrepared =
true;
2582 Uint32 startPos = serializedDef.getSize();
2583 serializedDef.alloc(QN_LookupNode::NodeSize);
2587 assert (getQueryOperationId() > 0);
2588 requestInfo |= appendParentList (serializedDef);
2591 requestInfo |= appendKeyPattern(serializedDef);
2597 requestInfo |= DABits::NI_LINKED_ATTR;
2599 spjProjSeq.
append(getIndex()->getNoOfColumns());
2605 if (unlikely(node==NULL)) {
2606 return Err_MemoryAlloc;
2608 node->tableId = getIndex()->getObjectId();
2609 node->tableVersion = getIndex()->getObjectVersion();
2610 node->requestInfo = requestInfo;
2611 const Uint32 length = serializedDef.getSize() - startPos;
2612 if (unlikely(length > 0xFFFF)) {
2613 return QRY_DEFINITION_TOO_LARGE;
2615 QueryNode::setOpLen(node->len, QueryNode::QN_LOOKUP, length);
2618 #ifdef __TRACE_SERIALIZATION
2619 ndbout <<
"Serialized index " << getQueryOperationId()-1 <<
" : ";
2620 for (Uint32 i = startPos; i < serializedDef.getSize(); i++){
2622 sprintf(buf,
"%.8x", serializedDef.get(i));
2623 ndbout << buf <<
" ";
2631 Uint32 startPos = serializedDef.getSize();
2632 serializedDef.alloc(QN_LookupNode::NodeSize);
2633 Uint32 requestInfo = 0;
2643 { requestInfo |= DABits::NI_HAS_PARENT;
2645 parentSeq.
append(getQueryOperationId()-1);
2651 requestInfo |= DABits::NI_KEY_LINKED;
2652 serializedDef.append(1
U);
2657 requestInfo |= appendChildProjection(serializedDef);
2661 if (unlikely(node==NULL)) {
2662 return Err_MemoryAlloc;
2666 node->requestInfo = requestInfo;
2667 const Uint32 length = serializedDef.getSize() - startPos;
2668 if (unlikely(length > 0xFFFF)) {
2669 return QRY_DEFINITION_TOO_LARGE;
2671 QueryNode::setOpLen(node->len, QueryNode::QN_LOOKUP, length);
2674 #ifdef __TRACE_SERIALIZATION
2675 ndbout <<
"Serialized node " << getQueryOperationId() <<
" : ";
2676 for (Uint32 i = startPos; i < serializedDef.getSize(); i++) {
2678 sprintf(buf,
"%.8x", serializedDef.get(i));
2679 ndbout << buf <<
" ";
2688 NdbQueryScanOperationDefImpl::NdbQueryScanOperationDefImpl (
2690 const NdbQueryOptionsImpl& options,
2694 : NdbQueryOperationDefImpl(table,options,ident,ix,error)
2698 NdbQueryScanOperationDefImpl::serialize(Uint32Buffer& serializedDef,
2701 bool isRoot = (getQueryOperationIx()==0);
2704 assert (!m_isPrepared);
2705 m_isPrepared =
true;
2708 Uint32 startPos = serializedDef.getSize();
2709 assert (QN_ScanFragNode::NodeSize==QN_ScanIndexNode::NodeSize);
2710 serializedDef.alloc(QN_ScanFragNode::NodeSize);
2711 Uint32 requestInfo = 0;
2714 requestInfo |= appendParentList (serializedDef);
2717 requestInfo |= appendBoundPattern(serializedDef);
2720 requestInfo |= appendChildProjection(serializedDef);
2723 requestInfo |= appendPrunePattern(serializedDef);
2725 const Uint32 length = serializedDef.getSize() - startPos;
2726 if (unlikely(length > 0xFFFF))
2728 return QRY_DEFINITION_TOO_LARGE;
2734 if (unlikely(node==NULL)) {
2735 return Err_MemoryAlloc;
2739 node->requestInfo = requestInfo;
2740 QueryNode::setOpLen(node->len, QueryNode::QN_SCAN_FRAG, length);
2745 if (unlikely(node==NULL)) {
2746 return Err_MemoryAlloc;
2752 QueryNode::setOpLen(node->len, QueryNode::QN_SCAN_INDEX, length);
2755 #ifdef __TRACE_SERIALIZATION
2756 ndbout <<
"Serialized node " << getQueryOperationId() <<
" : ";
2757 for(Uint32 i = startPos; i < serializedDef.getSize(); i++){
2759 sprintf(buf,
"%.8x", serializedDef.get(i));
2760 ndbout << buf <<
" ";
2769 NdbQueryTableScanOperationDefImpl
2770 ::serializeOperation(Uint32Buffer& serializedDef)
2772 return NdbQueryScanOperationDefImpl::serialize(serializedDef, getTable());
2777 NdbQueryIndexScanOperationDefImpl
2778 ::serializeOperation(Uint32Buffer& serializedDef)
2780 return NdbQueryScanOperationDefImpl::serialize(serializedDef, *m_index.getIndexTable());
2799 main(
int argc,
const char** argv)
2801 printf(
"Hello, I am the unit test for NdbQueryBuilder\n");
2827 { qb->constValue(
"d005"),
2828 qb->constValue(110567),
2834 assert (readManager);
2836 printf(
"readManager : %p\n", readManager);
2837 printf(
"Index : %p\n", readManager->
getIndex());
2838 printf(
"Table : %p\n", readManager->
getTable());