-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: fix a bug for 'int column <cmp> non-int constant' #11050
Conversation
/run-all-tests |
Codecov Report
@@ Coverage Diff @@
## master #11050 +/- ##
==========================================
Coverage ? 81.259%
==========================================
Files ? 423
Lines ? 90006
Branches ? 0
==========================================
Hits ? 73138
Misses ? 11569
Partials ? 5299 |
/run-all-tests |
expression/builtin_compare.go
Outdated
dt, err := con.Eval(chunk.Row{}) | ||
if err != nil { | ||
return con, false | ||
return con, nil, false | ||
} | ||
sc := ctx.GetSessionVars().StmtCtx | ||
intFieldType := types.NewFieldType(mysql.TypeLonglong) |
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.
We can define this intFieldType as an input parameter. It should be the FiledType of the int column.
tidb> create table t (a int);
Query OK, 0 rows affected (0.01 sec)
tidb> desc select * from t where a > 128; -- It should be TableDual for the sql as well.
+---------------------+----------+------+------------------------------------------------------------+
| id | count | task | operator info |
+---------------------+----------+------+------------------------------------------------------------+
| TableReader_7 | 3333.33 | root | data:Selection_6 |
| └─Selection_6 | 3333.33 | cop | gt(test.t.a, 128) |
| └─TableScan_5 | 10000.00 | cop | table:t, range:[-inf,+inf], keep order:false, stats:pseudo |
+---------------------+----------+------+------------------------------------------------------------+
3 rows in set (0.00 sec)
tidb> desc select * from t where a > 11111111111111111111111111111;
+-------------+-------+------+---------------+
| id | count | task | operator info |
+-------------+-------+------+---------------+
| TableDual_6 | 0.00 | root | rows:0 |
+-------------+-------+------+---------------+
1 row in set (0.00 sec)
Could you please describe more details about the root reason causing this bug. |
8dbc56e
to
2cbdea7
Compare
/run-all-tests |
1 similar comment
/run-all-tests |
846eb97
to
385f5c8
Compare
/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
/run-all-tests |
/run-unit-test |
/rebuild |
What problem does this PR solve?
#10675
Wrong result for
int column <cmp> non-int constant
when the constant isinf
or-inf
Before this pr:
This pr:
What is changed and how it works?
When the compare expression is
int column <cmp> non-int constant
ornon-int constant <cmp> int column
, TiDB will refine the constant to the int column type.E.g.,
a < 1.1
will be rewritten toa < 2
.Before this pr, the logic of refine function is wrong. It is only judged whether the constant is Overflow.
a < -184467440737095516167.1
will be rewritten toa < inf
a > 184467440737095516167.1
will be rewritten toa > -inf
This pr, I use the leading sing and Overflow flag to decide the constant is 'inf' or '-inf'
a < -184467440737095516167.1
will be rewritten toa < -inf
a > 184467440737095516167.1
will be rewritten toa > inf
Check List
Tests
Code changes
Side effects
Related changes