pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.19k stars 5.84k forks source link

A misleading warning from the SELECT statement #33226

Open sayJason opened 2 years ago

sayJason commented 2 years ago

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 FLOAT);
INSERT INTO t0 VALUES (0);
SELECT c0 FROM t0 WHERE '' < (t0.c0 REGEXP t0.c0);
SHOW WARNINGS;
UPDATE t0 SET c0 = 1 WHERE '' < (t0.c0 REGEXP t0.c0);
SHOW WARNINGS;

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

There should be no warning in the SELECT statement. Otherwise, it should be an error in the UPDATE statement since I run the above statements in strict SQL mode.

3. What did you see instead (Required)

SELECT throws a warning like following. UPDATE succeeds without error.

+---------+------+--------------------------------------+
| Level   | Code | Message                              |
+---------+------+--------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '' |
| Warning | 1292 | Truncated incorrect DOUBLE value: '' |
+---------+------+--------------------------------------+
2 rows in set (0.00 sec)

4. What is your TiDB version? (Required)

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()

                                                                       |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v5.4.0
Edition: Community
Git Commit Hash: 55f3b24c1c9f506bd652ef1d162283541e428872
Git Branch: heads/refs/tags/v5.4.0
UTC Build Time: 2022-01-25 08:39:26
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)
aytrack commented 2 years ago

for mysql 8.0.26, the update was execute success

mysql> SELECT c0 FROM t0 WHERE '' < (t0.c0 REGEXP t0.c0);SELECT c0 FROM t0 WHERE '' < (t0.c0 REGEXP t0.c0);
+------+
| c0   |
+------+
|    0 |
+------+
1 row in set (0.04 sec)

mysql> UPDATE t0 SET c0 = 1 WHERE '' < (t0.c0 REGEXP t0.c0);
Query OK, 1 row affected (0.04 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.26    |
+-----------+
1 row in set (0.05 sec)

mysql> select @@sql_mode;
+-----------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                            |
+-----------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------------------------------------------+
1 row in set (0.04 sec)