| Bug #60080 | STRAIGHT_JOIN is not enforced when right-hand table is itself a JOIN | ||
|---|---|---|---|
| Submitted: | 10 Feb 2011 9:29 | Modified: | 10 Feb 2012 3:11 |
| Reporter: | Roy Lyseng | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | MySQL Server: Optimizer | Severity: | S3 (Non-critical) |
| Version: | 5.5, mysql-trunk | OS: | Any |
| Assigned to: | CPU Architecture: | Any | |
[10 Feb 2011 9:29]
Roy Lyseng
[10 Feb 2011 9:48]
Roy Lyseng
More STRAIGHT_JOIN test cases can be found in the attachment to bug#56529: http://bugs.mysql.com/file.php?id=15677&text=1
[10 Feb 2011 10:51]
Valeriy Kravchuk
Verified with current mysql-trunk on 32-bit Ubuntu 10.04:
openxs@ubuntu:/home2/openxs/dbs/trunk$ bin/mysql --no-defaults -uroot testReading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.2-m5-valgrind-max-debug Source distribution
Copyright (c) 2000, 2010, 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> drop table t1, t2, t3;
ERROR 1051 (42S02): Unknown table 'test.t1,test.t2,test.t3'
mysql> CREATE TABLE t1 (
-> col_int_nokey INTEGER,
-> col_int_key INTEGER,
-> col_varchar_key VARCHAR(1),
->
-> KEY (col_int_key),
-> KEY (col_varchar_key, col_int_key)
-> );
Query OK, 0 rows affected (0.48 sec)
mysql> INSERT INTO t1 VALUES (NULL,2,'w');
Query OK, 1 row affected (0.22 sec)
mysql> INSERT INTO t1 VALUES (7,9,'m');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO t1 VALUES (9,3,'m');
Query OK, 1 row affected (0.00 sec)
...
mysql> INSERT INTO t1 VALUES (NULL,6,'f');
Query OK, 1 row affected (0.01 sec)
mysql> CREATE TABLE t2 (
-> c1 INTEGER NOT NULL
-> );
Query OK, 0 rows affected (0.02 sec)
mysql> explain SELECT table1.col_int_nokey
-> FROM t1 AS table1 STRAIGHT_JOIN (
-> t1 AS table2 INNER JOIN t1 AS table3
-> ON table3.col_varchar_key = table2.col_varchar_key)
-> ON table3.col_int_nokey = table1.col_int_key
-> WHERE table3.col_int_key != SOME ( SELECT c1 FROM t2 );
+----+--------------------+--------+-------+-----------------+-----------------+---------+-----------------------------+------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+--------------------+--------+-------+-----------------+-----------------+---------+-----------------------------+------+--------------------------+
| 1 | PRIMARY | table2 | index | col_varchar_key | col_varchar_key | 9 | NULL | 19 | Using where; Using index |
| 1 | PRIMARY | table3 | ref | col_varchar_key | col_varchar_key | 4 | test.table2.col_varchar_key | 1 | Using where |
| 1 | PRIMARY | table1 | ref | col_int_key | col_int_key | 5 | test.table3.col_int_nokey | 1 | |
| 2 | DEPENDENT SUBQUERY | t2 | ALL | NULL | NULL | NULL | NULL | 1 | Using where |
+----+--------------------+--------+-------+-----------------+-----------------+---------+-----------------------------+------+--------------------------+
4 rows in set (0.12 sec)
As you can see, optimizer does NOT start with table1.
[10 Feb 2012 3:11]
Paul DuBois
Noted in 5.6.5 changelog. The optimizer mishandled STRAIGHT_JOIN used with nested joins; for example, by not evaluating tables in the specified order.
