fix: restrict reverse cast constraint propagation to safe conversions - #25531
Merged
jayzhan211 merged 1 commit intoSep 20, 2026
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #25531 +/- ##
========================================
Coverage 82.38% 82.38%
========================================
Files 1138 1138
Lines 434328 434582 +254
Branches 434328 434582 +254
========================================
+ Hits 357824 358040 +216
- Misses 54872 54882 +10
- Partials 21632 21660 +28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jayzhan211
approved these changes
Sep 20, 2026
jayzhan211
left a comment
Contributor
There was a problem hiding this comment.
Thanks @haohuaijin , LGTM!
Contributor
Author
|
Thanks for your reviews @jayzhan211 |
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?
Closes #25523.
Related to #25407.
Rationale for this change
A filter on a cast can incorrectly make its input appear constant and remove a required sort. For example,
CAST(x AS INT) = 0matches both -0.5 and 0.5, but casting the singleton result interval back to DOUBLE yields [0.0, 0.0]. The optimizer can then return the wrong order forORDER BY x DESC.What changes are included in this PR?
Gate reverse Cast constraint propagation through a common allowlist for all types. Preserve propagation for conversions recognized by
check_bigger_cast, integer-to-integer casts, and Float32-to-Float64 casts. For other conversions, keep the existing input range instead of treating a cast back as an inverse.The conservative allowlist may reduce range refinement and pruning for safe conversions that are not yet recognized. Runtime CAST behavior and forward interval evaluation are unchanged.
What is the testing strategy for this PR?
cast.sltwith float-to-integer, integer-to-Float32, timestamp-to-date, and string-to-integer cases. The first three reproduce incorrect sort elimination before the corresponding guards; the string case checks compatibility.Are there any user-facing changes?
Queries retain required sorting when cast constraints cannot safely determine the input range. No public API changes.