tidb-challenge-program / bug-hunting-issue

Bug hunting issues.
3 stars 0 forks source link

P0-[4.0 bug hunting]-[SQL Plan Management]-Value in generated column depends on a WHERE clause #62

Open mrigger opened 4 years ago

mrigger commented 4 years ago

Consider the following statements:

CREATE TABLE t0(c0 INT AS (c1) UNIQUE, c1 TEXT);
INSERT INTO t0(c1) VALUES (0.5);
SELECT t0.c0 FROM t0 WHERE t0.c1 + 0.5; -- expected: {1}, actual: {0} 

Unexpectedly, the SELECT fetches an attribute value of 0, rather than 1. When removing the WHERE clause, the query works as expected:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25-TiDB- TiDB Server (Apache License 2.0), MySQL 5.7 compatible

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE TABLE t0(c0 INT AS (c1) UNIQUE, c1 TEXT);
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t0(c1) VALUES (0.5);
Query OK, 1 row affected (0.00 sec)

mysql> SELECT t0.c0 FROM t0 WHERE t0.c1 + 0.5; -- expected: {1}, actual: {0} 
+------+
| c0   |
+------+
|    0 |
+------+
1 row in set, 1 warning (0.00 sec)

mysql> SELECT t0.c0 FROM t0;
+------+
| c0   |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

I found this based on the latest master commit 187f225002b67daa47992816f6ef5ddb76b0f68a, and also checked that this reproduces on the 4.0 RC. On the latest master commit, the addition + 0.5 is not necessary to reproduce this.

shuke987 commented 4 years ago

/bug P1