[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. |
Beta Was this translation helpful? Give feedback.
-
For Order By, it could also be optimized in the case: agg without group by. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Also optimize DISTINCT ON, see #685 |
Beta Was this translation helpful? Give feedback.
-
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) |
Beta Was this translation helpful? Give feedback.
-
Implemented by #685 . |
Beta Was this translation helpful? Give feedback.
-
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?
Beta Was this translation helpful? Give feedback.
All reactions