Skip to content

fix(backport): avoid duplicating volatile file projections - #17

Open
discord9 wants to merge 1 commit into
GreptimeTeam:greptimedb-53.1.0-function-signature-exec-errorfrom
discord9:fix/qp-019-volatile-projection
Open

fix(backport): avoid duplicating volatile file projections#17
discord9 wants to merge 1 commit into
GreptimeTeam:greptimedb-53.1.0-function-signature-exec-errorfrom
discord9:fix/qp-019-volatile-projection

Conversation

@discord9

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

File-scan projection pushdown can inline a volatile expression at each outer reference site. A volatile expression aliased once in a subquery is then evaluated multiple times instead of once and reused, producing incorrect results such as different values for two references to the same random() alias.

Apache DataFusion fixed this in apache/datafusion@1e77af8. GreptimeDB's pinned fork revision predates that fix.

What changes are included in this PR?

  • Decline FileScanConfig projection merging when it would duplicate a volatile inner expression.
  • Adapt the upstream volatility/reference-count guard to this fork's physical-expression APIs.
  • Keep deterministic and unreferenced expressions eligible for projection merging.

Are these changes tested?

Yes. Added a focused physical-optimizer regression using a real CSV file scan at one target partition:

cargo test -p datafusion --test core_integration \
  physical_optimizer::projection_pushdown::test_volatile_projection_pushdown_does_not_duplicate_evaluation

Result: 1 passed, 915 filtered out.

Temporarily removing the guard makes the regression test fail with different random-value arrays, confirming that the test exercises the affected optimizer path. cargo fmt --all -- --check and git diff --check also pass.

Are there any user-facing changes?

No API changes. Queries that reuse an aliased volatile expression over a file scan now preserve evaluate-once semantics by retaining the materializing projection.

Signed-off-by: discord9 <discord9@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant