Current Path : /usr/opt/mysql57/mysql-test/r/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //usr/opt/mysql57/mysql-test/r/opt_hints.result |
# WL#8017 Infrastructure for Optimizer Hints CREATE TABLE t1(f1 INT, f2 INT); INSERT INTO t1 VALUES (1,1),(2,2),(3,3); CREATE TABLE t2(f1 INT NOT NULL, f2 INT NOT NULL, f3 CHAR(200), KEY(f1, f2)); INSERT INTO t2 VALUES (1,1, 'qwerty'),(1,2, 'qwerty'),(1,3, 'qwerty'), (2,1, 'qwerty'),(2,2, 'qwerty'),(2,3, 'qwerty'), (2,4, 'qwerty'),(2,5, 'qwerty'), (3,1, 'qwerty'),(3,4, 'qwerty'), (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'), (4,4, 'qwerty'), (1,1, 'qwerty'),(1,2, 'qwerty'),(1,3, 'qwerty'), (2,1, 'qwerty'),(2,2, 'qwerty'),(2,3, 'qwerty'), (2,4, 'qwerty'),(2,5, 'qwerty'), (3,1, 'qwerty'),(3,4, 'qwerty'), (4,1, 'qwerty'),(4,2, 'qwerty'),(4,3, 'qwerty'), (4,4, 'qwerty'); CREATE TABLE t3 (f1 INT NOT NULL, f2 INT, f3 VARCHAR(32), PRIMARY KEY(f1), KEY f2_idx(f1), KEY f3_idx(f3)); INSERT INTO t3 VALUES (1, 1, 'qwerty'), (2, 1, 'ytrewq'), (3, 2, 'uiop'), (4, 2, 'poiu'), (5, 2, 'lkjh'), (6, 2, 'uiop'), (7, 2, 'poiu'), (8, 2, 'lkjh'), (9, 2, 'uiop'), (10, 2, 'poiu'), (11, 2, 'lkjh'), (12, 2, 'uiop'), (13, 2, 'poiu'), (14, 2, 'lkjh'); INSERT INTO t3 SELECT f1 + 20, f2, f3 FROM t3; INSERT INTO t3 SELECT f1 + 40, f2, f3 FROM t3; ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status OK ANALYZE TABLE t2; Table Op Msg_type Msg_text test.t2 analyze status OK ANALYZE TABLE t3; Table Op Msg_type Msg_text test.t3 analyze status OK # NO_RANGE_OPTIMIZATION hint testing set optimizer_switch=default; # Check statistics with no hint FLUSH STATUS; SELECT f1 FROM t3 WHERE f1 > 30 AND f1 < 33; f1 31 32 SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 0 Handler_read_key 1 Handler_read_last 0 Handler_read_next 2 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 0 # Check statistics with hint FLUSH STATUS; SELECT /*+ NO_RANGE_OPTIMIZATION(t3 PRIMARY, f2_idx) */ f1 FROM t3 WHERE f1 > 30 AND f1 < 33; f1 31 32 SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 1 Handler_read_key 1 Handler_read_last 0 Handler_read_next 56 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 0 EXPLAIN SELECT f1 FROM t3 WHERE f1 > 30 AND f1 < 33; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL range PRIMARY,f2_idx f2_idx 4 NULL 2 100.00 Using where; Using index Warnings: Note 1003 /* select#1 */ select `test`.`t3`.`f1` AS `f1` from `test`.`t3` where ((`test`.`t3`.`f1` > 30) and (`test`.`t3`.`f1` < 33)) # Turn off range access for PRIMARY key # Should use range access by f2_idx key EXPLAIN SELECT /*+ NO_RANGE_OPTIMIZATION(t3 PRIMARY) */ f1 FROM t3 WHERE f1 > 30 AND f1 < 33; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL range PRIMARY,f2_idx f2_idx 4 NULL 2 100.00 Using where; Using index Warnings: Note 1003 /* select#1 */ select /*+ NO_RANGE_OPTIMIZATION(`t3`@`select#1` `PRIMARY`) */ `test`.`t3`.`f1` AS `f1` from `test`.`t3` where ((`test`.`t3`.`f1` > 30) and (`test`.`t3`.`f1` < 33)) # Turn off range access for PRIMARY & f2_idx keys # Should use index access EXPLAIN SELECT /*+ NO_RANGE_OPTIMIZATION(t3 PRIMARY, f2_idx) */ f1 FROM t3 WHERE f1 > 30 AND f1 < 33; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL index PRIMARY,f2_idx f2_idx 4 NULL 56 11.11 Using where; Using index Warnings: Note 1003 /* select#1 */ select /*+ NO_RANGE_OPTIMIZATION(`t3`@`select#1` `PRIMARY`) NO_RANGE_OPTIMIZATION(`t3`@`select#1` `f2_idx`) */ `test`.`t3`.`f1` AS `f1` from `test`.`t3` where ((`test`.`t3`.`f1` > 30) and (`test`.`t3`.`f1` < 33)) # Turn off range access for all keys # Should use index access EXPLAIN SELECT /*+ NO_RANGE_OPTIMIZATION(t3) */ f1 FROM t3 WHERE f1 > 30 AND f1 < 33; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL index PRIMARY,f2_idx f2_idx 4 NULL 56 11.11 Using where; Using index Warnings: Note 1003 /* select#1 */ select /*+ NO_RANGE_OPTIMIZATION(`t3`@`select#1`) */ `test`.`t3`.`f1` AS `f1` from `test`.`t3` where ((`test`.`t3`.`f1` > 30) and (`test`.`t3`.`f1` < 33)) # Turn off range access for PRIMARY & f2_idx keys # Should use index access EXPLAIN SELECT /*+ NO_RANGE_OPTIMIZATION(t3 PRIMARY) NO_RANGE_OPTIMIZATION(t3 f2_idx) */ f1 FROM t3 WHERE f1 > 30 AND f1 < 33; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL index PRIMARY,f2_idx f2_idx 4 NULL 56 11.11 Using where; Using index Warnings: Note 1003 /* select#1 */ select /*+ NO_RANGE_OPTIMIZATION(`t3`@`select#1` `PRIMARY`) NO_RANGE_OPTIMIZATION(`t3`@`select#1` `f2_idx`) */ `test`.`t3`.`f1` AS `f1` from `test`.`t3` where ((`test`.`t3`.`f1` > 30) and (`test`.`t3`.`f1` < 33)) # NO_ICP hint testing set optimizer_switch='index_condition_pushdown=on'; EXPLAIN SELECT f2 FROM (SELECT f2, f3, f1 FROM t3 WHERE f1 > 2 AND f3 = 'poiu') AS TD WHERE TD.f1 > 2 AND TD.f3 = 'poiu'; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL range PRIMARY,f2_idx,f3_idx f3_idx 39 NULL 16 100.00 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t3`.`f2` AS `f2` from `test`.`t3` where ((`test`.`t3`.`f3` = 'poiu') and (`test`.`t3`.`f1` > 2) and (`test`.`t3`.`f1` > 2)) EXPLAIN SELECT /*+ NO_ICP(t3@qb1 f3_idx) */ f2 FROM (SELECT /*+ QB_NAME(QB1) */ f2, f3, f1 FROM t3 WHERE f1 > 2 AND f3 = 'poiu') AS TD WHERE TD.f1 > 2 AND TD.f3 = 'poiu'; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL range PRIMARY,f2_idx,f3_idx f3_idx 39 NULL 16 100.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ NO_ICP(`t3`@`QB1` `f3_idx`) */ `test`.`t3`.`f2` AS `f2` from `test`.`t3` where ((`test`.`t3`.`f3` = 'poiu') and (`test`.`t3`.`f1` > 2) and (`test`.`t3`.`f1` > 2)) EXPLAIN SELECT /*+ NO_ICP(t3@qb1) */ f2 FROM (SELECT /*+ QB_NAME(QB1) */ f2, f3, f1 FROM t3 WHERE f1 > 2 AND f3 = 'poiu') AS TD WHERE TD.f1 > 2 AND TD.f3 = 'poiu'; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL range PRIMARY,f2_idx,f3_idx f3_idx 39 NULL 16 100.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ NO_ICP(`t3`@`QB1`) */ `test`.`t3`.`f2` AS `f2` from `test`.`t3` where ((`test`.`t3`.`f3` = 'poiu') and (`test`.`t3`.`f1` > 2) and (`test`.`t3`.`f1` > 2)) # Expected warning for f1_idx key, unresolved name. EXPLAIN SELECT f2 FROM (SELECT /*+ NO_ICP(t3 f3_idx, f1_idx, f2_idx) */ f2, f3, f1 FROM t3 WHERE f1 > 2 AND f3 = 'poiu') AS TD WHERE TD.f1 > 2 AND TD.f3 = 'poiu'; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL range PRIMARY,f2_idx,f3_idx f3_idx 39 NULL 16 100.00 Using where Warnings: Warning 3128 Unresolved name `t3`@`select#2` `f1_idx` for NO_ICP hint Note 1003 /* select#1 */ select /*+ NO_ICP(`t3`@`select#2` `f3_idx`) NO_ICP(`t3`@`select#2` `f2_idx`) */ `test`.`t3`.`f2` AS `f2` from `test`.`t3` where ((`test`.`t3`.`f3` = 'poiu') and (`test`.`t3`.`f1` > 2) and (`test`.`t3`.`f1` > 2)) # ICP should still be used. EXPLAIN SELECT f2 FROM (SELECT /*+ NO_ICP(t3 f1_idx, f2_idx) */ f2, f3, f1 FROM t3 WHERE f1 > 2 AND f3 = 'poiu') AS TD WHERE TD.f1 > 2 AND TD.f3 = 'poiu'; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL range PRIMARY,f2_idx,f3_idx f3_idx 39 NULL 16 100.00 Using index condition Warnings: Warning 3128 Unresolved name `t3`@`select#2` `f1_idx` for NO_ICP hint Note 1003 /* select#1 */ select /*+ NO_ICP(`t3`@`select#2` `f2_idx`) */ `test`.`t3`.`f2` AS `f2` from `test`.`t3` where ((`test`.`t3`.`f3` = 'poiu') and (`test`.`t3`.`f1` > 2) and (`test`.`t3`.`f1` > 2)) # BKA & NO_BKA hint testing set optimizer_switch=default; set optimizer_switch='batched_key_access=off,mrr_cost_based=off'; # Check statistics without hint FLUSH STATUS; SELECT t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; f1 f2 f3 1 1 qwerty 1 1 qwerty 2 2 qwerty 2 2 qwerty SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 1 Handler_read_key 4 Handler_read_last 0 Handler_read_next 4 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 4 # Check statistics with hint FLUSH STATUS; SELECT /*+ BKA() */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; f1 f2 f3 1 1 qwerty 2 2 qwerty 1 1 qwerty 2 2 qwerty SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 1 Handler_read_key 8 Handler_read_last 0 Handler_read_next 20 Handler_read_prev 0 Handler_read_rnd 4 Handler_read_rnd_next 4 EXPLAIN SELECT t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ BKA(t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t2`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ BKA() */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ BKA(t1, t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t1`@`select#1`) BKA(`t2`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ BKA(t1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t1`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ QB_NAME(QB1) BKA(t2@QB1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`QB1`) BKA(`t2`@`QB1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) set optimizer_switch='batched_key_access=off,mrr_cost_based=on'; EXPLAIN SELECT t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ BKA(t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t2`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ BKA() */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ BKA(t1, t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t1`@`select#1`) BKA(`t2`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ QB_NAME(QB1) BKA(t2@QB1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`QB1`) BKA(`t2`@`QB1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) set optimizer_switch='batched_key_access=on,mrr_cost_based=off'; EXPLAIN SELECT t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) set optimizer_switch='mrr=off'; EXPLAIN SELECT t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) # MRR switch should not affect BKA. # BKA should be used for table t2. EXPLAIN SELECT /*+ BKA(t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t2`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) set optimizer_switch='mrr=on'; EXPLAIN SELECT /*+ NO_BKA(t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Note 1003 /* select#1 */ select /*+ NO_BKA(`t2`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ NO_BKA() */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Note 1003 /* select#1 */ select /*+ NO_BKA(@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ NO_BKA(t1, t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Note 1003 /* select#1 */ select /*+ NO_BKA(`t1`@`select#1`) NO_BKA(`t2`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) EXPLAIN SELECT /*+ QB_NAME(QB1) NO_BKA(t2@QB1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`QB1`) NO_BKA(`t2`@`QB1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) # UPDATE|DELETE|INSERT|REPLACE hint testing set optimizer_switch='batched_key_access=off,mrr_cost_based=off'; EXPLAIN UPDATE t3 SET f3 = 'mnbv' WHERE f1 > 30 AND f1 < 33 AND (t3.f1, t3.f2, t3.f3) IN (SELECT t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t3 NULL range PRIMARY,f2_idx PRIMARY 4 const 2 100.00 Using where 2 DEPENDENT SUBQUERY t2 NULL ref f1 f1 8 func,func 2 10.00 Using index condition; Using where 2 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using join buffer (Block Nested Loop) # Turn off range access for PRIMARY key. # Range access should be used for f2_idx key. EXPLAIN UPDATE /*+ NO_RANGE_OPTIMIZATION(t3 PRIMARY) */ t3 SET f3 = 'mnbv' WHERE f1 > 30 AND f1 < 33 AND (t3.f1, t3.f2, t3.f3) IN (SELECT /*+ BKA(t2) NO_BNL(t1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t3 NULL range f2_idx f2_idx 4 const 2 100.00 Using where 2 DEPENDENT SUBQUERY t2 NULL ref f1 f1 8 func,func 2 10.00 Using index condition; Using where 2 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 3 33.33 Using where EXPLAIN DELETE FROM t3 WHERE f1 > 30 AND f1 < 33 AND (t3.f1, t3.f2, t3.f3) IN (SELECT /*+ QB_NAME(qb1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 DELETE t3 NULL range PRIMARY,f2_idx PRIMARY 4 const 2 100.00 Using where 2 DEPENDENT SUBQUERY t2 NULL ref f1 f1 8 func,func 2 10.00 Using index condition; Using where 2 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 3 33.33 Using where; Using join buffer (Block Nested Loop) # Turn off range access. Range access should not be used. # Turn off BNL. BNL should not be used. EXPLAIN DELETE /*+ NO_RANGE_OPTIMIZATION(t3 PRIMARY, f2_idx) NO_BNL(t1@QB1) */ FROM t3 WHERE f1 > 30 AND f1 < 33 AND (t3.f1, t3.f2, t3.f3) IN (SELECT /*+ QB_NAME(qb1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 DELETE t3 NULL ALL NULL NULL NULL NULL 56 100.00 Using where 2 DEPENDENT SUBQUERY t2 NULL ref f1 f1 8 func,func 2 10.00 Using index condition; Using where 2 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 3 33.33 Using where EXPLAIN INSERT INTO t3(f1, f2, f3) (SELECT t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 INSERT t3 NULL ALL NULL NULL NULL NULL NULL NULL NULL 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition # Turn off ICP. ICP should not be used. EXPLAIN INSERT INTO t3(f1, f2, f3) (SELECT /*+ NO_ICP(t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 INSERT t3 NULL ALL NULL NULL NULL NULL NULL NULL NULL 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using where # Turn off ICP. ICP should not be used. EXPLAIN INSERT /*+ NO_ICP(t2@QB1 f1) */ INTO t3(f1, f2, f3) (SELECT /*+ QB_NAME(qb1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 INSERT t3 NULL ALL NULL NULL NULL NULL NULL NULL NULL 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using where EXPLAIN REPLACE INTO t3(f1, f2, f3) (SELECT t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 REPLACE t3 NULL ALL NULL NULL NULL NULL NULL NULL NULL 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition # Turn off ICP. ICP should not be used. EXPLAIN REPLACE INTO t3(f1, f2, f3) (SELECT /*+ NO_ICP(t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 REPLACE t3 NULL ALL NULL NULL NULL NULL NULL NULL NULL 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using where # Turn off ICP for nonexistent table. ICP should be used. EXPLAIN REPLACE /*+ NO_ICP(t2@qb1) */ INTO t3(f1, f2, f3) SELECT /*+ QB_NAME(qb2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 REPLACE t3 NULL ALL NULL NULL NULL NULL NULL NULL NULL 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Warning 3127 Query block name `qb1` is not found for NO_ICP hint # Turn off ICP. ICP should not be used. EXPLAIN REPLACE /*+ NO_ICP(t2@qb1) */ INTO t3(f1, f2, f3) SELECT /*+ QB_NAME(qb1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 REPLACE t3 NULL ALL NULL NULL NULL NULL NULL NULL NULL 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using where # Misc tests # Should issue warning EXPLAIN SELECT /*+ QB_NAME(qb1) QB_NAME(qb1 ) */ * FROM t2; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 28 100.00 NULL Warnings: Warning 3126 Hint QB_NAME(`qb1`) is ignored as conflicting/duplicated Note 1003 /* select#1 */ select /*+ QB_NAME(`qb1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t2` # Should issue warning EXPLAIN SELECT /*+ BKA(@qb1) QB_NAME(qb1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition Warnings: Warning 3127 Query block name `qb1` is not found for BKA hint Note 1003 /* select#1 */ select /*+ QB_NAME(`qb1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) # Should not crash PREPARE stmt1 FROM "SELECT /*+ BKA(t2) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1"; EXECUTE stmt1; f1 f2 f3 1 1 qwerty 2 2 qwerty 1 1 qwerty 2 2 qwerty EXECUTE stmt1; f1 f2 f3 1 1 qwerty 2 2 qwerty 1 1 qwerty 2 2 qwerty DEALLOCATE PREPARE stmt1; # Check use of alias EXPLAIN SELECT tbl2.f1, tbl2.f2, tbl2.f3 FROM t1 tbl1,t2 tbl2 WHERE tbl1.f1=tbl2.f1 AND tbl2.f2 BETWEEN tbl1.f1 and tbl1.f2 and tbl2.f2 + 1 >= tbl1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE tbl1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE tbl2 NULL ref f1 f1 4 test.tbl1.f1 7 11.11 Using index condition Warnings: Note 1003 /* select#1 */ select `test`.`tbl2`.`f1` AS `f1`,`test`.`tbl2`.`f2` AS `f2`,`test`.`tbl2`.`f3` AS `f3` from `test`.`t1` `tbl1` join `test`.`t2` `tbl2` where ((`test`.`tbl2`.`f1` = `test`.`tbl1`.`f1`) and (`test`.`tbl2`.`f2` between `test`.`tbl1`.`f1` and `test`.`tbl1`.`f2`) and ((`test`.`tbl2`.`f2` + 1) >= (`test`.`tbl1`.`f1` + 1))) # Turn on BKA for multiple tables. BKA should be used for tbl2. EXPLAIN SELECT /*+ BKA(tbl1, tbl2) */ tbl2.f1, tbl2.f2, tbl2.f3 FROM t1 tbl1,t2 tbl2 WHERE tbl1.f1=tbl2.f1 AND tbl2.f2 BETWEEN tbl1.f1 and tbl1.f2 and tbl2.f2 + 1 >= tbl1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE tbl1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE tbl2 NULL ref f1 f1 4 test.tbl1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`tbl1`@`select#1`) BKA(`tbl2`@`select#1`) */ `test`.`tbl2`.`f1` AS `f1`,`test`.`tbl2`.`f2` AS `f2`,`test`.`tbl2`.`f3` AS `f3` from `test`.`t1` `tbl1` join `test`.`t2` `tbl2` where ((`test`.`tbl2`.`f1` = `test`.`tbl1`.`f1`) and (`test`.`tbl2`.`f2` between `test`.`tbl1`.`f1` and `test`.`tbl1`.`f2`) and ((`test`.`tbl2`.`f2` + 1) >= (`test`.`tbl1`.`f1` + 1))) # Print warnings for nonexistent names EXPLAIN SELECT /*+ BKA(t2) NO_BNL(t1) BKA(t3) NO_RANGE_OPTIMIZATION(t3 idx1) NO_RANGE_OPTIMIZATION(t3) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 AND t1.f2 AND t2.f2 + 1 >= t1.f1 + 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Warning 3128 Unresolved name `t3`@`select#1` for BKA hint Warning 3128 Unresolved name `t3`@`select#1` for NO_RANGE_OPTIMIZATION hint Warning 3128 Unresolved name `t3`@`select#1` `idx1` for NO_RANGE_OPTIMIZATION hint Note 1003 /* select#1 */ select /*+ BKA(`t2`@`select#1`) NO_BNL(`t1`@`select#1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) # Check illegal syntax EXPLAIN SELECT /*+ BKA(qb1 t3@qb1) */ f2 FROM (SELECT /*+ QB_NAME(qb1) */ f2, f3, f1 FROM t3 WHERE f1 > 2 AND f3 = 'poiu') AS TD WHERE TD.f1 > 2 AND TD.f3 = 'poiu'; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t3 NULL range PRIMARY,f2_idx,f3_idx f3_idx 39 NULL 16 100.00 Using index condition; Using MRR Warnings: Warning 1064 Optimizer hint syntax error near 't3@qb1) */ f2 FROM (SELECT /*+ QB_NAME(qb1) */ f2, f3, f1 FROM t3 WHERE f1 > 2 A' at line 1 Note 1003 /* select#1 */ select `test`.`t3`.`f2` AS `f2` from `test`.`t3` where ((`test`.`t3`.`f3` = 'poiu') and (`test`.`t3`.`f1` > 2) and (`test`.`t3`.`f1` > 2)) # Check illegal syntax EXPLAIN SELECT * FROM (SELECT /*+ QB_NAME(qb1) BKA(@qb1 t1@qb1, t2@qb1, t3) */ t2.f1, t2.f2, t2.f3 FROM t1,t2,t3) tt; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 28 100.00 Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL index NULL f2_idx 4 NULL 56 100.00 Using index; Using join buffer (Block Nested Loop) Warnings: Warning 1064 Optimizer hint syntax error near 'qb1, t2@qb1, t3) */ t2.f1, t2.f2, t2.f3 FROM t1,t2,t3) tt' at line 2 Note 1003 /* select#1 */ select `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` join `test`.`t3` # Check '@qb_name table_name' syntax. BKA should be used for t2. EXPLAIN SELECT /*+ BKA(@qb1 t2) */ * FROM (SELECT /*+ QB_NAME(QB1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1) AS s1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE t2 NULL ref f1 f1 4 test.t1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t2`@`QB1`) */ `test`.`t2`.`f1` AS `f1`,`test`.`t2`.`f2` AS `f2`,`test`.`t2`.`f3` AS `f3` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`f1` = `test`.`t1`.`f1`) and (`test`.`t2`.`f2` between `test`.`t1`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t1`.`f1` + 1))) # Check that original table name is not recognized if alias is used. EXPLAIN SELECT * FROM (SELECT /*+ BKA(t2) */ tb2.f1, tb2.f2, tb2.f3 FROM t1 tb1,t2 tb2 WHERE tb1.f1=tb2.f1 AND tb2.f2 BETWEEN tb1.f1 and tb1.f2 and tb2.f2 + 1 >= tb1.f1 + 1) AS s1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE tb1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE tb2 NULL ref f1 f1 4 test.tb1.f1 7 11.11 Using index condition Warnings: Warning 3128 Unresolved name `t2`@`select#2` for BKA hint Note 1003 /* select#1 */ select `test`.`tb2`.`f1` AS `f1`,`test`.`tb2`.`f2` AS `f2`,`test`.`tb2`.`f3` AS `f3` from `test`.`t1` `tb1` join `test`.`t2` `tb2` where ((`test`.`tb2`.`f1` = `test`.`tb1`.`f1`) and (`test`.`tb2`.`f2` between `test`.`tb1`.`f1` and `test`.`tb1`.`f2`) and ((`test`.`tb2`.`f2` + 1) >= (`test`.`tb1`.`f1` + 1))) # Table t2 should use BKA. EXPLAIN SELECT * FROM (SELECT /*+ BKA(tb2) */ tb2.f1, tb2.f2, tb2.f3 FROM t1 tb1,t2 tb2 WHERE tb1.f1=tb2.f1 AND tb2.f2 BETWEEN tb1.f1 and tb1.f2 and tb2.f2 + 1 >= tb1.f1 + 1) AS s1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE tb1 NULL ALL NULL NULL NULL NULL 3 100.00 Using where 1 SIMPLE tb2 NULL ref f1 f1 4 test.tb1.f1 7 11.11 Using index condition; Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`tb2`@`select#2`) */ `test`.`tb2`.`f1` AS `f1`,`test`.`tb2`.`f2` AS `f2`,`test`.`tb2`.`f3` AS `f3` from `test`.`t1` `tb1` join `test`.`t2` `tb2` where ((`test`.`tb2`.`f1` = `test`.`tb1`.`f1`) and (`test`.`tb2`.`f2` between `test`.`tb1`.`f1` and `test`.`tb1`.`f2`) and ((`test`.`tb2`.`f2` + 1) >= (`test`.`tb1`.`f1` + 1))) # Check that PS and conventional statements give the same result. FLUSH STATUS; SELECT /*+ BKA(@qb1 t2) */ * FROM (SELECT /*+ QB_NAME(QB1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1) AS s1; f1 f2 f3 1 1 qwerty 2 2 qwerty 1 1 qwerty 2 2 qwerty SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 1 Handler_read_key 8 Handler_read_last 0 Handler_read_next 20 Handler_read_prev 0 Handler_read_rnd 4 Handler_read_rnd_next 4 PREPARE stmt1 FROM "SELECT /*+ BKA(@qb1 t2) */ * FROM (SELECT /*+ QB_NAME(QB1) */ t2.f1, t2.f2, t2.f3 FROM t1,t2 WHERE t1.f1=t2.f1 AND t2.f2 BETWEEN t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1) AS s1"; RESET QUERY CACHE; Warnings: Warning 1681 'RESET QUERY CACHE' is deprecated and will be removed in a future release. FLUSH STATUS; EXECUTE stmt1; f1 f2 f3 1 1 qwerty 2 2 qwerty 1 1 qwerty 2 2 qwerty SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 1 Handler_read_key 8 Handler_read_last 0 Handler_read_next 20 Handler_read_prev 0 Handler_read_rnd 4 Handler_read_rnd_next 4 RESET QUERY CACHE; Warnings: Warning 1681 'RESET QUERY CACHE' is deprecated and will be removed in a future release. FLUSH STATUS; EXECUTE stmt1; f1 f2 f3 1 1 qwerty 2 2 qwerty 1 1 qwerty 2 2 qwerty SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 1 Handler_read_key 8 Handler_read_last 0 Handler_read_next 20 Handler_read_prev 0 Handler_read_rnd 4 Handler_read_rnd_next 4 DEALLOCATE PREPARE stmt1; DROP TABLE t1, t2, t3; # BNL & NO_BNL hint testing set optimizer_switch=default; set optimizer_switch='block_nested_loop=on'; CREATE TABLE t1 (a INT, b INT); INSERT INTO t1 VALUES (1,1),(2,2); CREATE TABLE t2 (a INT, b INT); INSERT INTO t2 VALUES (1,1),(2,2); CREATE TABLE t3 (a INT, b INT); INSERT INTO t3 VALUES (1,1),(2,2); # Check statistics without hint FLUSH STATUS; SELECT t1.* FROM t1,t2,t3; a b 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 3 Handler_read_key 3 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 9 # Check statistics with hint FLUSH STATUS; SELECT /*+ NO_BNL() */t1.* FROM t1,t2,t3; a b 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 7 Handler_read_key 7 Handler_read_last 0 Handler_read_next 0 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 21 EXPLAIN SELECT t1.* FROM t1,t2,t3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` EXPLAIN SELECT /*+ NO_BNL() */t1.* FROM t1,t2,t3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` EXPLAIN SELECT /*+ NO_BNL(t2, t3) */t1.* FROM t1,t2,t3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t2`@`select#1`) NO_BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` EXPLAIN SELECT /*+ NO_BNL(t1, t3) */t1.* FROM t1,t2,t3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t1`@`select#1`) NO_BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` set optimizer_switch='block_nested_loop=off'; EXPLAIN SELECT t1.* FROM t1,t2,t3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` EXPLAIN SELECT /*+ BNL() */t1.* FROM t1,t2,t3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ BNL(@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` EXPLAIN SELECT /*+ BNL(t2, t3) */t1.* FROM t1,t2,t3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t2`@`select#1`) BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` EXPLAIN SELECT /*+ BNL(t1, t3) */t1.* FROM t1,t2,t3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t1`@`select#1`) BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` EXPLAIN SELECT /*+ BNL(t2) BNL(t3) */t1.* FROM t1,t2,t3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t2`@`select#1`) BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` join `test`.`t2` join `test`.`t3` DROP TABLE t1, t2, t3; # BNL in subquery set optimizer_switch = DEFAULT; CREATE TABLE t1 (a INT, b INT, PRIMARY KEY (a)); CREATE TABLE t2 (a INT, INDEX a (a)); CREATE TABLE t3 (a INT, b INT, INDEX a (a,b)); INSERT INTO t1 VALUES (1,10), (2,20), (3,30), (4,40); INSERT INTO t2 VALUES (2), (3), (4), (5); INSERT INTO t3 VALUES (10,3), (20,4), (30,5); ANALYZE TABLE t1, t2, t3; Table Op Msg_type Msg_text test.t1 analyze status OK test.t2 analyze status OK test.t3 analyze status OK SET optimizer_prune_level = 0; EXPLAIN SELECT /*+ QB_NAME(q) */ * FROM t1 JOIN t2 ON t1.b = t2.a WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) */ t3.b FROM t3 JOIN t1 t4 ON t3.b = t4.b); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE <subquery2> NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 <subquery2>.b 1 100.00 Using index 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 25.00 Using where; Using join buffer (Block Nested Loop) 2 MATERIALIZED t3 NULL index NULL a 10 NULL 3 100.00 Using index 2 MATERIALIZED t4 NULL ALL NULL NULL NULL NULL 4 25.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`q`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3` join `test`.`t1` `t4`) join `test`.`t2` where ((`test`.`t2`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`b` = `<subquery2>`.`b`) and (`test`.`t4`.`b` = `test`.`t3`.`b`)) EXPLAIN SELECT /*+ QB_NAME(q) NO_BNL() */ * FROM t1 JOIN t2 ON t1.b = t2.a WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) */ t3.b FROM t3 JOIN t1 t4 ON t3.b = t4.b); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE <subquery2> NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 <subquery2>.b 1 100.00 Using index 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 25.00 Using where 2 MATERIALIZED t3 NULL index NULL a 10 NULL 3 100.00 Using index 2 MATERIALIZED t4 NULL ALL NULL NULL NULL NULL 4 25.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`q`) NO_BNL(@`q`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3` join `test`.`t1` `t4`) join `test`.`t2` where ((`test`.`t2`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`b` = `<subquery2>`.`b`) and (`test`.`t4`.`b` = `test`.`t3`.`b`)) EXPLAIN SELECT /*+ QB_NAME(q) NO_BNL(t1, t2) */ * FROM t1 JOIN t2 ON t1.b = t2.a WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) */ t3.b FROM t3 JOIN t1 t4 ON t3.b = t4.b); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE <subquery2> NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 <subquery2>.b 1 100.00 Using index 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 25.00 Using where 2 MATERIALIZED t3 NULL index NULL a 10 NULL 3 100.00 Using index 2 MATERIALIZED t4 NULL ALL NULL NULL NULL NULL 4 25.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`q`) NO_BNL(`t1`@`q`) NO_BNL(`t2`@`q`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3` join `test`.`t1` `t4`) join `test`.`t2` where ((`test`.`t2`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`b` = `<subquery2>`.`b`) and (`test`.`t4`.`b` = `test`.`t3`.`b`)) EXPLAIN SELECT /*+ QB_NAME(q) NO_BNL(@subq1) */ * FROM t1 JOIN t2 ON t1.b = t2.a WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) */ t3.b FROM t3 JOIN t1 t4 ON t3.b = t4.b); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE <subquery2> NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 <subquery2>.b 1 100.00 Using index 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 25.00 Using where; Using join buffer (Block Nested Loop) 2 MATERIALIZED t3 NULL index NULL a 10 NULL 3 100.00 Using index 2 MATERIALIZED t4 NULL ALL NULL NULL NULL NULL 4 25.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`q`) NO_BNL(@`subq1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3` join `test`.`t1` `t4`) join `test`.`t2` where ((`test`.`t2`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`b` = `<subquery2>`.`b`) and (`test`.`t4`.`b` = `test`.`t3`.`b`)) EXPLAIN SELECT /*+ QB_NAME(q) NO_BNL(t4@subq1) */ * FROM t1 JOIN t2 ON t1.b = t2.a WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) */ t3.b FROM t3 JOIN t1 t4 ON t3.b = t4.b); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE <subquery2> NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 <subquery2>.b 1 100.00 Using index 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 25.00 Using where; Using join buffer (Block Nested Loop) 2 MATERIALIZED t4 NULL ALL NULL NULL NULL NULL 4 100.00 NULL 2 MATERIALIZED t3 NULL index NULL a 10 NULL 3 33.33 Using where; Using index; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`q`) NO_BNL(`t4`@`subq1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3` join `test`.`t1` `t4`) join `test`.`t2` where ((`test`.`t2`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`b` = `<subquery2>`.`b`) and (`test`.`t3`.`b` = `test`.`t4`.`b`)) EXPLAIN SELECT /*+ QB_NAME(q) NO_BNL(t3@subq1,t4@subq1) */ * FROM t1 JOIN t2 ON t1.b = t2.a WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) */ t3.b FROM t3 JOIN t1 t4 ON t3.b = t4.b); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE <subquery2> NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 <subquery2>.b 1 100.00 Using index 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 25.00 Using where; Using join buffer (Block Nested Loop) 2 MATERIALIZED t3 NULL index NULL a 10 NULL 3 100.00 Using index 2 MATERIALIZED t4 NULL ALL NULL NULL NULL NULL 4 25.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`q`) NO_BNL(`t3`@`subq1`) NO_BNL(`t4`@`subq1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3` join `test`.`t1` `t4`) join `test`.`t2` where ((`test`.`t2`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`b` = `<subquery2>`.`b`) and (`test`.`t4`.`b` = `test`.`t3`.`b`)) EXPLAIN SELECT /*+ QB_NAME(q) NO_BNL(@subq1 t3, t4) */ * FROM t1 JOIN t2 ON t1.b = t2.a WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) */ t3.b FROM t3 JOIN t1 t4 ON t3.b = t4.b); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE <subquery2> NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 <subquery2>.b 1 100.00 Using index 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 25.00 Using where; Using join buffer (Block Nested Loop) 2 MATERIALIZED t3 NULL index NULL a 10 NULL 3 100.00 Using index 2 MATERIALIZED t4 NULL ALL NULL NULL NULL NULL 4 25.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`q`) NO_BNL(`t3`@`subq1`) NO_BNL(`t4`@`subq1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3` join `test`.`t1` `t4`) join `test`.`t2` where ((`test`.`t2`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`b` = `<subquery2>`.`b`) and (`test`.`t4`.`b` = `test`.`t3`.`b`)) EXPLAIN SELECT /*+ QB_NAME(q) */ * FROM t1 JOIN t2 ON t1.b = t2.a WHERE t2.a IN (SELECT /*+ QB_NAME(subq1) NO_BNL(t3, t4) */ t3.b FROM t3 JOIN t1 t4 ON t3.b = t4.b); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE <subquery2> NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 <subquery2>.b 1 100.00 Using index 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 4 25.00 Using where; Using join buffer (Block Nested Loop) 2 MATERIALIZED t3 NULL index NULL a 10 NULL 3 100.00 Using index 2 MATERIALIZED t4 NULL ALL NULL NULL NULL NULL 4 25.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`q`) NO_BNL(`t3`@`subq1`) NO_BNL(`t4`@`subq1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a` from `test`.`t1` semi join (`test`.`t3` join `test`.`t1` `t4`) join `test`.`t2` where ((`test`.`t2`.`a` = `<subquery2>`.`b`) and (`test`.`t1`.`b` = `<subquery2>`.`b`) and (`test`.`t4`.`b` = `test`.`t3`.`b`)) SET optimizer_prune_level = DEFAULT; DROP TABLE t1, t2, t3; # MRR & NO_MRR hint testing set optimizer_switch=default; CREATE TABLE t1 ( f1 int NOT NULL DEFAULT '0', f2 int NOT NULL DEFAULT '0', f3 int NOT NULL DEFAULT '0', INDEX idx1(f2, f3), INDEX idx2(f3) ); INSERT INTO t1(f1) VALUES (1), (2), (3), (4), (5), (6), (7), (8); INSERT INTO t1(f2, f3) VALUES (3,4), (3,4); ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status OK set optimizer_switch='mrr=on,mrr_cost_based=off'; # Check statistics without hint FLUSH STATUS; SELECT * FROM t1 WHERE f2 <= 3 AND 3 <= f3; f1 f2 f3 0 3 4 0 3 4 SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 0 Handler_read_key 3 Handler_read_last 0 Handler_read_next 2 Handler_read_prev 0 Handler_read_rnd 2 Handler_read_rnd_next 0 # Check statistics with hint FLUSH STATUS; SELECT /*+ NO_MRR(t1) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; f1 f2 f3 0 3 4 0 3 4 SHOW STATUS LIKE 'handler_read%'; Variable_name Value Handler_read_first 0 Handler_read_key 1 Handler_read_last 0 Handler_read_next 2 Handler_read_prev 0 Handler_read_rnd 0 Handler_read_rnd_next 0 EXPLAIN SELECT * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where; Using MRR Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) # Turn off MRR. MRR should not be used. EXPLAIN SELECT /*+ NO_MRR(t1) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where Warnings: Note 1003 /* select#1 */ select /*+ NO_MRR(`t1`@`select#1`) */ `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) # Turn off MRR. MRR should not be used. EXPLAIN SELECT /*+ NO_MRR(t1 idx2) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where Warnings: Note 1003 /* select#1 */ select /*+ NO_MRR(`t1`@`select#1` `idx2`) */ `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) # Turn off MRR for unused key. MRR should be used. EXPLAIN SELECT /*+ NO_MRR(t1 idx1) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where; Using MRR Warnings: Note 1003 /* select#1 */ select /*+ NO_MRR(`t1`@`select#1` `idx1`) */ `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) set optimizer_switch='mrr=off,mrr_cost_based=off'; EXPLAIN SELECT * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) # Turn on MRR. MRR should be used. EXPLAIN SELECT /*+ MRR(t1) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where; Using MRR Warnings: Note 1003 /* select#1 */ select /*+ MRR(`t1`@`select#1`) */ `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) # Turn on MRR. MRR should be used. EXPLAIN SELECT /*+ MRR(t1 IDX2) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where; Using MRR Warnings: Note 1003 /* select#1 */ select /*+ MRR(`t1`@`select#1` `IDX2`) */ `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) # Turn on MRR for unused key. MRR should not be used. EXPLAIN SELECT /*+ MRR(t1 idx1) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where Warnings: Note 1003 /* select#1 */ select /*+ MRR(`t1`@`select#1` `idx1`) */ `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) set optimizer_switch='mrr=off,mrr_cost_based=on'; EXPLAIN SELECT * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) # Turn on MRR. MRR should be used. EXPLAIN SELECT /*+ MRR(t1) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where; Using MRR Warnings: Note 1003 /* select#1 */ select /*+ MRR(`t1`@`select#1`) */ `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) # Turn on MRR. MRR should be used. EXPLAIN SELECT /*+ MRR(t1 idx2) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where; Using MRR Warnings: Note 1003 /* select#1 */ select /*+ MRR(`t1`@`select#1` `idx2`) */ `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) # Turn on MRR for unused key. MRR should not be used. EXPLAIN SELECT /*+ MRR(t1 IDX1) */ * FROM t1 WHERE f2 <= 3 AND 3 <= f3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL range idx1,idx2 idx2 4 NULL 2 100.00 Using index condition; Using where Warnings: Note 1003 /* select#1 */ select /*+ MRR(`t1`@`select#1` `IDX1`) */ `test`.`t1`.`f1` AS `f1`,`test`.`t1`.`f2` AS `f2`,`test`.`t1`.`f3` AS `f3` from `test`.`t1` where ((`test`.`t1`.`f2` <= 3) and (3 <= `test`.`t1`.`f3`)) DROP TABLE t1; # # Bug#21205282 CRASH/ASSERTION IN JOIN_CACHE::SET_MATCH_FLAG_IF_NONE WITH NO_BNL HINT # CREATE TABLE t(a INT); INSERT INTO t VALUES (1); SET optimizer_switch='block_nested_loop=on'; EXPLAIN SELECT 1 FROM t t1 LEFT JOIN t t2 ON 1 LEFT JOIN (t t3 LEFT JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t` `t1` left join `test`.`t` `t2` on(1) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(1)) on(1) where 1 EXPLAIN SELECT /*+ NO_BNL(t1) */ 1 FROM t t1 LEFT JOIN t t2 ON 1 LEFT JOIN (t t3 LEFT JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t1`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join `test`.`t` `t2` on(1) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(1)) on(1) where 1 EXPLAIN SELECT /*+ NO_BNL(t2) */ 1 FROM t t1 LEFT JOIN t t2 ON 1 LEFT JOIN (t t3 LEFT JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t2`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join `test`.`t` `t2` on(1) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(1)) on(1) where 1 EXPLAIN SELECT /*+ NO_BNL(t3) */ 1 FROM t t1 LEFT JOIN t t2 ON 1 LEFT JOIN (t t3 LEFT JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t3`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join `test`.`t` `t2` on(1) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(1)) on(1) where 1 EXPLAIN SELECT /*+ NO_BNL(t4) */ 1 FROM t t1 LEFT JOIN t t2 ON 1 LEFT JOIN (t t3 LEFT JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t4`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join `test`.`t` `t2` on(1) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(1)) on(1) where 1 EXPLAIN SELECT /*+ NO_BNL(t3) */ 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 LEFT JOIN t t4 ON 1) ON 1 WHERE 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t3`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on(1) left join `test`.`t` `t4` on(1)) on(1) where 1 SELECT /*+ NO_BNL(t4) */ 1 FROM t t1 LEFT JOIN t t2 ON 1 LEFT JOIN (t t3 LEFT JOIN t t4 ON 1) ON 1; 1 1 SELECT /*+ NO_BNL(t3) */ 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 LEFT JOIN t t4 ON 1) ON 1 WHERE 1; 1 1 SET optimizer_switch='block_nested_loop=off'; EXPLAIN SELECT 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 INNER JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select 1 AS `1` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on(1) join `test`.`t` `t4`) on((1 and 1)) where 1 EXPLAIN SELECT /*+ BNL(t1) */ 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 INNER JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t1`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on(1) join `test`.`t` `t4`) on((1 and 1)) where 1 EXPLAIN SELECT /*+ BNL(t2) */ 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 INNER JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t2`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on(1) join `test`.`t` `t4`) on((1 and 1)) where 1 EXPLAIN SELECT /*+ BNL(t3) */ 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 INNER JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t3`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on(1) join `test`.`t` `t4`) on((1 and 1)) where 1 EXPLAIN SELECT /*+ BNL(t4) */ 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 INNER JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t4`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on(1) join `test`.`t` `t4`) on((1 and 1)) where 1 EXPLAIN SELECT /*+ BNL(t2, t3) */ 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 INNER JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t2`@`select#1`) BNL(`t3`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on(1) join `test`.`t` `t4`) on((1 and 1)) where 1 EXPLAIN SELECT /*+ BNL(t3, t4) */ 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 INNER JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t3`@`select#1`) BNL(`t4`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on(1) join `test`.`t` `t4`) on((1 and 1)) where 1 EXPLAIN SELECT /*+ BNL(t2, t3, t4) */ 1 FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON 1 INNER JOIN t t4 ON 1) ON 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t2`@`select#1`) BNL(`t3`@`select#1`) BNL(`t4`@`select#1`) */ 1 AS `1` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on(1) join `test`.`t` `t4`) on((1 and 1)) where 1 DROP TABLE t; CREATE TABLE t(a INT, b INT, KEY k(a)); INSERT INTO t VALUES (1,1); EXPLAIN SELECT * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 USING(a) LEFT JOIN t t4 USING(a)) USING(a); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t4 NULL ref k k 5 test.t1.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`a` = `test`.`t1`.`a`)) left join `test`.`t` `t4` on((`test`.`t4`.`a` = `test`.`t1`.`a`))) on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 EXPLAIN SELECT /*+ BKA(t1) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 USING(a) LEFT JOIN t t4 USING(a)) USING(a); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t4 NULL ref k k 5 test.t1.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t1`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`a` = `test`.`t1`.`a`)) left join `test`.`t` `t4` on((`test`.`t4`.`a` = `test`.`t1`.`a`))) on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 EXPLAIN SELECT /*+ BKA(t2) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 USING(a) LEFT JOIN t t4 USING(a)) USING(a); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t4 NULL ref k k 5 test.t1.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t2`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`a` = `test`.`t1`.`a`)) left join `test`.`t` `t4` on((`test`.`t4`.`a` = `test`.`t1`.`a`))) on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 EXPLAIN SELECT /*+ BKA(t3) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 USING(a) LEFT JOIN t t4 USING(a)) USING(a); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t4 NULL ref k k 5 test.t1.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`a` = `test`.`t1`.`a`)) left join `test`.`t` `t4` on((`test`.`t4`.`a` = `test`.`t1`.`a`))) on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 EXPLAIN SELECT /*+ BKA(t4) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 USING(a) LEFT JOIN t t4 USING(a)) USING(a); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t4 NULL ref k k 5 test.t1.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`a` = `test`.`t1`.`a`)) left join `test`.`t` `t4` on((`test`.`t4`.`a` = `test`.`t1`.`a`))) on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 EXPLAIN SELECT /*+ BKA(t2, t3) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 USING(a) LEFT JOIN t t4 USING(a)) USING(a); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t4 NULL ref k k 5 test.t1.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t2`@`select#1`) BKA(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`a` = `test`.`t1`.`a`)) left join `test`.`t` `t4` on((`test`.`t4`.`a` = `test`.`t1`.`a`))) on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 EXPLAIN SELECT /*+ BKA(t2, t4) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 USING(a) LEFT JOIN t t4 USING(a)) USING(a); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t4 NULL ref k k 5 test.t1.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t2`@`select#1`) BKA(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`a` = `test`.`t1`.`a`)) left join `test`.`t` `t4` on((`test`.`t4`.`a` = `test`.`t1`.`a`))) on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 EXPLAIN SELECT /*+ BKA(t2, t3, t4) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 USING(a) LEFT JOIN t t4 USING(a)) USING(a); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 Using join buffer (Batched Key Access) 1 SIMPLE t3 NULL ref k k 5 test.t1.a 1 100.00 Using join buffer (Batched Key Access) 1 SIMPLE t4 NULL ref k k 5 test.t1.a 1 100.00 Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t2`@`select#1`) BKA(`t3`@`select#1`) BKA(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`a` = `test`.`t1`.`a`)) left join `test`.`t` `t4` on((`test`.`t4`.`a` = `test`.`t1`.`a`))) on((`test`.`t2`.`a` = `test`.`t1`.`a`)) where 1 SET optimizer_switch='block_nested_loop=on,batched_key_access=on,mrr_cost_based=off'; EXPLAIN SELECT * FROM t t1 INNER JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b LEFT JOIN t t4 ON t3.b=t4.b) ON t1.a=t2.a; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` join `test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`b` = `test`.`t2`.`b`)) left join `test`.`t` `t4` on((`test`.`t4`.`b` = `test`.`t3`.`b`)) where (`test`.`t2`.`a` = `test`.`t1`.`a`) EXPLAIN SELECT /*+ NO_BKA(t1) */ * FROM t t1 INNER JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b LEFT JOIN t t4 ON t3.b=t4.b) ON t1.a=t2.a; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ NO_BKA(`t1`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` join `test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`b` = `test`.`t2`.`b`)) left join `test`.`t` `t4` on((`test`.`t4`.`b` = `test`.`t3`.`b`)) where (`test`.`t2`.`a` = `test`.`t1`.`a`) EXPLAIN SELECT /*+ NO_BKA(t2) */ * FROM t t1 INNER JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b LEFT JOIN t t4 ON t3.b=t4.b) ON t1.a=t2.a; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ NO_BKA(`t2`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` join `test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`b` = `test`.`t2`.`b`)) left join `test`.`t` `t4` on((`test`.`t4`.`b` = `test`.`t3`.`b`)) where (`test`.`t2`.`a` = `test`.`t1`.`a`) EXPLAIN SELECT /*+ NO_BNL(t3) */ * FROM t t1 INNER JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b LEFT JOIN t t4 ON t3.b=t4.b) ON t1.a=t2.a; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` join `test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`b` = `test`.`t2`.`b`)) left join `test`.`t` `t4` on((`test`.`t4`.`b` = `test`.`t3`.`b`)) where (`test`.`t2`.`a` = `test`.`t1`.`a`) EXPLAIN SELECT /*+ NO_BNL(t4) */ * FROM t t1 INNER JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b LEFT JOIN t t4 ON t3.b=t4.b) ON t1.a=t2.a; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` join `test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`b` = `test`.`t2`.`b`)) left join `test`.`t` `t4` on((`test`.`t4`.`b` = `test`.`t3`.`b`)) where (`test`.`t2`.`a` = `test`.`t1`.`a`) EXPLAIN SELECT /*+ NO_BKA(t2) NO_BNL(t3) */ * FROM t t1 INNER JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b LEFT JOIN t t4 ON t3.b=t4.b) ON t1.a=t2.a; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ NO_BKA(`t2`@`select#1`) NO_BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` join `test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`b` = `test`.`t2`.`b`)) left join `test`.`t` `t4` on((`test`.`t4`.`b` = `test`.`t3`.`b`)) where (`test`.`t2`.`a` = `test`.`t1`.`a`) EXPLAIN SELECT /*+ NO_BNL(t3) NO_BKA(t4) */ * FROM t t1 INNER JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b LEFT JOIN t t4 ON t3.b=t4.b) ON t1.a=t2.a; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t3`@`select#1`) NO_BKA(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` join `test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`b` = `test`.`t2`.`b`)) left join `test`.`t` `t4` on((`test`.`t4`.`b` = `test`.`t3`.`b`)) where (`test`.`t2`.`a` = `test`.`t1`.`a`) EXPLAIN SELECT /*+ NO_BKA(t2) NO_BNL(t3) NO_BKA(t4) */ * FROM t t1 INNER JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b LEFT JOIN t t4 ON t3.b=t4.b) ON t1.a=t2.a; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t2 NULL ref k k 5 test.t1.a 1 100.00 NULL 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: Note 1003 /* select#1 */ select /*+ NO_BKA(`t2`@`select#1`) NO_BNL(`t3`@`select#1`) NO_BKA(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` join `test`.`t` `t2` left join `test`.`t` `t3` on((`test`.`t3`.`b` = `test`.`t2`.`b`)) left join `test`.`t` `t4` on((`test`.`t4`.`b` = `test`.`t3`.`b`)) where (`test`.`t2`.`a` = `test`.`t1`.`a`) SET optimizer_switch='batched_key_access=off'; EXPLAIN SELECT * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BKA(t1) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t1`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ NO_BNL(t2) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_BNL(`t2`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BNL(t3) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BKA(t4) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BNL(t2, t3) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t2`@`select#1`) BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BKA(t3, t4) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where; Using join buffer (Block Nested Loop) 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 Using join buffer (Batched Key Access) Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t3`@`select#1`) BKA(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 SET optimizer_switch='block_nested_loop=off'; EXPLAIN SELECT * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BKA(t1) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t1`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BNL(t2) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t2`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BNL(t3) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BKA(t4) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BNL(t2, t3) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t2`@`select#1`) BNL(`t3`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BKA(t3, t4) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BKA(`t3`@`select#1`) BKA(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 EXPLAIN SELECT /*+ BNL(t2, t3, t4) */ * FROM t t1 LEFT JOIN (t t2 LEFT JOIN t t3 ON t2.b=t3.b INNER JOIN t t4 ON t3.a=t4.a) ON t1.b=t2.b; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 SIMPLE t2 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 1 SIMPLE t3 NULL ALL k NULL NULL NULL 1 100.00 Using where 1 SIMPLE t4 NULL ref k k 5 test.t3.a 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ BNL(`t2`@`select#1`) BNL(`t3`@`select#1`) BNL(`t4`@`select#1`) */ `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b`,`test`.`t4`.`a` AS `a`,`test`.`t4`.`b` AS `b` from `test`.`t` `t1` left join (`test`.`t` `t2` join `test`.`t` `t3` join `test`.`t` `t4`) on(((`test`.`t4`.`a` = `test`.`t3`.`a`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t3`.`b` = `test`.`t1`.`b`))) where 1 DROP TABLE t; set optimizer_switch=default; # # Duplicate hints # CREATE TABLE t1 (i INT PRIMARY KEY); SELECT /*+ BKA() BKA() */ 1; 1 1 Warnings: Warning 3126 Hint BKA( ) is ignored as conflicting/duplicated SELECT /*+ BKA(t1) BKA(t1) */ * FROM t1; i Warnings: Warning 3126 Hint BKA(`t1` ) is ignored as conflicting/duplicated SELECT /*+ QB_NAME(q1) BKA(t1@q1) BKA(t1@q1) */ * FROM t1; i Warnings: Warning 3126 Hint BKA(`t1`@`q1` ) is ignored as conflicting/duplicated SELECT /*+ QB_NAME(q1) NO_ICP(@q1 t1 PRIMARY) NO_ICP(@q1 t1 PRIMARY) */ * FROM t1; i Warnings: Warning 3126 Hint NO_ICP(`t1`@`q1` `PRIMARY` ) is ignored as conflicting/duplicated DROP TABLE t1; # # Bug#21192857 ASSERTION FAILED: KEYINFO_ARRAY.SIZE() == 0, FILE OPT_HINTS.CC:280 # CREATE TABLE t1(a INT, KEY(a)); INSERT INTO t1(a) SELECT /*+ NO_RANGE_OPTIMIZATION(t1 a)*/ 1 FROM t1; DROP TABLE t1; # WL#8016 Parser for optimizer hints CREATE TABLE t1 (i INT, j INT); CREATE INDEX i1 ON t1(i); CREATE INDEX i2 ON t1(j); # empty hint comment is ok: SELECT /*+*/ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '*/' at line 1 SELECT /*+ */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '*/' at line 1 SELECT /*+ * ** / // /* */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '* ** / // /* */ 1' at line 1 SELECT /*+ @ */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '@ */ 1' at line 1 SELECT /*+ @foo */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '@foo */ 1' at line 1 SELECT /*+ foo@bar */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near 'foo@bar */ 1' at line 1 SELECT /*+ foo @bar */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near 'foo @bar */ 1' at line 1 SELECT /*+ `@` */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '@` */ 1' at line 1 SELECT /*+ `@foo` */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '@foo` */ 1' at line 1 SELECT /*+ `foo@bar` */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near 'foo@bar` */ 1' at line 1 SELECT /*+ `foo @bar` */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near 'foo @bar` */ 1' at line 1 SELECT /*+ BKA( @) */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1' at line 1 SELECT /*+ BKA( @) */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1' at line 1 SELECT /*+ BKA(t1 @) */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '@) */ 1' at line 1 # We don't support "*/" inside quoted identifiers (syntax error): SELECT /*+ BKA(`test*/`) */ 1; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`) */ 1' at line 1 # valid hint sequences: SELECT /*+ NO_ICP() */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1' at line 1 SELECT /*+NO_ICP()*/ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ')*/ 1' at line 1 SELECT /*+ NO_ICP () */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1' at line 1 SELECT /*+ NO_ICP ( ) */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1' at line 1 SELECT /*+ NO_ICP() */ 1 UNION SELECT 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1 UNION SELECT 1' at line 1 (SELECT /*+ NO_ICP() */ 1) UNION (SELECT 1); 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1) UNION (SELECT 1)' at line 1 ((SELECT /* + NO_ICP() */ 1)); 1 1 EXPLAIN SELECT /*+ QB_NAME(qb1) */ 1 UNION SELECT /*+ QB_NAME(qb2) */ 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> NULL ALL NULL NULL NULL NULL NULL NULL Using temporary Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`qb1`) */ 1 AS `1` union /* select#2 */ select /*+ QB_NAME(`qb2`) */ 1 AS `1` EXPLAIN (SELECT /*+ QB_NAME(qb1) */ 1) UNION (SELECT /*+ QB_NAME(qb2) */ 1); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used 2 UNION NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used NULL UNION RESULT <union1,2> NULL ALL NULL NULL NULL NULL NULL NULL Using temporary Warnings: Note 1003 (/* select#1 */ select /*+ QB_NAME(`qb1`) */ 1 AS `1`) union (/* select#2 */ select /*+ QB_NAME(`qb2`) */ 1 AS `1`) UPDATE /*+ NO_ICP() */ t1 SET i = 10; Warnings: Warning 1064 Optimizer hint syntax error near ') */ t1 SET i = 10' at line 1 INSERT /*+ NO_ICP() */ INTO t1 VALUES (); Warnings: Warning 1064 Optimizer hint syntax error near ') */ INTO t1 VALUES ()' at line 1 REPLACE /*+ NO_ICP() */ INTO t1 VALUES (); Warnings: Warning 1064 Optimizer hint syntax error near ') */ INTO t1 VALUES ()' at line 1 DELETE /*+ NO_ICP() */ FROM t1 WHERE 1; Warnings: Warning 1064 Optimizer hint syntax error near ') */ FROM t1 WHERE 1' at line 1 SELECT /*+ BKA(t1) */ 1 FROM t1; 1 SELECT /*+ BKA(a b) */ 1 FROM t1 a, t1 b; 1 Warnings: Warning 1064 Optimizer hint syntax error near 'b) */ 1 FROM t1 a, t1 b' at line 1 SELECT /*+ NO_ICP(i1) */ 1 FROM t1; 1 Warnings: Warning 3128 Unresolved name `i1`@`select#1` for NO_ICP hint SELECT /*+ NO_ICP(i1 i2) */ 1 FROM t1; 1 Warnings: Warning 3128 Unresolved name `i1`@`select#1` `i2` for NO_ICP hint SELECT /*+ NO_ICP(@qb ident) */ 1 FROM t1; 1 Warnings: Warning 3127 Query block name `qb` is not found for NO_ICP hint # # test explainable statements for hint support: # they should warn with a hint syntax error near "test */" # EXPLAIN SELECT /*+ test */ 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Warning 1064 Optimizer hint syntax error near 'test */ 1' at line 1 Note 1003 /* select#1 */ select 1 AS `1` EXPLAIN INSERT /*+ test */ INTO t1 VALUES (10, 10); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 INSERT t1 NULL ALL NULL NULL NULL NULL NULL NULL NULL Warnings: Warning 1064 Optimizer hint syntax error near 'test */ INTO t1 VALUES (10, 10)' at line 1 EXPLAIN REPLACE /*+ test */ INTO t1 VALUES (10, 10); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 REPLACE t1 NULL ALL NULL NULL NULL NULL NULL NULL NULL Warnings: Warning 1064 Optimizer hint syntax error near 'test */ INTO t1 VALUES (10, 10)' at line 1 EXPLAIN UPDATE /*+ test */ t1 SET i = 10 WHERE j = 10; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t1 NULL range i2 i2 5 const 1 100.00 Using where Warnings: Warning 1064 Optimizer hint syntax error near 'test */ t1 SET i = 10 WHERE j = 10' at line 1 EXPLAIN DELETE /*+ test */ FROM t1 WHERE i = 10; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 DELETE t1 NULL range i1 i1 5 const 1 100.00 Using where Warnings: Warning 1064 Optimizer hint syntax error near 'test */ FROM t1 WHERE i = 10' at line 1 # non-alphabetic and non-ASCII identifiers: CREATE INDEX 3rd_index ON t1(i, j); SELECT /*+ NO_ICP(3rd_index) */ 1 FROM t1; 1 Warnings: Warning 3128 Unresolved name `3rd_index`@`select#1` for NO_ICP hint CREATE INDEX $index ON t1(j, i); SELECT /*+ NO_ICP($index) */ 1 FROM t1; 1 Warnings: Warning 3128 Unresolved name `$index`@`select#1` for NO_ICP hint CREATE TABLE ` quoted name тест` (i INT); SELECT /*+ BKA(` quoted name тест`) */ 1 FROM t1; 1 Warnings: Warning 3128 Unresolved name ` quoted name тест`@`select#1` for BKA hint SELECT /*+ BKA(` quoted name тест`@`select#1`) */ 1 FROM t1; 1 Warnings: Warning 3127 Query block name `select#1` is not found for BKA hint DROP TABLE ` quoted name тест`; SET SQL_MODE = 'ANSI_QUOTES'; Warnings: Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release. CREATE TABLE " quoted name тест" (i INT); SELECT /*+ BKA(" quoted name тест") */ 1 FROM t1; 1 Warnings: Warning 3128 Unresolved name " quoted name тест"@"select#1" for BKA hint SELECT /*+ BKA(" quoted name тест"@"select#1") */ 1 FROM t1; 1 Warnings: Warning 3127 Query block name "select#1" is not found for BKA hint CREATE TABLE `test1``test2``` (i INT); SELECT /*+ BKA(`test1``test2```) */ 1; 1 1 Warnings: Warning 3128 Unresolved name "test1`test2`"@"select#1" for BKA hint SELECT /*+ BKA("test1""test2""") */ 1; 1 1 Warnings: Warning 3128 Unresolved name "test1""test2"""@"select#1" for BKA hint SET SQL_MODE = ''; # should warn: SELECT /*+ BKA(" quoted name тест") */ 1 FROM t1; 1 Warnings: Warning 1064 Optimizer hint syntax error near '" quoted name тест") */ 1 FROM t1' at line 1 DROP TABLE ` quoted name тест`; DROP TABLE `test1``test2```; EXPLAIN SELECT /*+ QB_NAME(`*`) */ 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`*`) */ 1 AS `1` EXPLAIN SELECT /*+ QB_NAME(`a*`) */ 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`a*`) */ 1 AS `1` EXPLAIN SELECT /*+ QB_NAME(`*b`) */ 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`*b`) */ 1 AS `1` EXPLAIN SELECT /*+ QB_NAME(`a b`) */ 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`a b`) */ 1 AS `1` # hint syntax error: empty quoted identifier EXPLAIN SELECT /*+ QB_NAME(``) */ 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Warning 1064 Optimizer hint syntax error near '`) */ 1' at line 1 Note 1003 /* select#1 */ select 1 AS `1` SET NAMES utf8; EXPLAIN SELECT /*+ QB_NAME(````) */ 1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(````) */ 1 AS `1` CREATE TABLE tableТ (i INT); SELECT /*+ BKA(tableТ) */ 1 FROM t1; 1 Warnings: Warning 3128 Unresolved name `tableТ`@`select#1` for BKA hint SELECT /*+ BKA(test@tableТ) */ 1 FROM t1; 1 Warnings: Warning 3127 Query block name `tableТ` is not found for BKA hint DROP TABLE tableТ; CREATE TABLE таблица (i INT); SELECT /*+ BKA(`таблица`) */ 1 FROM t1; 1 Warnings: Warning 3128 Unresolved name `таблица`@`select#1` for BKA hint SELECT /*+ BKA(таблица) */ 1 FROM t1; 1 Warnings: Warning 3128 Unresolved name `таблица`@`select#1` for BKA hint SELECT /*+ BKA(test@таблица) */ 1 FROM t1; 1 Warnings: Warning 3127 Query block name `таблица` is not found for BKA hint # broken multibyte char, should warn: SELECT /*+ NO_ICP(``) */ 1 FROM t1; 1 Warnings: Warning 1064 Optimizer hint syntax error near '?`) */ 1 FROM t1' at line 1 DROP TABLE таблица; # derived tables and other subqueries: SELECT * FROM (SELECT /*+ DEBUG_HINT3 */ 1) a; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near 'DEBUG_HINT3 */ 1) a' at line 1 SELECT (SELECT /*+ DEBUG_HINT3 */ 1); (SELECT /*+ DEBUG_HINT3 */ 1) 1 Warnings: Warning 1064 Optimizer hint syntax error near 'DEBUG_HINT3 */ 1)' at line 1 SELECT 1 FROM DUAL WHERE 1 IN (SELECT /*+ DEBUG_HINT3 */ 1); 1 1 Warnings: Warning 1064 Optimizer hint syntax error near 'DEBUG_HINT3 */ 1)' at line 1 # invalid hint sequences (should warn): SELECT /*+ 10 */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '10 */ 1' at line 1 SELECT /*+ NO_ICP() */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1' at line 1 SELECT /*+ NO_ICP(10) */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '10) */ 1' at line 1 SELECT /*+ NO_ICP( */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '*/' at line 1 SELECT /*+ NO_ICP) */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1' at line 1 SELECT /*+ NO_ICP(t1 */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '*/' at line 1 SELECT /*+ NO_ICP(t1 ( */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '( */ 1' at line 1 (SELECT 1) UNION (SELECT /*+ NO_ICP() */ 1); 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1)' at line 1 INSERT INTO t1 VALUES (1, 1), (2, 2); # wrong place for hint, so recognize that stuff as a regular commentary: SELECT 1 FROM /*+ regular commentary, not a hint! */ t1; 1 1 1 SELECT 1 FROM /*+ #1 */ t1 WHERE /*+ #2 */ 1 /*+ #3 */; 1 1 1 SELECT /*+ NO_ICP() */ 1 FROM /*+ regular commentary, not a hint! */ t1; 1 1 1 Warnings: Warning 1064 Optimizer hint syntax error near ') */ 1 FROM /*+ regular commentary, not a hint! */ t1' at line 1 SELECT /*+ NO_ICP(t1) bad_hint */ 1 FROM t1; 1 1 1 Warnings: Warning 1064 Optimizer hint syntax error near 'bad_hint */ 1 FROM t1' at line 1 SELECT /*+ NO_ICP(@qb ident) */ 1 FROM t1; 1 1 1 Warnings: Warning 3127 Query block name `qb` is not found for NO_ICP hint SELECT /*+ ? bad syntax */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '? bad syntax */ 1' at line 2 SELECT /*+ ? bad syntax */ 1; 1 1 Warnings: Warning 1064 Optimizer hint syntax error near '? bad syntax */ 1' at line 2 DROP TABLE t1; # # Bug #21095608: OPTIMIZER HINT PARSER DOESN'T ACCEPT NUMBER-PREFIXED # QUERY BLOCK NAMES AFTER @ # CREATE TABLE t1 (i INT); EXPLAIN SELECT /*+ QB_NAME(1a) BKA(t1@1a) */ 1 FROM t1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ QB_NAME(`1a`) BKA(`t1`@`1a`) */ 1 AS `1` from `test`.`t1` DROP TABLE t1; # # Bug #21148405: OPTIMIZER HINTS: READ OF FREE MEMORY FOR INVALID HINTS # CREATE PROCEDURE p1() BEGIN DECLARE cur1 CURSOR FOR SELECT /*+ NO_MRR(q w)*/1; OPEN cur1; END| CALL p1(); Warnings: Warning 3128 Unresolved name `q`@`select#1` `w` for NO_MRR hint CALL p1(); Warnings: Warning 3128 Unresolved name `q`@`select#1` `w` for NO_MRR hint DROP PROCEDURE p1; # # Unbalanced commentary test # SELECT /*+ 10; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/*+ 10' at line 1