Skip to content
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

executor: refineArgs() bug fix when compare int with very small decimal #23694

Merged
merged 3 commits into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions expression/builtin_compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,10 @@ func (c *compareFunctionClass) refineArgs(ctx sessionctx.Context, args []Express
isExceptional, finalArg0, finalArg1 := false, args[0], args[1]
isPositiveInfinite, isNegativeInfinite := false, false
// int non-constant [cmp] non-int constant
if arg0IsInt && !arg0IsCon && !arg1IsInt && arg1IsCon {
// Why check not null flag
// eg: int_col > const_val(which is less than min_int32)
// If int_col got null, compare result cannot be true
if arg0IsInt && !arg0IsCon && !arg1IsInt && arg1IsCon && mysql.HasNotNullFlag(arg0Type.Flag) {
arg1, isExceptional = RefineComparedConstant(ctx, *arg0Type, arg1, c.op)
finalArg1 = arg1
if isExceptional && arg1.GetType().EvalType() == types.ETInt {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If arg1 == false, can we ignore the not-null flag ?

Copy link
Collaborator Author

@guo-shaoge guo-shaoge Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

select xxx where (col_int > (select sum(xx) xx) ) is null;

So need to distinguish null or false of GT expr.

Expand All @@ -1370,7 +1373,7 @@ func (c *compareFunctionClass) refineArgs(ctx sessionctx.Context, args []Express
}
}
// non-int constant [cmp] int non-constant
if arg1IsInt && !arg1IsCon && !arg0IsInt && arg0IsCon {
if arg1IsInt && !arg1IsCon && !arg0IsInt && arg0IsCon && mysql.HasNotNullFlag(arg1Type.Flag) {
arg0, isExceptional = RefineComparedConstant(ctx, *arg1Type, arg0, symmetricOp[c.op])
finalArg0 = arg0
if isExceptional && arg0.GetType().EvalType() == types.ETInt {
Expand Down
9 changes: 9 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8946,3 +8946,12 @@ func (s *testIntegrationSerialSuite) TestCollationForBinaryLiteral(c *C) {
tk.MustQuery("select * from t where col1 not in (0x1B,0x20) order by col1").Check(testkit.Rows("\x1e \xec 6966939640596047133"))
tk.MustExec("drop table t")
}

func (s *testIntegrationSuite) TestIssue23623(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1;")
tk.MustExec("create table t1(c1 int);")
tk.MustExec("insert into t1 values(-2147483648), (-2147483648), (null);")
tk.MustQuery("select count(*) from t1 where c1 > (select sum(c1) from t1);").Check(testkit.Rows("2"))
}