Skip to content

Commit 27c16e7

Browse files
author
Jan Wedvik
committed
This commit concerns pushed queries (i.e. those using the SPJ block).
This commit adds checks to ensure that a pushed query should not have more than 32 operations. This is a limit set by the protocol towards the data nodes. (Unique index lookups count as two operations).
1 parent b226ff8 commit 27c16e7

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

storage/ndb/src/ndbapi/NdbQueryBuilder.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ class NdbQueryLookupOperationDefImpl : public NdbQueryOperationDefImpl
181181
const NdbQueryOptionsImpl& options,
182182
const char* ident,
183183
Uint32 ix,
184+
Uint32 id,
184185
int& error);
185186

186187
virtual const NdbQueryLookupOperationDef& getInterface() const
@@ -213,8 +214,9 @@ class NdbQueryPKLookupOperationDefImpl : public NdbQueryLookupOperationDefImpl
213214
const NdbQueryOptionsImpl& options,
214215
const char* ident,
215216
Uint32 ix,
217+
Uint32 id,
216218
int& error)
217-
: NdbQueryLookupOperationDefImpl(table,keys,options,ident,ix,error)
219+
: NdbQueryLookupOperationDefImpl(table,keys,options,ident,ix,id,error)
218220
{}
219221

220222
virtual NdbQueryOperationDef::Type getType() const
@@ -242,8 +244,10 @@ class NdbQueryIndexOperationDefImpl : public NdbQueryLookupOperationDefImpl
242244
const NdbQueryOptionsImpl& options,
243245
const char* ident,
244246
Uint32 ix,
247+
Uint32 id,
245248
int& error)
246-
: NdbQueryLookupOperationDefImpl(table,keys,options,ident,ix,error),
249+
// Add 1 to 'id' since index lookup is serialized as two operations.
250+
: NdbQueryLookupOperationDefImpl(table,keys,options,ident,ix,id+1,error),
247251
m_index(index)
248252
{}
249253

@@ -276,8 +280,9 @@ class NdbQueryTableScanOperationDefImpl : public NdbQueryScanOperationDefImpl
276280
const NdbQueryOptionsImpl& options,
277281
const char* ident,
278282
Uint32 ix,
283+
Uint32 id,
279284
int& error)
280-
: NdbQueryScanOperationDefImpl(table,options,ident,ix,error),
285+
: NdbQueryScanOperationDefImpl(table,options,ident,ix,id,error),
281286
m_interface(*this)
282287
{}
283288

@@ -859,6 +864,7 @@ NdbQueryBuilder::readTuple(const NdbDictionary::Table* table, // Primary key
859864
options ? options->getImpl() : defaultOptions,
860865
ident,
861866
m_impl.m_operations.size(),
867+
m_impl.getNextId(),
862868
error);
863869

864870
returnErrIf(m_impl.takeOwnership(op)!=0, Err_MemoryAlloc);
@@ -928,6 +934,7 @@ NdbQueryBuilder::readTuple(const NdbDictionary::Index* index, // Unique key l
928934
options ? options->getImpl() : defaultOptions,
929935
ident,
930936
m_impl.m_operations.size(),
937+
m_impl.getNextId(),
931938
error);
932939

933940
returnErrIf(m_impl.takeOwnership(op)!=0, Err_MemoryAlloc);
@@ -962,6 +969,7 @@ NdbQueryBuilder::scanTable(const NdbDictionary::Table* table,
962969
options ? options->getImpl() : defaultOptions,
963970
ident,
964971
m_impl.m_operations.size(),
972+
m_impl.getNextId(),
965973
error);
966974

967975
returnErrIf(m_impl.takeOwnership(op)!=0, Err_MemoryAlloc);
@@ -1004,6 +1012,7 @@ NdbQueryBuilder::scanIndex(const NdbDictionary::Index* index,
10041012
options ? options->getImpl() : defaultOptions,
10051013
ident,
10061014
m_impl.m_operations.size(),
1015+
m_impl.getNextId(),
10071016
error);
10081017

10091018
returnErrIf(m_impl.takeOwnership(op)!=0, Err_MemoryAlloc);
@@ -1194,26 +1203,22 @@ NdbQueryDefImpl(const Vector<NdbQueryOperationDefImpl*>& operations,
11941203
return;
11951204
}
11961205

1197-
Uint32 nodeId = 0;
1198-
11991206
/* Grab first word, such that serialization of operation 0 will start from
12001207
* offset 1, leaving space for the length field to be updated later
12011208
*/
12021209
m_serializedDef.append(0);
12031210
for(Uint32 i = 0; i<m_operations.size(); i++){
12041211
NdbQueryOperationDefImpl* op = m_operations[i];
1205-
op->assignQueryOperationId(nodeId);
12061212
error = op->serializeOperation(m_serializedDef);
12071213
if(unlikely(error != 0)){
12081214
return;
12091215
}
12101216
}
1211-
assert (nodeId >= m_operations.size());
12121217

12131218
// Set length and number of nodes in tree.
12141219
Uint32 cntLen;
12151220
QueryTree::setCntLen(cntLen,
1216-
nodeId,
1221+
m_operations[m_operations.size()-1]->getQueryOperationId()+1,
12171222
m_serializedDef.getSize());
12181223
m_serializedDef.put(0,cntLen);
12191224

