Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P0-[4.0-bug-hunting]-[SQL Hint]-Using an index twice in an index hint results in an incorrect result #47

Open
mrigger opened this issue Apr 22, 2020 · 1 comment

Comments

@mrigger
Copy link

mrigger commented Apr 22, 2020

Consider the following statements:

CREATE TABLE t0(c0 INT, c1 INT);
CREATE INDEX i0 ON t0(c0, c1);
INSERT INTO t0 VALUES (0, 0);
SELECT /*+ USE_INDEX(t0, i0, i0)*/t0.c0 FROM t0 WHERE t0.c1; -- expected: {}, actual: {0}

Unexpectedly, when using the index hint, the row is fetched:

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

mysql> CREATE INDEX i0 ON t0(c0, c1);
Query OK, 0 rows affected (0.00 sec)

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

mysql> SELECT /*+ USE_INDEX(t0, i0, i0)*/t0.c0 FROM t0 WHERE t0.c1;
+------+
| c0   |
+------+
|    0 |
+------+
1 row in set (0.00 sec)

When omitting the hint, or specifying i0 only once, the row is not fetched, as expected. I found this bug based on the latest master commit b6fcc157442894f048c1cc65cfcc7776e9ed1a72, and checked that it is also reproducible for the 4.0 RC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants