apache / apache/datafusion

Avoid re-evaluating expressions in filters and projections

Open
#17,599 6 comments 0 reactions 0 assignees View on GitHub
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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.