Skip to content

fix: preserve range partitioning through joins#23584

Open
EdsonPetry wants to merge 1 commit into
apache:mainfrom
EdsonPetry:edson.petry/perverse-range-partitioning-output-partitions-on-joins
Open

fix: preserve range partitioning through joins#23584
EdsonPetry wants to merge 1 commit into
apache:mainfrom
EdsonPetry:edson.petry/perverse-range-partitioning-output-partitions-on-joins

Conversation

@EdsonPetry

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

#23184 allowed compatible range-partitioned inputs to satisfy partitioned inner joins without hash repartitioning. However, join output still downgraded Partitioning::Range to UnknownPartitioning, so downstream joins and aggregates could not reuse the preserved range layout and inserted avoidable hash repartitions.

What changes are included in this PR?

  • Preserve Partitioning::Range in adjust_right_output_partitioning.
  • Shift right-side range-ordering column indexes into the joined schema while retaining split points and sort options.
  • Add unit coverage for compound range keys and non-default sort options.
  • Update SQL logic test plans for nested range joins and a range join feeding an aggregate.

Are these changes tested?

Yes.

  • ./dev/rust_lint.sh
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo test -p datafusion-physical-plan test_adjust_right_output_partitioning_preserves_range
  • cargo test --profile=ci --test sqllogictests -- range_partitioning.slt
  • ulimit -n 10240 && RUST_BACKTRACE=1 cargo test --profile ci --exclude datafusion-examples --exclude datafusion-benchmarks --exclude datafusion-cli --workspace --lib --tests --bins --features avro,json,backtrace,extended_tests,recursive_protection,parquet_encryption

Are there any user-facing changes?

Yes. Physical plans can preserve proven range partitioning through joins, allowing compatible downstream joins and aggregates to avoid unnecessary hash repartitioning. There are no public API changes.

@github-actions github-actions Bot added sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Jul 14, 2026
@EdsonPetry EdsonPetry marked this pull request as ready for review July 14, 2026 20:00
@EdsonPetry

Copy link
Copy Markdown
Contributor Author

@gene-bordegaray

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

could we add one test for sort merge joins too, maybe do this one in slt with going into another join

other than that looks good 👍

eit we will have to wait for #23480 to land for that test but think it is worth it for coverage

@gene-bordegaray

Copy link
Copy Markdown
Contributor

cc: @gabotechs

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

Nice, thanks @EdsonPetry and @gene-bordegaray

Comment on lines +154 to +156
let ordering = LexOrdering::new(ordering)
.expect("offsetting a range ordering keeps it non-empty");
Partitioning::Range(RangePartitioning::new(

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.

Rather than panicking, can we through a controlled internal error here?

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.

Makes sense, thanks!

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

Labels

physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve Partitioning::Range output partitioning through joins

3 participants