pingcap/tidb

Incorrect data conversion

sayJason opened this issue · 2 comments

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE t1 (c1 INT UNSIGNED NOT NULL);
INSERT INTO t1 VALUES (0);
SELECT c1 > - '7' FROM t1;

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

SELECT returns 1

3. What did you see instead (Required)

SELECT returns 0

4. What is your TiDB version? (Required)

Release Version: v7.0.0
Edition: Community
Git Commit Hash: 7376954
Git Branch: heads/refs/tags/v7.0.0
UTC Build Time: 2023-03-29 13:32:13
GoVersion: go1.20.2
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv

The root cause may be that -'7' is erroneously converted into 0.

mysql> EXPLAIN SELECT c1 > - '7' FROM t1;
+-------------------------+---------+-----------+---------------+--------------------------------+
| id                      | estRows | task      | access object | operator info                  |
+-------------------------+---------+-----------+---------------+--------------------------------+
| Projection_3            | 1.00    | root      |               | 0->Column#3                    |
| └─TableReader_5         | 1.00    | root      |               | data:TableFullScan_4           |
|   └─TableFullScan_4     | 1.00    | cop[tikv] | table:t1      | keep order:false, stats:pseudo |
+-------------------------+---------+-----------+---------------+--------------------------------+
3 rows in set (0.00 sec)

in mysql8:

mysql> SELECT c1 > - '7' FROM t1;
+------------+
| c1 > - '7' |
+------------+
|          1 |
+------------+
1 row in set (0.00 sec)