fix: consider nulls_first when propagating ordered SortProperties - #24206
Open
Nagato-Yuzuru wants to merge 3 commits into
Open
fix: consider nulls_first when propagating ordered SortProperties#24206Nagato-Yuzuru wants to merge 3 commits into
Nagato-Yuzuru wants to merge 3 commits into
Conversation
Nagato-Yuzuru
marked this pull request as ready for review
August 9, 2026 18:19
Contributor
Author
|
The old query plan can lead to this sort error In datafusion-cli Get Order C was silently violated |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #24206 +/- ##
========================================
Coverage 81.05% 81.05%
========================================
Files 1106 1106
Lines 382287 382097 -190
Branches 382287 382097 -190
========================================
- Hits 309851 309723 -128
+ Misses 54121 54090 -31
+ Partials 18315 18284 -31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jayzhan211
reviewed
Aug 10, 2026
| OPTIONS ('format.has_header' 'true'); | ||
|
|
||
| query TT | ||
| EXPLAIN SELECT CAST((inc_col>desc_col) as integer) as c from annotated_data_finite_nulls_last order by c; |
Contributor
There was a problem hiding this comment.
Do we have sqltest like the example in the description covered, like null + numeric -> null, then we expect to see the null first -> unordered
jayzhan211
approved these changes
Aug 10, 2026
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.
Which issue does this PR close?
SortPropertiesshould considernulls_first#11596.Rationale for this change
In the original implementation, cases where
null_firstis not same were not correctly handled and were still treated asordered.Example:
asortedASC NULLS FIRST,bsortedASC NULLS LAST:Since
a + bisNULLwherever either input is, the result has nulls at both ends. The previous code returnedOrdered(ASC, nulls_first: true)for this case; it now returnsUnordered.What changes are included in this PR?
Unit Tests were added and issues were fixed. Additional processing was performed on
and_or(see #11596 (comment) )SortProperties::{add, sub, gt_or_gteq, and_or} now propagate an Ordered result only when both operands agree on nulls_first; otherwise they return Unordered.
This is conservative. If one input were known to be non-null the old result could be valid. But SortProperties carries no nullability information, so Unordered is the only sound answer at this layer.
Are these changes tested?
Yes.
Are there any user-facing changes?
No.