-
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 #3762, signed integer overflow handle in minus unary scalar function #3780
Merged
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7762b8b
expression: handle int builtinUnaryOpSig overflow
winkyao f87e0af
expression: fix #3762, signed integer overflow handle in minus unary …
winkyao 465dd1b
expression: fix #3762, add builtin_op_test.go, some builtin test cases
winkyao 17f1e5f
*: tiny cleanup
winkyao 1d15330
expression: set the correct unary minus function ScalarFunction.RetType
winkyao a803f9d
expression: rewrite unary minus builtin function to handle overflow.
winkyao d6e6c25
plan: fix popRowArg bug: when get expression.Constatn and getRowLen i…
winkyao ae342fc
*:git stash
winkyao 869e1f6
Merge branch 'master' of https://github.com/pingcap/tidb into winkyao…
winkyao b305a4f
expression: base #3868 pr, and rewrite builtin function unary minus t…
winkyao bedd270
expression: refactor builtin unary minus function
winkyao 0e5de09
expression: tiny refactor
winkyao 4045075
expression: tiny cleanup
winkyao 636170d
expression: cleanup
winkyao 33bf09c
expresion: cleanup
winkyao eb58c48
expression: tiny cleanup
winkyao b199772
Merge branch 'master' of https://github.com/pingcap/tidb into winkyao…
winkyao 6005a18
Merge branch 'master' into winkyao/fix_issue_3762
winkyao e2aa622
expression: add some comment
winkyao d0395bf
Merge branch 'winkyao/fix_issue_3762' of https://github.com/pingcap/t…
winkyao ffc0df7
Merge branch 'master' into winkyao/fix_issue_3762
winkyao 27202d6
Merge branch 'master' of https://github.com/pingcap/tidb into winkyao…
winkyao 03dc0e5
Merge branch 'winkyao/fix_issue_3762' of https://github.com/pingcap/t…
winkyao 7f01b42
expression: adjust commet
winkyao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -352,25 +352,26 @@ type unaryMinusFunctionClass struct { | |
} | ||
|
||
func (b *unaryMinusFunctionClass) handleIntOverflow(arg *Constant) (overflow bool) { | ||
overflow = false | ||
if mysql.HasUnsignedFlag(arg.GetType().Flag) { | ||
uval := arg.Value.GetUint64() | ||
// -math.MinInt64 is 9223372036854775808, so if uval is more than 9223372036854775808, like | ||
// 9223372036854775809, -9223372036854775809 is less than math.MinInt64, overflow occurs. | ||
if uval > uint64(-math.MinInt64) { | ||
overflow = true | ||
return true | ||
} | ||
} else { | ||
val := arg.Value.GetInt64() | ||
// The math.MinInt64 is -9223372036854775808, the math.MaxInt64 is 9223372036854775807, | ||
// which is less than abs(-9223372036854775808). When val == math.MinInt64, overflow occurs. | ||
if val == math.MinInt64 { | ||
overflow = true | ||
return true | ||
} | ||
} | ||
return | ||
return false | ||
} | ||
|
||
// typeInfer infer unary Minus Function return type. when arg is int constant and overflow, | ||
// typerInfer will infer the return type as tpDecimal, not tpInt. | ||
func (b *unaryMinusFunctionClass) typeInfer(argExpr Expression, ctx context.Context) (evalTp, bool) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a comment for what this function does. |
||
tp := tpInt | ||
switch argExpr.GetTypeClass() { | ||
|
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.
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.
s/ infer/ infers
s/ unary Minus/ unaryMinus
s/ Function/ function
s/ when arg/ When the arg
s/ int/ an int