8000 fixed issue #6031: Broken LIMIT in nested list iterations (#6032) · mnemosdev/arangodb@0660044 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0660044

Browse files
authored
fixed issue arangodb#6031: Broken LIMIT in nested list iterations (arangodb#6032)
1 parent 2ae7b78 commit 0660044

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
v3.3.14 (XXXX-XX-XX)
2+
--------------------
3+
4+
* fixed issue #6031: Broken LIMIT in nested list iterations
5+
6+
17
v3.3.13 (2018-07-26)
28
--------------------
39

arangod/Aql/EnumerateListBlock.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,13 @@ AqlItemBlock* EnumerateListBlock::getSome(size_t, size_t atMost) {
111111
else {
112112
sizeInVar = inVarReg.length();
113113
}
114+
114115

115116
if (sizeInVar == 0) {
116117
res = nullptr;
117118
} else {
118119
size_t toSend = (std::min)(atMost, sizeInVar - _index);
119-
120+
120121
// create the result
121122
res.reset(requestBlock(toSend, getPlanNode()->getRegisterPlan()->nrRegs[getPlanNode()->getDepth()]));
122123

@@ -146,6 +147,7 @@ AqlItemBlock* EnumerateListBlock::getSome(size_t, size_t atMost) {
146147

147148
if (_index == sizeInVar) {
148149
_index = 0;
150+
149151
// advance read position in the current block . . .
150152
if (++_pos == cur->size()) {
151153
returnBlock(cur);
@@ -169,7 +171,7 @@ size_t EnumerateListBlock::skipSome(size_t atLeast, size_t atMost) {
169171
}
170172

171173
size_t skipped = 0;
172-
174+
173175
while (skipped < atLeast) {
174176
if (_buffer.empty()) {
175177
size_t toFetch = (std::min)(DefaultBatchSize(), atMost);
@@ -202,13 +204,15 @@ size_t EnumerateListBlock::skipSome(size_t atLeast, size_t atMost) {
202204
else {
203205
sizeInVar = inVarReg.length();
204206
}
205-
207+
206208
if (atMost < sizeInVar - _index) {
207209
// eat just enough of inVariable . . .
210+
atLeast -= atMost;
208211
_index += atMost;
209212
skipped += atMost;
210213
} else {
211214
// eat the whole of the current inVariable and proceed . . .
215+
atLeast -= (sizeInVar - _index);
212216
skipped += (sizeInVar - _index);
213217
_index = 0;
214218
if (++_pos == cur->size()) {

js/server/tests/aql/aql-queries-optimizer-limit-noncluster.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,15 @@ function ahuacatlQueryOptimizerLimitTestSuite () {
777777
var actual = getQueryResults(query[0]);
778778
assertEqual(query[1], actual, query);
779779
});
780+
},
781+
782+
testLimitNestedLoops: function() {
783+
let expected = [[1, 1], [1, 2], [1, 3], [1, 4], [2, 1], [2, 2], [2, 3], [2, 4]];
784+
let query = "FOR i IN 1..2 FOR j IN 1..4 LIMIT @limit, 2 RETURN [i , j]";
785+
for (let i = 0; i <= 8; ++i) {
786+
let actual = getQueryResults(query, { limit: i });
787+
assertEqual(expected.slice(i, i + 2), actual, i);
788+
}
780789
}
781790

782791
};

0 commit comments

Comments
 (0)
0