8000 fixed issue #10440: Incorrect sorting with sort criteria partially co… · arangodb/arangodb@d8ee8fd · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit d8ee8fd

Browse files
jsteemannKVS85
authored andcommitted
fixed issue #10440: Incorrect sorting with sort criteria partially covered by index (#10444)
1 parent f4d1cec commit d8ee8fd

File tree

4 files changed

+13
-23
lines changed

4 files changed

+13
-23
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
v3.4.9 (XXXX-XX-XX)
22
-------------------
33

4+
* Fixed issue #10440: Incorrect sorting with sort criteria partially covered
5+
by index.
6+
47
* Fixed UPSERT matching.
58

69
Empty objects in the `UPSERT { ... }` expression will not be omitted anymore:

arangod/Aql/OptimizerRules.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,12 +3153,6 @@ struct SortToIndexNode final : public WalkerWorker<ExecutionNode> {
31533153
// sorted GatherNode in the cluster
31543154
indexNode->needsGatherNodeSort(true);
31553155
_modified = true;
3156-
} else if (numCovered > 0 && sortCondition.isUnidirectional()) {
3157-
// remove the first few attributes if they are constant
3158-
SortNode* sortNode =
3159-
ExecutionNode::castTo<SortNode*>(_plan->getNodeById(_sortNode->id()));
3160-
sortNode->removeConditions(numCovered);
3161-
_modified = true;
31623156
}
31633157
}
31643158
}

arangod/Aql/SortCondition.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,25 +184,21 @@ size_t SortCondition::coveredAttributes(
184184
}
185185

186186
// no match
187-
bool isConstant = false;
188-
189187
if (isContained(indexAttributes, field.attributes) &&
190188
isContained(_constAttributes, field.attributes)) {
191189
// no field match, but a constant attribute
192-
isConstant = true;
193190
++fieldsPosition;
194191
++numCovered;
192+
continue;
195193
}
196194

197-
if (!isConstant && isContained(_constAttributes, indexAttributes[i])) {
195+
if (isContained(_constAttributes, indexAttributes[i])) {
198196
// no field match, but a constant attribute
199-
isConstant = true;
200197
++i; // next index field
198+
continue;
201199
}
202200

203-
if (!isConstant) {
204-
break;
205-
}
201+
break;
206202
}
207203

208204
TRI_ASSERT(numCovered <= _fields.size());

tests/js/server/aql/aql-optimizer-rule-use-index-for-sort.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,16 @@ function optimizerRuleTestSuite() {
189189
[ "FOR v IN " + colName + " FILTER v.b == 1 SORT v.b, v.a RETURN 1", false, true ],
190190
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.b, v.a RETURN 1", true, false ],
191191
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.b RETURN 1", true, false ],
192-
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.c RETURN 1", true, true ],
192+
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.c RETURN 1", false, true ],
193193
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.b, v.a RETURN 1", true, false ],
194-
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.b, v.c RETURN 1", true, true ]
194+
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.b, v.c RETURN 1", false, true ]
195195
];
196196

197197
queries.forEach(function(query) {
198198
var result = AQL_EXPLAIN(query[0]);
199199
if (query[1]) {
200200
assertNotEqual(-1, removeAlwaysOnClusterRules(result.plan.rules).indexOf(ruleName), query[0]);
201-
}
202-
else {
201+
} else {
203202
assertEqual(-1, removeAlwaysOnClusterRules(result.plan.rules).indexOf(ruleName), query[0]);
204203
}
205204
if (query[2]) {
@@ -402,7 +401,6 @@ function optimizerRuleTestSuite() {
402401
// place since the index can't fullfill all of the sorting criteria.
403402
////////////////////////////////////////////////////////////////////////////////
404403
testSortMoreThanIndexed: function () {
405-
406404
var query = "FOR v IN " + colName + " FILTER v.a == 1 SORT v.a, v.c RETURN [v.a, v.b, v.c]";
407405
// no index can be used for v.c -> sort has to remain in place!
408406
var XPresult;
@@ -431,7 +429,7 @@ function optimizerRuleTestSuite() {
431429
QResults[2] = AQL_EXECUTE(query, { }, paramIndexFromSort_IndexRange).json;
432430
XPresult = AQL_EXPLAIN(query, { }, paramIndexFromSort_IndexRange);
433431

434-
assertEqual([ ruleName, secondRuleName ], removeAlwaysOnClusterRules(XPresult.plan.rules).sort());
432+
assertEqual([ secondRuleName ], removeAlwaysOnClusterRules(XPresult.plan.rules).sort());
435433
// The sortnode and its calculation node should not have been removed.
436434
hasSortNode(XPresult);
437435
hasCalculationNodes(XPresult, 4);
@@ -1124,7 +1122,7 @@ function optimizerRuleTestSuite() {
11241122
testSortModifyFilterCondition : function () {
11251123
var query = "FOR v IN " + colName + " FILTER v.a == 123 SORT v.a, v.xxx RETURN v";
11261124
var rules = AQL_EXPLAIN(query).plan.rules;
1127-
assertNotEqual(-1, rules.indexOf(ruleName));
1125+
assertEqual(-1, rules.indexOf(ruleName));
11281126
assertNotEqual(-1, rules.indexOf(secondRuleName));
11291127
assertNotEqual(-1, rules.indexOf("remove-filter-covered-by-index"));
11301128

@@ -1135,9 +1133,8 @@ function optimizerRuleTestSuite() {
11351133
++seen;
11361134
assertFalse(node.reverse);
11371135
} else if (node.type === "SortNode") {
1138-
// first sort condition (v.a) should have been removed because it is const
11391136
++seen;
1140-
assertEqual(1, node.elements.length);
1137+
assertEqual(2, node.elements.length);
11411138
}
11421139
});
11431140
assertEqual(2, seen);

0 commit comments

Comments
 (0)
0