Skip to content
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

optimize count(*) #4555

Merged
merged 2 commits into from
Aug 19, 2022
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
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