Repository navigation
Conversation
A check of the split needs to build one before the lower half moves down. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three of these queries fail to plan. The split drops a column that gives the output its order, or makes it constant, and an ancestor relies on that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The split compares the output with that of a trial split. If the trial loses a constant, an equality or an ordering, the lower half also passes through the columns that it came from. It checks again after the lower half has moved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…them Otherwise the split reads a sort column, and builds a trial split, for an ordering that nothing needs. A sort replaces the ordering of its input, and `OutputRequirementExec` declares the one that the query needs. An operator that is not known to declare every ordering it relies on keeps the check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| .data() | ||
| // `OutputRequirementExec` declares the ordering that the query needs. Without | ||
| // one at the root, the caller may rely on any ordering of the output. | ||
| let order_matters = !plan.is::<OutputRequirementExec>(); |
There was a problem hiding this comment.
this seems incorrect to me to special case check for OutputRequirementExec -- @jayzhan211 and I just today updated the docs to try and explain what it does better:
datafusion/datafusion/physical-optimizer/src/output_requirements.rs
Lines 35 to 90 in 5184bdd
Basically ordering should matter if the node above this one is relying on the ordering coming out
| /// Any other operator can need one that it does not declare. `PartialSortExec` | ||
| /// does, and `AggregateExec` chooses its mode from the ordering of its input. | ||
| /// Nothing detects the wrong rows that a lost ordering then gives. | ||
| fn relies_only_on_declared_ordering(plan: &Arc<dyn ExecutionPlan>) -> bool { |
There was a problem hiding this comment.
If this is an important property if should be put on ExectionPlan rather than this hard coded list -- otherwise extension nodes can't transmit it
I also don't understand how it differs from required_input_ordering -- all those operators don't need a required_input_ordering execept SortPreservingMergeExec
There was a problem hiding this comment.
Poking around with the 🤖 it seems like maybe the real issue is that PartialSortExec does not declare required_input_ordering or maintains_input_order. even though it relies on its sorted prefix
We could probably add that as a separate PR (and remove the generic check here)
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>
The list of known operators excludes extension nodes. The ordering of a child matters if its parent requires one, or maintains one that matters. The ordering of the root always matters. A query without ORDER BY can thus read a sort column more than before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before OutputRequirementExec is removed, it declares the ordering of the query. After, the round robin repartition loses any global ordering, so an operator above it that needs one declares it. A query without ORDER BY then no longer reads a sort column that nothing needs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Which issue does this PR close?
No issue. This is also preparation for #27867, which is stacked on it.
Rationale for this change
#27152 splits a projection across a round robin repartition to extract leaf expressions such as
s['v']. The split can drop a column that gives the output its ordering, or makes it constant. If an ancestor relies on that, the query fails to plan:All the failures we know need the non-default
enable_leaf_expression_pushdown = false. The pruning in #27867 reaches the same problem with the default settings.What changes are included in this PR?
main.OutputRequirementExecdeclares the one that the query needs.PartialSortExecdoes not, and nothing would detect the wrong rows. The list of known operators inrelies_only_on_declared_orderingdeserves review.Some queries that split today do more planning work, because the check builds a trial split. The benchmarks of the stacked PR include this cost.
Review commit by commit:
main.main.main.AI assistance
Claude Code wrote the code, the tests and this description at the request of the PR author.
What is the testing strategy for this PR?
main, and for two plans that must not change.PartialSortExec. It fails if unknown operators lose the protection.mainplans the query. None newly fails to plan, and 12 that fail onmainnow succeed.Are there any user-facing changes?
No public API changes. Some queries that fail to plan now succeed.
🤖 Generated with Claude Code