tidb-challenge-program / bug-hunting-issue

Bug hunting issues.
3 stars 0 forks source link

P0-[4.0 bug hunting]-[SQL Plan Management]-UNIQUE constraint on DECIMAL/floating-point columns causes incorrect result for NULL in AND #48

Open mrigger opened 4 years ago

mrigger commented 4 years ago

Consider the following statements:

CREATE TABLE t0(c0 DOUBLE UNIQUE);
INSERT INTO t0(c0) VALUES (NULL);
SELECT t0.c0 FROM t0 WHERE NOT (t0.c0 AND 1); -- expected: {}, actual: {NULL}

Unexpectedly, the SELECT fetches a row:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
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 DOUBLE UNIQUE);
Query OK, 0 rows affected (0.00 sec)

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

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

I found this based on the latest master commit b6fcc157442894f048c1cc65cfcc7776e9ed1a72, and can also reproduce it on the 4.0 RC. Interestingly, when removing the UNIQUE constraint, the query works as expected on the latest master commit, but still fails on the RC. This bug affects also FLOAT and DECIMAL, but not INT.

shuke987 commented 4 years ago

/bug P2