tidb-challenge-program / bug-hunting-issue

Bug hunting issues.
3 stars 0 forks source link

P0-[4.0 bug hunting]-[SQL Hint]-INL_HASH_JOIN hint causes an incorrect result for a table with a generated column #50

Open mrigger opened 4 years ago

mrigger commented 4 years ago

Consider the following statements:

CREATE TABLE t0(c0 INT AS (0) VIRTUAL, c1 INT);
CREATE TABLE t1(c0 INT);
INSERT INTO t1(c0) VALUES (0);
SELECT /*+ INL_HASH_JOIN(t1, t0)*/t1.c0 FROM t1 NATURAL LEFT JOIN t0 WHERE NOT t1.c0; -- expected: {0}, actual: {}

Unexpectedly, the query does not fetch the row:

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 INT AS (0) VIRTUAL, c1 INT);
Query OK, 0 rows affected (0.01 sec)

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

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

mysql> SELECT /*+ INL_HASH_JOIN(t1, t0)*/t1.c0 FROM t1 NATURAL LEFT JOIN t0 WHERE NOT t1.c0;
Empty set (0.00 sec)

When removing the index hint /*+ INL_HASH_JOIN(t1, t0)*, the query works as expected.

I found this based on the latest master commit b6fcc157442894f048c1cc65cfcc7776e9ed1a72, and can also reproduce it on the 4.0 RC.

shuke987 commented 4 years ago

/bug P1