8000 fixed issue #10440: Incorrect sorting with sort criteria partially covered by index by jsteemann · Pull Request #10442 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

fixed issue #10440: Incorrect sorting with sort criteria partially covered by index #10442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions arangod/Aql/OptimizerRules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3233,12 +3233,6 @@ struct SortToIndexNode final : public WalkerWorker<ExecutionNode> {
// sorted GatherNode in the cluster
indexNode->needsGatherNodeSort(true);
_modified = true;
} else if (numCovered > 0 && sortCondition.isUnidirectional()) {
// remove the first few attributes if they are constant
SortNode* sortNode =
ExecutionNode::castTo<SortNode*>(_plan->getNodeById(_sortNode->id()));
sortNode->removeConditions(numCovered);
_modified = true;
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions arangod/Aql/SortCondition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,21 @@ size_t SortCondition::coveredAttributes(
}

// no match
bool isConstant = false;

if (isContained(indexAttributes, field.attributes) &&
isContained(_constAttributes, field.attributes)) {
// no field match, but a constant attribute
isConstant = true;
++fieldsPosition;
++numCovered;
continue;
}

if (!isConstant && isContained(_constAttributes, indexAttributes[i])) {
if (isContained(_constAttributes, indexAttributes[i])) {
// no field match, but a constant attribute
isConstant = true;
++i; // next index field
continue;
}

if (!isConstant) {
break;
}
break;
}

TRI_ASSERT(numCovered <= _fields.size());
Expand Down
15 changes: 6 additions & 9 deletions tests/js/server/aql/aql-optimizer-rule-use-index-for-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,16 @@ function optimizerRuleTestSuite() {
[ "FOR v IN " + colName + " FILTER v.b == 1 SORT v.b, v.a RETURN 1", false, true ],
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.b, v.a RETURN 1", true, false ],
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.b RETURN 1", true, false ],
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.c RETURN 1", true, true ],
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.c RETURN 1", false, true ],
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.b, v.a RETURN 1", true, false ],
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.b, v.c RETURN 1", true, true ]
[ "FOR v IN " + colName + " FILTER v.a == 1 && v.b == 1 SORT v.a, v.b, v.c RETURN 1", false, true ]
];

queries.forEach(function(query) {
var result = AQL_EXPLAIN(query[0]);
if (query[1]) {
assertNotEqual(-1, removeAlwaysOnClusterRules(result.plan.rules).indexOf(ruleName), query[0]);
}
else {
} else {
assertEqual(-1, removeAlwaysOnClusterRules(result.plan.rules).indexOf(ruleName), query[0]);
}
if (query[2]) {
Expand Down Expand Up @@ -409,7 +408,6 @@ function optimizerRuleTestSuite() {
// place since the index can't fullfill all of the sorting criteria.
////////////////////////////////////////////////////////////////////////////////
testSortMoreThanIndexed: function () {

var query = "FOR v IN " + colName + " FILTER v.a == 1 SORT v.a, v.c RETURN [v.a, v.b, v.c]";
// no index can be used for v.c -> sort has to remain in place!
var XPresult;
Expand Down Expand Up @@ -438,7 +436,7 @@ function optimizerRuleTestSuite() {
QResults[2] = AQL_EXECUTE(query, { }, paramIndexFromSort_IndexRange).json;
XPresult = AQL_EXPLAIN(query, { }, paramIndexFromSort_IndexRange);

assertEqual([ ruleName, secondRuleName ], removeAlwaysOnClusterRules(XPresult.plan.rules).sort());
assertEqual([ secondRuleName ], removeAlwaysOnClusterRules(XPresult.plan.rules).sort());
// The sortnode and its calculation node should not have been removed.
hasSortNode(XPresult);
hasCalculationNodes(XPresult, 4);
Expand Down Expand Up @@ -1193,7 +1191,7 @@ function optimizerRuleTestSuite() {
testSortModifyFilterCondition : function () {
var query = "FOR v IN " + colName + " FILTER v.a == 123 SORT v.a, v.xxx RETURN v";
var rules = AQL_EXPLAIN(query).plan.rules;
assertNotEqual(-1, rules.indexOf(ruleName));
assertEqual(-1, rules.indexOf(ruleName));
assertNotEqual(-1, rules.indexOf(secondRuleName));
assertNotEqual(-1, rules.indexOf("remove-filter-covered-by-index"));

Expand All @@ -1204,9 +1202,8 @@ function optimizerRuleTestSuite() {
++seen;
assertFalse(node.reverse);
} else if (node.type === "SortNode") {
// first sort condition (v.a) should have been removed because it is const
++seen;
assertEqual(1, node.elements.length);
assertEqual(2, node.elements.length);
}
});
assertEqual(2, seen);
Expand Down
0