Skip to content

fix: declare the input ordering that PartialSortExec requires - #27937

Draft
adriangb wants to merge 1 commit into
apache:mainfrom
adriangb:adriangb/partial-sort-required-ordering
Draft

adriangb wants to merge 1 commit into
apache:mainfrom
adriangb:adriangb/partial-sort-required-ordering

Conversation

@adriangb

@adriangb adriangb commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

No issue. alamb suggested it in a review of #27925 (comment).

Rationale for this change

PartialSortExec sorts each run of rows with equal values of its common prefix. It returns wrong rows if its input is not sorted by that prefix. It does not declare this in required_input_ordering, so optimizer rules and SanityCheckPlan cannot see the requirement. A rule that changes the input ordering then gives wrong results that nothing detects.

#27925 needs the declaration. It decides which orderings it must keep from required_input_ordering and maintains_input_order.

What changes are included in this PR?

PartialSortExec::required_input_ordering returns the first common_prefix_length sort expressions.

What is the testing strategy for this PR?

A unit test checks the declared requirement. The existing PartialSortExec plans in the sqllogictests and in the enforce_sorting tests are unchanged, because EnsureRequirements creates the operator only when the input already satisfies the prefix.

AI assistance

Claude Code wrote the code, the test and this description at the request of the PR author.

Are there any user-facing changes?

No public API changes.

🤖 Generated with Claude Code

The operator sorts each run of equal prefix values, so it returns wrong rows if
its input is not sorted by the prefix. Without the declaration, the optimizer
rules and SanityCheckPlan cannot see that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Dec 2, 2026

@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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants