8000 fix some issues with sorted variant of COLLECT (#6433) · arangodb/arangodb@dbe4559 · GitHub
[go: up one dir, main page]

Skip to content

Commit dbe4559

Browse files
authored
fix some issues with sorted variant of COLLECT (#6433)
1 parent 0ebae00 commit dbe4559

File tree

6 files changed

+520
-11
lines changed

6 files changed

+520
-11
lines changed

arangod/Aql/Aggregator.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,16 @@ struct AggregatorMax final : public Aggregator {
226226

227227
struct AggregatorSum final : public Aggregator {
228228
explicit AggregatorSum(transaction::Methods* trx)
229-
: Aggregator(trx), sum(0.0), invalid(false) {}
229+
: Aggregator(trx), sum(0.0), invalid(false), invoked(false) {}
230230

231231
void reset() override {
232232
sum = 0.0;
233233
invalid = false;
234+
invoked = false;
234235
}
235236

236237
void reduce(AqlValue const& cmpValue) override {
238+
invoked = true;
237239
if (!invalid) {
238240
if (cmpValue.isNull(true)) {
239241
// ignore `null` values here
@@ -253,7 +255,7 @@ struct AggregatorSum final : public Aggregator {
253255
}
254256

255257
AqlValue stealValue() override {
256-
if (invalid || std::isnan(sum) || sum == HUGE_VAL || sum == -HUGE_VAL) {
258+
if (invalid || !invoked || std::isnan(sum) || sum == HUGE_VAL || sum == -HUGE_VAL) {
257259
return AqlValue(AqlValueHintNull());
258260
}
259261

@@ -266,6 +268,7 @@ struct AggregatorSum final : public Aggregator {
266268

267269
double sum;
268270
bool invalid;
271+
bool invoked;
269272
};
270273

271274
/// @brief the single-server variant of AVERAGE

arangod/Aql/CollectBlock.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,8 @@ void SortedCollectBlock::emitGroup(AqlItemBlock const* cur, AqlItemBlock* res,
511511
++r) {
512512
it->reduce(getValueForRegister(cur, r, reg));
513513
}
514-
res->setValue(row, _aggregateRegisters[j].first, it->stealValue());
515-
} else {
516-
res->emplaceValue(row, _aggregateRegisters[j].first,
517-
AqlValueHintNull());
518514
}
515+
res->setValue(row, _aggregateRegisters[j].first, it->stealValue());
519516
++j;
520517
}
521518

arangod/Aql/OptimizerRules.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2128,10 +2128,10 @@ struct SortToIndexNode final : public WalkerWorker<ExecutionNode> {
21282128

21292129
IndexIteratorOptions opts;
21302130
opts.ascending = sortCondition.isAscending();
2131-
std::unique_ptr<ExecutionNode> newNode(new IndexNode(
2131+
auto newNode = std::make_unique<IndexNode>(
21322132
_plan, _plan->nextId(),
21332133
enumerateCollectionNode->collection(), outVariable, usedIndexes,
2134-
std::move(condition), opts));
2134+
std::move(condition), opts);
21352135

21362136
auto n = newNode.release();
21372137

@@ -2142,6 +2142,7 @@ struct SortToIndexNode final : public WalkerWorker<ExecutionNode> {
21422142
if (coveredAttributes == sortCondition.numAttributes()) {
21432143
// if the index covers the complete sort condition, we can also remove
21442144
// the sort node
2145+
n->needsGatherNodeSort(true);
21452146
_plan->unlinkNode(_plan->getNodeById(_sortNode->id()));
21462147
}
21472148
}

js/common/modules/@arangodb/aql/explainer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ function printIndexes (indexes) {
332332
var ranges;
333333
if (indexes[i].hasOwnProperty('condition')) {
334334
ranges = indexes[i].condition;
335-
} else {
335+
} else {
336336
ranges = '[ ' + indexes[i].ranges + ' ]';
337337
}
338338

@@ -982,11 +982,11 @@ function processQuery (query, explain) {
982982
if (node.hasOwnProperty('condition') && node.condition.type && node.condition.type === 'n-ary or') {
983983
idx.condition = buildExpression(node.condition.subNodes[i]);
984984
} else {
985-
if (variable !== false) {
985+
if (variable !== false && variable !== undefined) {
986986
idx.condition = variable;
987987
}
988988
}
989-
if (idx.condition === '') {
989+
if (idx.condition === '' || idx.condition === undefined) {
990990
idx.condition = '*'; // empty condition. this is likely an index used for sorting or scanning only
991991
}
992992
indexes.push(idx);

0 commit comments

Comments
 (0)
0