Add bounded distinct count optimization
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Is your feature request related to a problem or challenge?
Optimize queries like
```sql
SELECT count(DISTINCT col) > 1 FROM table;
```
For cases where col has high cardinality. The issue is that currently the distinct accumulates all values first and only then are they counted, so we both insert values into the distinct accumulator, leaving CPU on the table, and we pay for memory unnecessarily.
### Describe the solution you'd like
Add a bound to count distinct and only insert into the tracked values collection up to N+1.
### Describe alternatives you've considered
n/a
### Additional context
I have a prototype of this working, if the general idea sounds good, I can clean it up and submit the PR.
@alamb
Contributor guide
Assessment
This issue has not been assessed yet.