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

TiDB produces different results for SELECT statements (BIGINT value is out of range in '(8 - 100)') #34222

Open
JZuming opened this issue Apr 25, 2022 · 3 comments
Labels
affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 severity/minor sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@JZuming
Copy link

JZuming commented Apr 25, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Setup the environment:

tiup playground --db.binpath /path/to/latest/tidb-server &
mysql -h "127.0.0.1" -u root -P 4000 -D testdb < mysql_bk.sql

mysql_bk.sql:
mysql_bk.txt

Testcase 1

mysql -h "127.0.0.1" -u root -P 4000 -D testdb

mysql> delete from t_xa9msd;
mysql> select * from t_xa9msd as ref_0
        where (63 & 72) - case when ref_0.wkey is NULL then 66 else 100 end > 88;

Testcase 2

mysql -h "127.0.0.1" -u root -P 4000 -D testdb

mysql> start transaction;
mysql> delete from t_xa9msd;
mysql> select * from t_xa9msd as ref_0
        where (63 & 72) - case when ref_0.wkey is NULL then 66 else 100 end > 88;
mysql> commit;

2. What did you expect to see? (Required)

The execution result of SELECT statements in Testcase 1 and Testcase 2 are same.

3. What did you see instead (Required)

Output of SELECT statement in Testcase 1

Empty set (0.00 sec)

Output of SELECT statement in Testcase 2

ERROR 1690 (22003): BIGINT value is out of range in '(8 - 100)'

Their results are different.

4. What is your TiDB version? (Required)

Release Version: v6.1.0-alpha-173-g32b9c1477
Edition: Community
Git Commit Hash: 32b9c14779c2a7dd73003667d81bb42f67a33385
Git Branch: master
UTC Build Time: 2022-04-11 17:53:15
GoVersion: go1.18
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@JZuming JZuming added the type/bug The issue is confirmed as a bug. label Apr 25, 2022
@JZuming
Copy link
Author

JZuming commented Apr 25, 2022

Another test cases correctly return the result (only change 63 & 72 to 8):

Testcase 1

mysql> delete from t_xa9msd;
mysql> select * from t_xa9msd as ref_0
        where (8) - case when ref_0.wkey is NULL then 66 else 100 end > 88;

Testcase 2

mysql> start transaction;
mysql> delete from t_xa9msd;
mysql> select * from t_xa9msd as ref_0
        where (8) - case when ref_0.wkey is NULL then 66 else 100 end > 88;
mysql> commit;

Both of them return this result:

Empty set (0.00 sec)

@ChenPeng2013 ChenPeng2013 added sig/execution SIG execution severity/major affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 labels Apr 26, 2022
@gengliqi
Copy link
Contributor

gengliqi commented May 13, 2022

There are three issues in my opinion.

First, the overflow error is caused by (63 & 72) is a unsigned integer and (63 & 72) - 66/100 is less than 0.
And 8 is a signed integer, so in your latter case, there is no error.

Second, the different error output between non-transaction and transaction is a little confusing. In transaction mode, the execution is pushed down to TiKV and the table is not deleted(the deleted rows are just cached in TiDB memory). So the error occurs.
In my opinion, this inconsistent behavior is acceptable because it doesn't make any sense to query a table after it is deleted and even this query may have an overflow error.

Third, the error log should be BIGINT UNSIGNED value is out of range. It's a small bug in TiKV.

As a result, I think the severity should be minor.

@gengliqi
Copy link
Contributor

/remove-severity major
/severity minor

@JZuming JZuming changed the title TiDB (with tikv) produces different results for SELECT statements when using transaction TiDB produces different results for SELECT statements (BIGINT value is out of range in '(8 - 100)') Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.0 severity/minor sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

4 participants