@@ -1579,8 +1584,9 @@ NdbQueryLookupOperationDefImpl::NdbQueryLookupOperationDefImpl (
15791584
const NdbQueryOptionsImpl& options,
15801585
const char* ident,
15811586
Uint32 ix,
1587+
Uint32 id,
15821588
int& error)
1583-
: NdbQueryOperationDefImpl(table,options,ident,ix,error),
1589+
: NdbQueryOperationDefImpl(table,options,ident,ix,id,error),
15841590
m_interface(*this)
15851591
{
15861592
int i;
@@ -1601,8 +1607,9 @@ NdbQueryIndexScanOperationDefImpl::NdbQueryIndexScanOperationDefImpl (
16011607
const NdbQueryOptionsImpl& options,
16021608
const char* ident,
16031609
Uint32 ix,
1610+
Uint32 id,
16041611
int& error)
1605-
: NdbQueryScanOperationDefImpl(table,options,ident,ix,error),
1612+
: NdbQueryScanOperationDefImpl(table,options,ident,ix,id,error),
16061613
m_interface(*this),
16071614
m_index(index)
16081615
{
@@ -1841,12 +1848,13 @@ NdbQueryOperationDefImpl::NdbQueryOperationDefImpl (
18411848
const NdbQueryOptionsImpl& options,
18421849
const char* ident,
18431850
Uint32 ix,
1851+
Uint32 id,
18441852
int& error)
18451853
:m_isPrepared(false),
18461854
m_diskInChildProjection(false),
18471855
m_table(table),
18481856
m_ident(ident),
1849-
m_ix(ix), m_id(ix),
1857+
m_ix(ix), m_id(id),
18501858
m_options(options),
18511859
m_parent(NULL),
18521860
m_children(),
@@ -1859,6 +1867,11 @@ NdbQueryOperationDefImpl::NdbQueryOperationDefImpl (
18591867
error = Err_MemoryAlloc;
18601868
return;
18611869
}
1870+
if (unlikely(m_id >= NDB_SPJ_MAX_TREE_NODES))
1871+
{
1872+
error = QRY_DEFINITION_TOO_LARGE;
1873+
return;
1874+
}
18621875
if (m_options.m_parent != NULL)
18631876
{
18641877
m_parent = m_options.m_parent;
@@ -2690,8 +2703,9 @@ NdbQueryScanOperationDefImpl::NdbQueryScanOperationDefImpl (
26902703
const NdbQueryOptionsImpl& options,
26912704
const char* ident,
26922705
Uint32 ix,
2706+
Uint32 id,
26932707
int& error)
2694-
: NdbQueryOperationDefImpl(table,options,ident,ix,error)
2708+
: NdbQueryOperationDefImpl(table,options,ident,ix,id,error)
26952709
{}
26962710

26972711
int

storage/ndb/src/ndbapi/NdbQueryBuilderImpl.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,6 @@ class NdbQueryOperationDefImpl
343343
const NdbInterpretedCode* getInterpretedCode() const
344344
{ return m_options.m_interpretedCode; }
345345

346-
Uint32 assignQueryOperationId(Uint32& nodeId)
347-
{ if (getType()==NdbQueryOperationDef::UniqueIndexAccess) nodeId++;
348-
m_id = nodeId++;
349-
return m_id;
350-
}
351-
352346
// Establish a linked parent <-> child relationship with this operation
353347
int linkWithParent(NdbQueryOperationDefImpl* parentOp);
354348

@@ -418,6 +412,7 @@ class NdbQueryOperationDefImpl
418412
const NdbQueryOptionsImpl& options,
419413
const char* ident,
420414
Uint32 ix,
415+
Uint32 id,
421416
int& error);
422417
public:
423418
// Get the ordinal position of this operation within the query def.
@@ -475,7 +470,7 @@ class NdbQueryOperationDefImpl
475470
const NdbTableImpl& m_table;
476471
const char* const m_ident; // Optional name specified by aplication
477472
const Uint32 m_ix; // Index of this operation within operation array
478-
Uint32 m_id; // Operation id when materialized into queryTree.
473+
const Uint32 m_id; // Operation id when materialized into queryTree.
479474
// If op has index, index id is 'm_id-1'.
480475

481476
// Optional (or default) options specified when building query:
@@ -505,6 +500,7 @@ class NdbQueryScanOperationDefImpl :
505500
const NdbQueryOptionsImpl& options,
506501
const char* ident,
507502
Uint32 ix,
503+
Uint32 id,
508504
int& error);
509505

510506
virtual bool isScanOperation() const
@@ -563,6 +559,7 @@ class NdbQueryIndexScanOperationDefImpl : public NdbQueryScanOperationDefImpl
563559
const NdbQueryOptionsImpl& options,
564560
const char* ident,
565561
Uint32 ix,
562+
Uint32 id,
566563
int& error);
567564

568565
// Append pattern for creating a single bound value to serialized code
@@ -666,6 +663,13 @@ class NdbQueryBuilderImpl
666663

667664
bool contains(const NdbQueryOperationDefImpl*);
668665

666+
// Get interal operation number of the next operation.
667+
Uint32 getNextId() const
668+
{
669+
return m_operations.size() == 0 ? 0 :
670+
m_operations[m_operations.size()-1]->getQueryOperationId()+1;
671+
}
672+
669673
NdbQueryBuilder m_interface;
670674
NdbError m_error;
671675

0 commit comments

Comments
 (0)