[Ideas] Optimize SQL: select distinct count(a) from t1; #677
Replies: 6 comments 6 replies
|
ORCA already has this feature It's a special case for another general cases. |
1 reply
|
For Order By, it could also be optimized in the case: agg without group by. |
0 replies
|
Do not know helped it or not, but in Clickhouse the same query will look like The small description - https://clickhouse.com/docs/en/sql-reference/aggregate-functions/reference/uniq |
4 replies
However SRF will break this: select count(*), generate_series(1, 4) from t1;
count | generate_series
-------+-----------------
3 | 1
3 | 2
3 | 3
3 | 4
(4 rows) |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Description
User has a auto-generated SQL by 3rd-party like:
However, for such query: Aggregate SQL without Group by, there is one row returned at most.
The first DISTINCT could be removed in theory, then the Unique and Sort(May be other nodes due to planner) on Finalize Aggregate could be avoided.
Currently, Postgres planner doesn't have that feature.
Shall we do it in CBDB?
Pro:
Simply plan tree a little.
Con:
User's SQL is changed, and there may be other risk for planner.
Use case/motivation
No response
Related issues
No response
Are you willing to submit a PR?
All reactions