ClickHouse / ClickHouse/ClickHouse

Optimise window functions to use projections, where applicable

Open
#76,845 3 comments 0 reactions 0 assignees View on GitHub
comp-projections external feature
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.