ClickHouse / ClickHouse/ClickHouse
Optimise window functions to use projections, where applicable
- Dominant language
- C++
- Stars
- 49.9k
- Forks
- 9k
- Avg merge
- 21h 32m
- Merged PRs (30d)
- 515
Description
### Company or project name
Gridcog
### Use case
If I do
```sql
create table data (
id String,
type String,
n Int32,
projection sum_n (
select type, sum(n) group by type
)
)
```
and then do
```sql
select
type, sum(n)
from data
group by type
```
then the projection will be used. Fabulous!
However, if I do
```sql
select
type, sum(n) over (partition by type), ...
from data
```
,
then the projection is not used.
### Describe the solution you'd like
I'd like for projections to be used to optimise window functions in SELECT and QUALIFY clauses where relevant.
### Describe alternatives you've considered
- live with queries being slower than they theoretically could be
- re-write the query into a CTE + join
### Additional context
CTE+join suggestion came from your support team, thanks Stephen!
Contributor guide
Assessment
This issue has not been assessed yet.