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

Confusing behavior in the UPDATE statement #31708

Closed
where2me opened this issue Jan 14, 2022 · 7 comments
Closed

Confusing behavior in the UPDATE statement #31708

where2me opened this issue Jan 14, 2022 · 7 comments
Assignees
Labels
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 5.4.x versions. affects-6.0 affects-6.1 severity/major sig/execution SIG execution type/bug This issue is a bug.

Comments

@where2me
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

DROP TABLE IF EXISTS t0;
CREATE TABLE t0(c0 INT);
INSERT INTO t0 VALUES(0);
UPDATE t0 SET c0 = 1 WHERE 0^('0.5');

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

The column c0 should not be updated, as the result of 0^('0.5') is 0.

3. What did you see instead (Required)

mysql> UPDATE t0 SET c0 = 1 WHERE 0^('0.5');
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

4. What is your TiDB version? (Required)

mysql> SELECT tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version() |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v5.3.0
Edition: Community
Git Commit Hash: 4a1b2e9
Git Branch: heads/refs/tags/v5.3.0
UTC Build Time: 2021-11-24 13:32:39
GoVersion: go1.16.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql>

@where2me where2me added the type/bug This issue is a bug. label Jan 14, 2022
@morgo
Copy link
Contributor

morgo commented Jan 14, 2022

I can't reproduce against master:

tidb> DROP TABLE IF EXISTS t0;
Query OK, 0 rows affected (0.01 sec)

tidb> CREATE TABLE t0(c0 INT);
Query OK, 0 rows affected (0.00 sec)

tidb> INSERT INTO t0 VALUES(0);
Query OK, 1 row affected (0.00 sec)

tidb> UPDATE t0 SET c0 = 1 WHERE 0^('0.5');
ERROR 1292 (22007): Truncated incorrect INTEGER value: '0.5'
tidb> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v5.5.0-alpha-26-ge249588f5-dirty
Edition: Community
Git Commit Hash: e249588f5bca9424aaa6b37a1f2c523cf97eb9d0
Git Branch: experimental-instance-vars
UTC Build Time: 2022-01-14 17:33:34
GoVersion: go1.16.9
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

It looks like this might be a duplicate of a bug that has been fixed.

@morgo
Copy link
Contributor

morgo commented Jan 14, 2022

I was mistaken, it can be reproduced against master. However, this can only be reproduced when using TiKV. against unistore there is an error and the UPDATE statement will not run.

@morgo
Copy link
Contributor

morgo commented Jan 14, 2022

Confirming that this expression is executed in the coprocessor:

tidb> explain UPDATE t0 SET c0 = 1 WHERE 0^('0.3');
+---------------------------+----------+-----------+---------------+------------------------------------------+
| id                        | estRows  | task      | access object | operator info                            |
+---------------------------+----------+-----------+---------------+------------------------------------------+
| Update_4                  | N/A      | root      |               | N/A                                      |
| └─TableReader_8           | 8000.00  | root      |               | data:Selection_7                         |
|   └─Selection_7           | 8000.00  | cop[tikv] |               | bitxor(0, cast("0.3", bigint(3) BINARY)) |
|     └─TableFullScan_6     | 10000.00 | cop[tikv] | table:t0      | keep order:false, stats:pseudo           |
+---------------------------+----------+-----------+---------------+------------------------------------------+
4 rows in set (0.00 sec)

tidb> explain UPDATE t0 SET c0 = 1 WHERE 0^('0.5');
+---------------------------+----------+-----------+---------------+------------------------------------------+
| id                        | estRows  | task      | access object | operator info                            |
+---------------------------+----------+-----------+---------------+------------------------------------------+
| Update_4                  | N/A      | root      |               | N/A                                      |
| └─TableReader_8           | 8000.00  | root      |               | data:Selection_7                         |
|   └─Selection_7           | 8000.00  | cop[tikv] |               | bitxor(0, cast("0.5", bigint(3) BINARY)) |
|     └─TableFullScan_6     | 10000.00 | cop[tikv] | table:t0      | keep order:false, stats:pseudo           |
+---------------------------+----------+-----------+---------------+------------------------------------------+
4 rows in set (0.00 sec)

There are technically 2 bugs:

  1. In MySQL, a cast of a floating point string would truncate the fractional part. i.e. SELECT cast("0.5" as unsigned) == 0.
  2. MySQL refuses to cast a string representation of an integer that has a fractional part in the default SQL mode:
mysql [localhost:8027] {msandbox} (test) > insert into t2 VALUES (cast("1.0" as unsigned));
ERROR 1292 (22007): Truncated incorrect INTEGER value: '1.0'
mysql [localhost:8027] {msandbox} (test) > insert into t2 VALUES (cast("1" as unsigned));
Query OK, 1 row affected (0.00 sec)

For (2) tidb gets this right with unistore, but not with tikv.

@jebter jebter added severity/major sig/execution SIG execution 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. labels Jan 15, 2022
@sayJason
Copy link

sayJason commented Mar 2, 2022

I try the same where clause in the DELETE statement as follows:

DROP TABLE IF EXISTS t0; 
CREATE TABLE t0 (c0 INT); 
INSERT INTO t0 VALUES (1);
DELETE FROM t0 WHERE 0^('0.5');

The DELETE statement also succeeded. I want to know whether the same reason as UPDATE cause this problem. Thanks!

@zanmato1984
Copy link
Contributor

They are 90% for the same reason.

@guo-shaoge
Copy link
Collaborator

Will fix in tikv/tikv#13045

@guo-shaoge guo-shaoge added the affects-5.4 This bug affects 5.4.x versions. label Jul 18, 2022
@guo-shaoge
Copy link
Collaborator

tikv/tikv#13046 merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 5.4.x versions. affects-6.0 affects-6.1 severity/major sig/execution SIG execution type/bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

8 participants