Skip to content

refactor: remove redundant join-flattening precheck - #25685

Merged
neilconway merged 3 commits into
apache:mainfrom
Toby1009:refactor/eliminate-cross-join-precheck
Sep 24, 2026
Merged

neilconway merged 3 commits into
apache:mainfrom
Toby1009:refactor/eliminate-cross-join-precheck

Conversation

@Toby1009

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #25680.

Rationale for this change

EliminateCrossJoin walks the inner-join subtree twice before rebuilding it. Both callers of can_flatten_join_inputs already establish an inner-join root, and the helper only recurses into inner-join children, so the precheck always succeeds at these call sites.

Removing it avoids the redundant traversal and the need to keep two traversal implementations in sync, while preserving the existing optimized plans.

What changes are included in this PR?

  • Remove can_flatten_join_inputs and its two call-site guards.
  • Make the private flatten_join_inputs helper infallible and update its documentation. Keep filter collection, non-inner join boundaries, and child/subquery rewriting unchanged.
  • Add a focused plan test for preserving a left-join subtree and its filter beneath an inner join, including the inner join's residual filter and output schema.
  • Fix two existing Clippy warnings in multi_group_by.rs to pass the required local checks.

What is the testing strategy for this PR?

  • All 26 eliminate_cross_join tests passed, including preserve_outer_join_boundary.
  • Extended workspace tests passed: 12,112 tests passed, 8 ignored, and all 523 sqllogictest files completed successfully.
  • cargo fmt --all, cargo clippy --all-targets --all-features -- -D warnings, and uv run ./dev/rust_lint.sh passed.
  • Compared the existing six-table self-join and no-join SQL planning workloads against main using a temporary Criterion harness. Across three alternating rounds, physical plans matched and no consistent end-to-end speedup was observed; six-table planning stayed around 4.9 ms. This is a maintainability refactor without a measured performance improvement claim.

Are there any user-facing changes?

No SQL behavior or public API changes.

Remove the always-successful precheck at the inner-join entry points and
make flatten_join_inputs infallible. Preserve outer join boundaries and
filter collection, with a focused plan regression test.

Fix two existing benchmark Clippy warnings required by local checks.

Refs apache#25680
@github-actions github-actions Bot added optimizer Optimizer rules physical-plan Changes to the physical-plan crate labels Sep 24, 2026
@codecov-commenter

codecov-commenter commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.50%. Comparing base (e2ca7f3) to head (a99fa29).

Files with missing lines Patch % Lines
datafusion/optimizer/src/eliminate_cross_join.rs 77.77% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25685      +/-   ##
==========================================
- Coverage   82.50%   82.50%   -0.01%     
==========================================
  Files        1140     1140              
  Lines      438050   438062      +12     
  Branches   438050   438062      +12     
==========================================
- Hits       361415   361407       -8     
- Misses      54829    54841      +12     
- Partials    21806    21814       +8     

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

@jayzhan211
jayzhan211 self-requested a review September 24, 2026 13:06

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

Thanks @Toby1009 👍🏻

@jayzhan211
jayzhan211 added this pull request to the merge queue Sep 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 24, 2026
@neilconway
neilconway added this pull request to the merge queue Sep 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 24, 2026
@neilconway
neilconway added this pull request to the merge queue Sep 24, 2026
Merged via the queue into apache:main with commit 39916a3 Sep 24, 2026
41 checks passed
@Toby1009
Toby1009 deleted the refactor/eliminate-cross-join-precheck branch September 24, 2026 17:04
diegoQuinas pushed a commit to diegoQuinas/datafusion that referenced this pull request Sep 24, 2026
## Which issue does this PR close?

Closes apache#25680.

## Rationale for this change

`EliminateCrossJoin` walks the inner-join subtree twice before
rebuilding it. Both callers of `can_flatten_join_inputs` already
establish an inner-join root, and the helper only recurses into
inner-join children, so the precheck always succeeds at these call
sites.

Removing it avoids the redundant traversal and the need to keep two
traversal implementations in sync, while preserving the existing
optimized plans.

## What changes are included in this PR?

- Remove `can_flatten_join_inputs` and its two call-site guards.
- Make the private `flatten_join_inputs` helper infallible and update
its documentation. Keep filter collection, non-inner join boundaries,
and child/subquery rewriting unchanged.
- Add a focused plan test for preserving a left-join subtree and its
filter beneath an inner join, including the inner join's residual filter
and output schema.
- Fix two existing Clippy warnings in `multi_group_by.rs` to pass the
required local checks.

## What is the testing strategy for this PR?

- All 26 `eliminate_cross_join` tests passed, including
`preserve_outer_join_boundary`.
- Extended workspace tests passed: 12,112 tests passed, 8 ignored, and
all 523 sqllogictest files completed successfully.
- `cargo fmt --all`, `cargo clippy --all-targets --all-features -- -D
warnings`, and `uv run ./dev/rust_lint.sh` passed.
- Compared the existing six-table self-join and no-join SQL planning
workloads against `main` using a temporary Criterion harness. Across
three alternating rounds, physical plans matched and no consistent
end-to-end speedup was observed; six-table planning stayed around 4.9
ms. This is a maintainability refactor without a measured performance
improvement claim.

## Are there any user-facing changes?

No SQL behavior or public API changes.

Co-authored-by: Neil Conway <neil.conway@gmail.com>
Omega359 pushed a commit to Omega359/arrow-datafusion that referenced this pull request Oct 11, 2026
## Which issue does this PR close?

Closes apache#25680.

## Rationale for this change

`EliminateCrossJoin` walks the inner-join subtree twice before
rebuilding it. Both callers of `can_flatten_join_inputs` already
establish an inner-join root, and the helper only recurses into
inner-join children, so the precheck always succeeds at these call
sites.

Removing it avoids the redundant traversal and the need to keep two
traversal implementations in sync, while preserving the existing
optimized plans.

## What changes are included in this PR?

- Remove `can_flatten_join_inputs` and its two call-site guards.
- Make the private `flatten_join_inputs` helper infallible and update
its documentation. Keep filter collection, non-inner join boundaries,
and child/subquery rewriting unchanged.
- Add a focused plan test for preserving a left-join subtree and its
filter beneath an inner join, including the inner join's residual filter
and output schema.
- Fix two existing Clippy warnings in `multi_group_by.rs` to pass the
required local checks.

## What is the testing strategy for this PR?

- All 26 `eliminate_cross_join` tests passed, including
`preserve_outer_join_boundary`.
- Extended workspace tests passed: 12,112 tests passed, 8 ignored, and
all 523 sqllogictest files completed successfully.
- `cargo fmt --all`, `cargo clippy --all-targets --all-features -- -D
warnings`, and `uv run ./dev/rust_lint.sh` passed.
- Compared the existing six-table self-join and no-join SQL planning
workloads against `main` using a temporary Criterion harness. Across
three alternating rounds, physical plans matched and no consistent
end-to-end speedup was observed; six-table planning stayed around 4.9
ms. This is a maintainability refactor without a measured performance
improvement claim.

## Are there any user-facing changes?

No SQL behavior or public API changes.

Co-authored-by: Neil Conway <neil.conway@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules physical-plan Changes to the physical-plan crate v56.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove the redundant join-flattening precheck in EliminateCrossJoin

5 participants