Avoid re-evaluating expressions in filters and projections
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
This patterns shows up pretty often:
```sql
select expensive(col)
from t
where expensive(col)
```
A pathological case is variant / json:
```sql
select variant_get(col, 'key')
from t
from variant_get(col, 'key')
```
There's two issues here:
1. Until we solve projection pushdown (https://github.com/apache/datafusion/issues/14993) if `key` is not shredded we materialize the entire `col` and then extract `key` in a `ProjectionExec`.
2. Even once that is resolved, or in the case that `key` is not shredded evaluating `variant_get(col, 'key')` itself is expensive we still re-compute `variant_get(col, 'key')` twice: once for the filter and once for the projection.
Contributor guide
Research direction
Start by reading the filter and projection behavior described in the SQL examples, including ProjectionExec and the projection-pushdown issue #14993. Determine how repeated expressions such as variant_get(col, 'key') are represented and evaluated, then define completion as avoiding duplicate evaluation while preserving the query results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- data-engineering, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100