-
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
*: fix the lower bound when converting numbers less than 0 to unsigned integers #8544
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
Currently
But it doesn't show which line caused the error. I tried to pick them out but still missed some. So is there any way to locate the line? |
@exialin You can find out which case failed in the output of |
PTAL @XuHuaiyu |
The order of explain result of the |
We're checking it. |
After more tests, I found there are two special cases hard to resolve:
For example: tidb> create table t(a bigint unsigned);
Query OK, 0 rows affected (0.03 sec)
tidb> insert into t value (18446744073709551616);
Query OK, 1 row affected (0.00 sec)
tidb> select * from t;
+---------------------+
| a |
+---------------------+
| 9223372036854775808 |
+---------------------+
1 row in set (0.00 sec)
tidb> insert into t value (18446744073709554616);
ERROR 1264 (22003): Out of range value for column 'a' at row 1 Here
For example: tidb> set sql_mode='';
Query OK, 0 rows affected (0.01 sec)
tidb> insert into t value (-9223372036854775809);
ERROR 1264 (22003): Out of range value for column 'a' at row 1
tidb> insert into t value (-18446744073709551615);
ERROR 1264 (22003): Out of range value for column 'a' at row 1 To be compatible with MySQL, here values in tidb/executor/insert_common.go Lines 247 to 254 in 808eab1
Other integer literals are evaluated correctly in I tried to do some workaround like making @zz-jason Do you have any suggestion for these two cases? |
@exialin Can not find out any easy way to fix them either. Could you file a github issue to record these two cases so that one day we may be able to fix it? |
@zz-jason OK. Maybe after changes in this PR are merged? The two cases are somewhat related with this PR. |
Codecov Report
@@ Coverage Diff @@
## master #8544 +/- ##
==========================================
- Coverage 67.59% 67.57% -0.03%
==========================================
Files 363 363
Lines 75317 75326 +9
==========================================
- Hits 50913 50901 -12
- Misses 19918 19932 +14
- Partials 4486 4493 +7
Continue to review full report at Codecov.
|
OK |
/run-all-tests |
The following sql failed, it seems to be unexpected. CREATE TABLE `table1_int_autoinc` (
`col_int_unsigned_not_null_unique` int(10) unsigned NOT NULL,
UNIQUE KEY `col_int_unsigned_not_null_unique` (`col_int_unsigned_not_null_unique`)
) ;
DELETE FROM `table1_int_autoinc` WHERE `col_int_unsigned_not_null_unique` = -1438187520 ; |
/run-all-tests |
/run-all-tests |
@XuHuaiyu CI test fails when executing |
sessionctx/stmtctx/stmtctx.go
Outdated
|
||
// ShouldIgnoreError indicates whether we should ignore the error when type conversion overflows, | ||
// so we can leave it for further processing like clipping values less than 0 to 0 for unsigned integer types. | ||
func (sc *StatementContext) ShouldIgnoreError() bool { |
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.
It is better to clarify what kind of error in the function name.
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.
Modified as you suggested.
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 |
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
It will be better to fix #8623 in an individual PR. |
@exialin Could you cherry-pick this commit to release-2.1 and release-2.0 branch? |
@zz-jason OK, I'll do it later and file a issue about the unresolved cases. Thanks for the review from all of you! |
What problem does this PR solve?
Fix issue #6360 so that when
set sql_mode = ''
, values less than 0 will be clipped to 0 for unsigned integer types. Besides, some other cases are also fixed.MySQL:
Previously in TiDB:
See issue #8623. If the problem described in that issue is fixed, the wrong behaviour can be fixed by rountines of this pull request (test cases should be added later).
Data file:
MySQL:
Previously in TiDB:
After this fix:
Question: is the third row of MySQL reasonable?
TiDB doesn't support the following
alter table
query currently. Just post for completeness.MySQL:
What is changed and how it works?
MySQL doc says:
So this makes the result different from other conversions like
CAST()
function. When the number to be inserted is less than 0, it should be clipped to 0.TODO: the warning message has not been fixed yet. It would be better to fix them in other pull requests.
Check List
Tests
Code changes
Side effects
This change is