Skip to content

refactor: thread PhysicalOptimizerContext through join_selection stats helpers - #24716

Merged
kosiew merged 3 commits into
apache:mainfrom
asolimando:asolimando/23671-context-threading
Sep 1, 2026
Merged

refactor: thread PhysicalOptimizerContext through join_selection stats helpers#24716
kosiew merged 3 commits into
apache:mainfrom
asolimando:asolimando/23671-context-threading

Conversation

@asolimando

Copy link
Copy Markdown
Member

Which issue does this PR close?

Rationale for this change

JoinSelection's internal statistics helpers each took separate config: &ConfigOptions
and registry: Option<&StatisticsRegistry> parameters. Any new session-scoped CBO input
to these rules (e.g. #21120) would require touching every helper's signature.

What changes are included in this PR?

Replace the config/registry parameter pair on the internal statistics helpers with a
single context: &dyn PhysicalOptimizerContext, reading context.config_options() and
context.statistics_registry() internally. This is a pure internal signature change: all
affected functions are private or pub(crate), with no cross-crate callers. Behavior is
unchanged.

Are these changes tested?

No new tests; this is a non-functional refactor covered by existing tests
(cargo test -p datafusion-physical-optimizer, the physical_optimizer::join_selection
integration tests, and statistics_registry.slt).

Are there any user-facing changes?

No.


Disclaimer: I used AI to assist in the code generation, I have manually reviewed the output and it matches my intention and understanding.

…s helpers

Replace separate config/registry parameters on join_selection stats
helpers with a single &dyn PhysicalOptimizerContext, so a future
session-scoped CBO input only needs a new context trait method
instead of touching every helper signature.
@github-actions github-actions Bot added the optimizer Optimizer rules label Aug 27, 2026
@codecov-commenter

codecov-commenter commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.25926% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.58%. Comparing base (a38bb10) to head (809b30b).
⚠️ Report is 45 commits behind head on main.

Files with missing lines Patch % Lines
...atafusion/physical-optimizer/src/join_selection.rs 59.25% 2 Missing and 9 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #24716      +/-   ##
==========================================
+ Coverage   81.45%   81.58%   +0.12%     
==========================================
  Files        1120     1123       +3     
  Lines      401289   406603    +5314     
  Branches   401289   406603    +5314     
==========================================
+ Hits       326871   331716    +4845     
- Misses      55295    55447     +152     
- Partials    19123    19440     +317     

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

@asolimando
asolimando marked this pull request as ready for review August 27, 2026 10:01
@asolimando

Copy link
Copy Markdown
Member Author

@kosiew a small follow-up of #23651, this is a pure refactor to properly propagate PhysicalOptimizerContext, which is meant to be a convenient way to pass context to physical rules, especially those dealing with CBO, so we can enrich context for statistics propagation without breaking signatures.

I have a question: since it's a pure refactor and it doesn't really alter coverage, I would consider #24716 (comment), wdyt?

Thanks!

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

@asolimando, thanks for working on this. The refactor looks good to me. I don't see any blocking issues. I left one non-blocking suggestion around adding focused coverage for the new context-threading boundary.

.transform_up(|plan| {
statistical_join_selection_subrule(plan, config, registry)
})
.transform_up(|plan| statistical_join_selection_subrule(plan, context))

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.

Could we add a focused test that calls JoinSelection::optimize_with_context with a custom context and statistics registry where the estimates actually change the join decision? The existing registry SLT covers this through the SessionState path, but a test here would directly exercise the context-threading boundary introduced by this refactor. Not blocking, but I think it would be useful coverage.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for your review! It's indeed a good chance to improve coverage on JoinSelection::optimize_with_context itself, I have proposed a test along the line you proposed in 809b30b, let me know if that works for you.

@github-actions github-actions Bot added the core Core DataFusion crate label Aug 31, 2026
@kosiew

kosiew commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🚀
@asolimando
Thank you for your contribution.

@kosiew
kosiew added this pull request to the merge queue Sep 1, 2026
Merged via the queue into apache:main with commit 19d31c5 Sep 1, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thread PhysicalOptimizerContext through join_selection stats helpers (CBO extension pattern)

3 participants