Repository navigation
Preserve required sorts above custom execution plans - #26118
Draft
geoffreyclaude wants to merge 2 commits into
Draft
geoffreyclaude wants to merge 2 commits into
geoffreyclaude wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #26118 +/- ##
==========================================
+ Coverage 82.73% 82.74% +0.01%
==========================================
Files 1147 1148 +1
Lines 449213 449974 +761
Branches 449213 449974 +761
==========================================
+ Hits 371634 372320 +686
- Misses 54929 54968 +39
- Partials 22650 22686 +36 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
geoffreyclaude
marked this pull request as draft
October 7, 2026 20:47
Check SQL-visible ordering in sort_pushdown.slt with a test-only custom projection table function. Retain four synchronous unit tests for the fallback ordering requirements and rejection decisions.
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?
Related to #23276. This fixes unsafe pushdown through the existing custom-plan fallback.
Rationale for this change
Sort pushdown through a custom execution plan can remove a necessary sort when the operator changes column positions or values, causing plan validation failures or incorrectly ordered results.
ExecutionPlan::maintains_input_order()means that the operator preserves the sequence of rows. It does not guarantee that transformed output values retain the same sort-key ordering. A projection can legitimately returntruewhile changing values: replacingawith-akeeps the rows in the same sequence, but turns[1, 2, 3]into[-1, -2, -3]. Sorting the input bya ASCtherefore does not satisfyORDER BY a ASCon the output.The plan's
output_ordering()andequivalence_properties()describe which output expressions are sorted, and in which direction. These properties must be checked after rebuilding the operator over the proposed child sorts. The generic fallback previously trusted row-sequence preservation and positional column mapping without checking that the resulting output would satisfy the requested ordering.What changes are included in this PR?
Rebuild the custom operator with candidate child orderings and check that its output properties satisfy the requested ordering before accepting pushdown. Invalid candidate expressions leave the outer sort in place. Transparent and renamed projections retain the optimization.
What is the testing strategy for this PR?
Six sqllogictest cases in
sort_pushdown.sltcheck ordered results for identity, renamed and reordered columns, generated and negated values, and Boolean sort expressions through a custom execution plan. A short EXPLAIN verifies that renaming still allows the sort below the custom operator. The test-onlycustom_projectiontable function uses the normal optimizer rules withSanityCheckPlanenabled.Four synchronous unit tests in
sort_pushdown.rscall the custom-plan fallback directly to check remapped requirements and rejection of reordered columns, changed values with the same schema, and incompatible child expressions.Validation: the full
./dev/rust_lint.shsuite, Clippy with all targets and features, all 528 sqllogictest files, and extended workspace validation passed. One core fuzz test initially hit the process's open-file limit and passed on retry with a higher limit. Removing the fix makes the reordered-column, generated-value and negated-value SQL cases fail.Are there any user-facing changes?
Queries sorting custom-operator output retain the necessary sort when the requested ordering cannot be proved.