[BugFix] Never raise a strict cast overflow error from a null row's data (backport #74903)#74957
Merged
Merged
Conversation
Contributor
Author
|
Cherry-pick of 5847dd7 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
23 tasks
Contributor
Author
|
@mergify[bot]: Backport conflict, please reslove the conflict and resubmit the pr |
60416ea to
c7dcaee
Compare
…ata (#74903) Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: wanpengfei-git <wanpengfei91@163.com>
5f687db to
1e032da
Compare
trueeyu
approved these changes
Jun 17, 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.
Why I'm doing:
A strict-mode numeric narrowing cast (the
AllowThrowExceptionpath ofUNARY_FN_CAST_VALID,e.g.
cast(x AS INT)when an overflow must error instead of becoming NULL) evaluated the overflowcheck on every row of the input, including null rows. The data stored in a null row's slot
is undefined: when a producer leaves garbage there, the check sees an out-of-range value and throws
a spurious exception, failing a query that should succeed — the row is NULL and its value is
irrelevant.
What I'm doing:
NullAwareInputCheckUnaryFunction(be/src/exprs/unary_function.h). For a nullable input itconverts all rows but only treats a non-null row's overflow as an error; a null row's data
can never be the cause of an exception. The hot loop stays branchless and vectorizable (convert
every row, detect overflow with the non-throwing check AND-ed with the not-null mask and
OR-accumulated); the throwing check runs only on a cold path entered when a genuine non-null row
overflows.
AllowThrowException) branch ofUNARY_FN_CAST_VALIDto use it, passing thenon-throwing
NumberCheckfor hot-loop detection andNumberCheckWithThrowExceptionfor the colderror path.
Bonus: the new implementation is ~1.4-1.6x faster than the old one across nullable/non-nullable
shapes — it avoids materializing and scanning a separate null-mask column and keeps the loop
vectorizable (no per-row branch, no throw in the hot path). Benchmark numbers are in the bench file.
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check:
This is an automatic backport of pull request #74903 done by [Mergify](https://mergify.com).