Skip to content

Add schema-aware optimizer child rewrites - #23686

Open
sakshichitnis27 wants to merge 2 commits into
apache:mainfrom
sakshichitnis27:issue/23666-schema-aware-child-rewrites
Open

Add schema-aware optimizer child rewrites#23686
sakshichitnis27 wants to merge 2 commits into
apache:mainfrom
sakshichitnis27:issue/23666-schema-aware-child-rewrites

Conversation

@sakshichitnis27

Copy link
Copy Markdown

Fixes #23666

Summary

  • Add an optimizer-local helper for schema-aware direct-child rewrites.
  • Recompute a parent schema only when a rewritten child’s schema changes.
  • Migrate EliminateCrossJoin to use the helper.
  • Preserve existing in-place optimizer schema protection.
  • Add tests for schema-changing and schema-preserving child rewrites.

This is an internal optimizer refactor and does not change SQL-visible behavior.

Testing

  • cargo fmt --all --check
  • cargo test -p datafusion-optimizer

The optimizer tests passed, including unit tests, integration tests, and doctests.
cargo clippy is currently blocked by an unrelated existing dead_code error in
datafusion-physical-expr.

@github-actions github-actions Bot added the optimizer Optimizer rules label Jul 18, 2026
@codecov-commenter

codecov-commenter commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.58621% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.75%. Comparing base (2e3626e) to head (6f918d0).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
datafusion/optimizer/src/optimizer.rs 75.92% 0 Missing and 13 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23686      +/-   ##
==========================================
- Coverage   80.75%   80.75%   -0.01%     
==========================================
  Files        1096     1096              
  Lines      373588   373642      +54     
  Branches   373588   373642      +54     
==========================================
+ Hits       301691   301719      +28     
- Misses      53896    53902       +6     
- Partials    18001    18021      +20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kosiew kosiew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sakshichitnis27
Thanks for working on this.

Could we consider migrating remaining owned-child rewrite path in datafusion/optimizer/src/optimize_projections/mod.rs' fn optimize_projections

    // Rewrite children of the plan
    let transformed_plan = plan.map_children(|child| {

to map_children_recompute_schema_if_needed in a follow-up, while keeping the separate optimize_subqueries handling?

It currently uses a manual map_children followed by an unconditional recompute_schema() whenever a transformation occurs. Using the new helper would keep the child-schema cache invariant more consistently owned by one API, and it may also avoid unnecessary recomputes when a child's internals change without affecting its schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor: Add an optimizer-local helper for schema-aware child rewrites

3 participants