Repository navigation
Conversation
A normal ordering keeps a constant whose value differs between partitions (`AcrossPartitions::Heterogeneous`, since apache#23528), so such a constant can lead a normal ordering. `SortKeyWalk` assumed every ordering's head was at index 0 until the first key was pinned, so it treated the constant as the head and did not see the expression after it. A window ordered by `(total DESC, k)` over an input ordered by `[k, total]`, with `k` constant within each partition, then failed `SanityCheckPlan`. Compute the initial heads past leading fixed expressions, as the walk already does after each pin. Closes apache#26762 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
xudong963
self-requested a review
November 6, 2026 14:06
35 of 57 tasks
Contributor
Author
|
Wil work on #27191 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WARNING: unreviewed AI PR now
Which issue does this PR close?
Details
Rationale for this change
A window ordered by
(total DESC, k)fails to plan with aSanityCheckPlanerror whenkis constant within each partition (for examplelower(g)underWHERE g = 'a'), its input is sorted by[k, total](fromSUM(...) OVER (PARTITION BY k)), andtarget_partitions = 1. The query planned fine in 54.1.0 and fails since 55.0.0.Since #23528, a normalized ordering keeps a constant whose value differs between partitions (
AcrossPartitions::Heterogeneous), so such a constant can lead a normal ordering, askdoes in[k, total].SortKeyWalkassumed that every ordering's head is at index 0 until the first key is pinned, so it treatedkas the head and never sawtotal. The requirement[total DESC, k]was therefore judged unsatisfied by the sanity check, while the window sort removal (which goes throughadd_constants, which drops all constants from the normal orderings) judged it satisfied, and no sort was added.What changes are included in this PR?
SortKeyWalk::newcomputes each ordering's initial head past leading fixed expressions, the same way the walk already moves heads after each pin. When no normal ordering starts with a fixed expression, nothing changes and no allocation happens.Normalization,
output_ordering()and the sort pruning in the physical optimizer are untouched, so the behavior from #23528 and #26455 is preserved. (I also tried dropping per-partition constants from normalized orderings again. That fixes the repro too but makesoutput_ordering()lose the constant, which turns an order-preserving repartition into a blocking sort over an unbounded input inrange_join_key_alignment_ignores_per_partition_constants.)What is the testing strategy for this PR?
leading_per_partition_constant_is_not_a_headinwalk.rs. It fails onmainwith the assertion this fix targets.window.slt.I ran the
datafusion-physical-exprunit tests, thephysical_optimizertests incore_integration, and theorder,union,window*,topk,limit,aggregate*andjoins*sqllogictest files locally.Are there any user-facing changes?
Affected queries plan and run again. No API changes.
This is a regression in 55.0.0 and later, so it is a candidate for a backport to
branch-56.