-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
expression: fix the corner case of CAST int as unsigned real/decimal #13637
Conversation
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
Signed-off-by: H-ZeX <hzx20112012@gmail.com>
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #13637 +/- ##
================================================
- Coverage 80.3222% 80.0678% -0.2545%
================================================
Files 474 473 -1
Lines 117605 116465 -1140
================================================
- Hits 94463 93251 -1212
- Misses 15759 15854 +95
+ Partials 7383 7360 -23 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@qw4990 PTAL |
@djshow832, @SunRunAway, @qw4990, PTAL. |
e9a7680
to
ed64f0c
Compare
/run-all-tests |
/run-all-tests |
@@ -461,9 +461,10 @@ func (b *builtinCastIntAsRealSig) evalReal(row chunk.Row) (res float64, isNull b | |||
if isNull || err != nil { | |||
return res, isNull, err | |||
} | |||
if !mysql.HasUnsignedFlag(b.tp.Flag) && !mysql.HasUnsignedFlag(b.args[0].GetType().Flag) { | |||
if unsignedArgs0 := mysql.HasUnsignedFlag(b.args[0].GetType().Flag); !mysql.HasUnsignedFlag(b.tp.Flag) && !unsignedArgs0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about:
} else if b.inUnion && !unsignedArgs0 && val < 0 {
// Round up to 0 if the value is negative but the expression eval type is unsigned in `UNION` statement
// NOTE: the following expressions are equal (so choose the more efficient one):
// `b.inUnion && mysql.HasUnsignedFlag(b.tp.Flag) && !unsignedArgs0 && val < 0`
// `b.inUnion && !unsignedArgs0 && val < 0`
res = 0
} else {
builtinCastIntAsRealSig
and builtinCastIntAsDecimalSig
that treat unsigned val as signed val
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/merge |
cherry pick to release-2.1 failed |
cherry pick to release-3.0 failed |
What problem does this PR solve?
In the original version, it will check inUnion && val<0 no matter whether the val is unsigned(the val is always int64, but in sql, it may be unsigned), so in some case, it will dirrerent from mysql5.7
This PR continue unfinished work in #11745.
What is changed and how it works?
add check of whether unsigned
Check List
Tests
Code changes
Side effects
Related changes
Release note