Skip to content

doc: Document the physical optimizer contract - #26351

Open
2010YOUY01 wants to merge 3 commits into
apache:mainfrom
2010YOUY01:optimizer-contract
Open

2010YOUY01 wants to merge 3 commits into
apache:mainfrom
2010YOUY01:optimizer-contract

Conversation

@2010YOUY01

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

See issue for rationale, this PR documents what has been agreed on

What changes are included in this PR?

doc only

What is the testing strategy for this PR?

Are there any user-facing changes?

//! example, [`EnsureRequirements`] enforces input distribution and ordering.
//! Some constraints remain implicit or are documented only in individual rules.
//!
//! - **Optimization Coverage:** A non-default rule order may expose rules to

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A CI tool might help to verify optimization coverage is reachable from queries.

@codecov-commenter

codecov-commenter commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.89%. Comparing base (e732212) to head (748e3b7).
⚠️ Report is 33 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #26351      +/-   ##
==========================================
+ Coverage   82.83%   82.89%   +0.06%     
==========================================
  Files        1151     1154       +3     
  Lines      455332   457620    +2288     
  Branches   455332   457620    +2288     
==========================================
+ Hits       377165   379350    +2185     
- Misses      55262    55263       +1     
- Partials    22905    23007     +102     

☔ 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.

@alamb alamb 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.

Thank you @2010YOUY01 and @jayzhan211 and @zhuqi-lucas

I think this is better than what we current have, so I am approving it. However, I found it somewhat hard to understand as written and have a few suggestions on how to improve it.

It would also be fine with me to merge this PR in as is and I can make a follow on PR with a proposal to improve the wording

//! disables the distinct aggregation soft-limit optimization. Custom pipelines
//! require more care, as described below.
//!
//! ## Custom Optimizer Pipelines

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.

I found this somewhat confusingly worded. I would find it clearer if we started by stating the invariants:

  1. All optimizer rules must preserve plan correctness (the output plan can be run and produces the same results as the input plan). We can note there are some built in plans that aren't yet there (like EnforceRequirements)
  2. That reordering optimizer rules (other than the exceptions) should result in a plan that produces the same results

Then we could then move on to the explicit warning that adding / reordering rules may make some of the built in rules less effective as some built in rules (e.g. CombinePartialFinalAggregate) match certain plan shapes.

p.s. I would love to split out EnforceRequrements into its own Analyzer thing precisely so we don't have to have to mention the special case for EnforceRequirements above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review! I've addressed other feedbacks since they're smaller wording improvements, but not this one.

I think i don't fully get how you want to express it better, feel free to directly push changes, or do a follow-up PR 🙏🏼

Comment thread datafusion/physical-optimizer/src/optimizer.rs Outdated
Comment thread datafusion/physical-optimizer/src/optimizer.rs Outdated
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.

Discussion: Define the Contract for Custom Physical Optimizer Pipelines

5 participants