Skip to content

Commit

Permalink
optimize count(*) (#4555)
Browse files Browse the repository at this point in the history
  • Loading branch information
jievince authored Aug 19, 2022
1 parent 9239b32 commit 2b1b733
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/graph/executor/query/AggregateExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ folly::Future<Status> AggregateExecutor::execute() {
auto iter = ectx_->getResult(agg->inputVar()).iter();
DCHECK(!!iter);
QueryExpressionContext ctx(ectx_);
// We could directly return size of input dataset for `COUNT(*)`
if (groupKeys.empty() && groupItems.size() == 1 && groupItems[0]->toString() == "COUNT(*)") {
DataSet ds;
ds.colNames = agg->colNames();
ds.rows.emplace_back(Row({Value(int64_t(iter->size()))}));
return finish(ResultBuilder().value(Value(std::move(ds))).build());
}

std::unordered_map<List, std::vector<std::unique_ptr<AggData>>, std::hash<nebula::List>> result;

Expand Down
28 changes: 28 additions & 0 deletions tests/tck/features/aggregate/Agg.feature
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,34 @@ Feature: Basic Aggregate and GroupBy
Then the result should be, in any order, with relax comparison:
| a |
| 1 |
When executing query:
"""
GO FROM "Tim Duncan" OVER like YIELD like._dst AS dst | YIELD COUNT(*)
"""
Then the result should be, in any order, with relax comparison:
| COUNT(*) |
| 2 |
When executing query:
"""
GO 3 STEPS FROM "Tim Duncan" OVER like YIELD like._dst AS dst | YIELD COUNT(*)
"""
Then the result should be, in any order, with relax comparison:
| COUNT(*) |
| 5 |
When executing query:
"""
GO 1 to 3 STEPS FROM "Tony Parker" OVER serve BIDIRECT YIELD DISTINCT id($$) AS dst | YIELD COUNT(*)
"""
Then the result should be, in any order, with relax comparison:
| COUNT(*) |
| 41 |
When executing query:
"""
MATCH (v:player) RETURN COUNT(*)
"""
Then the result should be, in any order, with relax comparison:
| COUNT(*) |
| 56 |

Scenario: [1] Basic GroupBy
When executing query:
Expand Down

0 comments on commit 2b1b733

Please sign in to comment.