# 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 4 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) */ 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,f3_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,f3_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 skip scan for f3_idx index 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 range PRIMARY,f2_idx,f3_idx f3_idx 135 NULL 6 100.00 Using where; Using index for skip scan 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 range PRIMARY,f2_idx,f3_idx f3_idx 135 NULL 6 100.00 Using where; Using index for skip scan 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 > 27 AND f3 = 'poiu') AS TD WHERE TD.f1 > 27 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 135 NULL 10 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` > 27) and (`test`.`t3`.`f1` > 27)) EXPLAIN SELECT /*+ NO_ICP(t3@qb1 f3_idx) */ f2 FROM (SELECT /*+ QB_NAME(QB1) */ f2, f3, f1 FROM t3 WHERE f1 > 27 AND f3 = 'poiu') AS TD WHERE TD.f1 > 27 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 135 NULL 10 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` > 27) and (`test`.`t3`.`f1` > 27)) EXPLAIN SELECT /*+ NO_ICP(t3@qb1) */ f2 FROM (SELECT /*+ QB_NAME(QB1) */ f2, f3, f1 FROM t3 WHERE f1 > 27 AND f3 = 'poiu') AS TD WHERE TD.f1 > 27 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 135 NULL 10 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` > 27) and (`test`.`t3`.`f1` > 27)) # 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 > 27 AND f3 = 'poiu') AS TD WHERE TD.f1 > 27 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 135 NULL 10 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` > 27) and (`test`.`t3`.`f1` > 27)) # ICP should still be used. EXPLAIN SELECT f2 FROM (SELECT /*+ NO_ICP(t3 f1_idx, f2_idx) */ f2, f3, f1 FROM t3 WHERE f1 > 27 AND f3 = 'poiu') AS TD WHERE TD.f1 > 27 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 135 NULL 10 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` > 27) and (`test`.`t3`.`f1` > 27)) # 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 9 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) Warnings: Note 1003 update `test`.`t3` set `test`.`t3`.`f3` = 'mnbv' where ((`test`.`t3`.`f1` > 30) and (`test`.`t3`.`f1` < 33) and ((`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`),(/* select#2 */ select 1,1,1 from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`f1` = `test`.`t2`.`f1`) and (`test`.`t2`.`f2` between `test`.`t2`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t2`.`f1` + 1)) and ((`test`.`t3`.`f1`) = `test`.`t2`.`f1`) and ((`test`.`t3`.`f2`) = `test`.`t2`.`f2`) and ((`test`.`t3`.`f3`) = `test`.`t2`.`f3`))))) # 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 Warnings: Note 1003 update /*+ BKA(`t2`@`select#2`) NO_BNL(`t1`@`select#2`) NO_RANGE_OPTIMIZATION(`t3`@`select#1` `PRIMARY`) */ `test`.`t3` set `test`.`t3`.`f3` = 'mnbv' where ((`test`.`t3`.`f1` > 30) and (`test`.`t3`.`f1` < 33) and ((`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`),(/* select#2 */ select 1,1,1 from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`f1` = `test`.`t2`.`f1`) and (`test`.`t2`.`f2` between `test`.`t2`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t2`.`f1` + 1)) and ((`test`.`t3`.`f1`) = `test`.`t2`.`f1`) and ((`test`.`t3`.`f2`) = `test`.`t2`.`f2`) and ((`test`.`t3`.`f3`) = `test`.`t2`.`f3`))))) 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) Warnings: Note 1003 delete from `test`.`t3` where ((`test`.`t3`.`f1` > 30) and (`test`.`t3`.`f1` < 33) and ((`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`),(/* select#2 */ select /*+ QB_NAME(`qb1`) */ 1,1,1 from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`f1` = `test`.`t2`.`f1`) and (`test`.`t2`.`f2` between `test`.`t2`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t2`.`f1` + 1)) and ((`test`.`t3`.`f1`) = `test`.`t2`.`f1`) and ((`test`.`t3`.`f2`) = `test`.`t2`.`f2`) and ((`test`.`t3`.`f3`) = `test`.`t2`.`f3`))))) # 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 Warnings: Note 1003 delete /*+ NO_BNL(`t1`@`qb1`) NO_RANGE_OPTIMIZATION(`t3`@`select#1` `PRIMARY`) NO_RANGE_OPTIMIZATION(`t3`@`select#1` `f2_idx`) */ from `test`.`t3` where ((`test`.`t3`.`f1` > 30) and (`test`.`t3`.`f1` < 33) and ((`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`),(/* select#2 */ select /*+ QB_NAME(`qb1`) */ 1,1,1 from `test`.`t1` join `test`.`t2` where ((`test`.`t1`.`f1` = `test`.`t2`.`f1`) and (`test`.`t2`.`f2` between `test`.`t2`.`f1` and `test`.`t1`.`f2`) and ((`test`.`t2`.`f2` + 1) >= (`test`.`t2`.`f1` + 1)) and ((`test`.`t3`.`f1`) = `test`.`t2`.`f1`) and ((`test`.`t3`.`f2`) = `test`.`t2`.`f2`) and ((`test`.`t3`.`f3`) = `test`.`t2`.`f3`))))) 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 Warnings: Note 1003 insert into `test`.`t3` (`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`) /* 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))) # 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 Warnings: Note 1003 insert /*+ NO_ICP(`t2`@`select#1`) */ into `test`.`t3` (`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`) /* 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))) # 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 Warnings: Note 1003 insert /*+ NO_ICP(`t2`@`qb1` `f1`) */ into `test`.`t3` (`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`) /* 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))) 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 Warnings: Note 1003 replace into `test`.`t3` (`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`) /* 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))) # 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 Warnings: Note 1003 replace /*+ NO_ICP(`t2`@`select#1`) */ into `test`.`t3` (`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`) /* 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))) # 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 Note 1003 replace into `test`.`t3` (`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`) /* select#1 */ select /*+ QB_NAME(`qb2`) */ `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))) # 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 Warnings: Note 1003 replace /*+ NO_ICP(`t2`@`qb1`) */ into `test`.`t3` (`test`.`t3`.`f1`,`test`.`t3`.`f2`,`test`.`t3`.`f3`) /* 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))) # 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 135 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"; 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 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 NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 .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` join `test`.`t2` semi join (`test`.`t3` join `test`.`t1` `t4`) where ((`test`.`t2`.`a` = ``.`b`) and (`test`.`t1`.`b` = ``.`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 NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 .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` join `test`.`t2` semi join (`test`.`t3` join `test`.`t1` `t4`) where ((`test`.`t2`.`a` = ``.`b`) and (`test`.`t1`.`b` = ``.`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 NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 .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` join `test`.`t2` semi join (`test`.`t3` join `test`.`t1` `t4`) where ((`test`.`t2`.`a` = ``.`b`) and (`test`.`t1`.`b` = ``.`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 NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 .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` join `test`.`t2` semi join (`test`.`t3` join `test`.`t1` `t4`) where ((`test`.`t2`.`a` = ``.`b`) and (`test`.`t1`.`b` = ``.`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 NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 .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` join `test`.`t2` semi join (`test`.`t3` join `test`.`t1` `t4`) where ((`test`.`t2`.`a` = ``.`b`) and (`test`.`t1`.`b` = ``.`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 NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 .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` join `test`.`t2` semi join (`test`.`t3` join `test`.`t1` `t4`) where ((`test`.`t2`.`a` = ``.`b`) and (`test`.`t1`.`b` = ``.`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 NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 .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` join `test`.`t2` semi join (`test`.`t3` join `test`.`t1` `t4`) where ((`test`.`t2`.`a` = ``.`b`) and (`test`.`t1`.`b` = ``.`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 NULL ALL NULL NULL NULL NULL NULL 100.00 Using where 1 SIMPLE t2 NULL ref a a 5 .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` join `test`.`t2` semi join (`test`.`t3` join `test`.`t1` `t4`) where ((`test`.`t2`.`a` = ``.`b`) and (`test`.`t1`.`b` = ``.`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 6 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(true) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(true)) on(true) where true 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(true) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(true)) on(true) where true 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(true) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(true)) on(true) where true 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(true) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(true)) on(true) where true 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(true) left join (`test`.`t` `t3` left join `test`.`t` `t4` on(true)) on(true) where true 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(true) left join `test`.`t` `t4` on(true)) on(true) where true 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(true) join `test`.`t` `t4`) on((true)) where true 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(true) join `test`.`t` `t4`) on((true)) where true 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(true) join `test`.`t` `t4`) on((true)) where true 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(true) join `test`.`t` `t4`) on((true)) where true 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(true) join `test`.`t` `t4`) on((true)) where true 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(true) join `test`.`t` `t4`) on((true)) where true 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(true) join `test`.`t` `t4`) on((true)) where true 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(true) join `test`.`t` `t4`) on((true)) where true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 true 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 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 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 Note 1003 insert into `test`.`t1` values (10,10) 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 Note 1003 replace into `test`.`t1` values (10,10) 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 Note 1003 update `test`.`t1` set `test`.`t1`.`i` = 10 where (`test`.`t1`.`j` = 10) 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 Note 1003 delete from `test`.`t1` where (`test`.`t1`.`i` = 10) # 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'; 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; Warnings: Warning 3719 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. 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; # # WL#9307 MERGE/NO_MERGE hint for derived table, view # create table t1(a int); explain select * from (select * from t1) as dt; 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 `test`.`t1`.`a` AS `a` from `test`.`t1` explain select /*+ merge(dt) */ * from (select * from t1) as dt; 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 /*+ MERGE(`dt`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` explain select /*+ no_merge(dt) */ * from (select * from t1) as dt; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(`dt`@`select#1`) */ `dt`.`a` AS `a` from (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` # Also testing that case of letters is irrelevant. explain select /*+ no_mERge(dt) */ * from (select * from t1) as dt; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(`dt`@`select#1`) */ `dt`.`a` AS `a` from (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` create view v1 as (select * from t1); explain select * from v1; 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 `test`.`t1`.`a` AS `a` from `test`.`t1` explain select /*+ merge(v1) */ * from v1; 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 /*+ MERGE(`v1`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` explain select /*+ no_merge(v1) */ * from v1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(`v1`@`select#1`) */ `v1`.`a` AS `a` from `test`.`v1` drop view v1; # hint is OVERRIDDEN by algorithm= create algorithm=merge view v1 as (select * from t1); explain select * from v1; 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 `test`.`t1`.`a` AS `a` from `test`.`t1` explain select /*+ merge(v1) */ * from v1; 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 /*+ MERGE(`v1`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` explain select /*+ no_merge(v1) */ * from v1; 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 /*+ NO_MERGE(`v1`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` drop view v1; create algorithm=temptable view v1 as (select * from t1); explain select * from v1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `v1`.`a` AS `a` from `test`.`v1` explain select /*+ merge(v1) */ * from v1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ MERGE(`v1`@`select#1`) */ `v1`.`a` AS `a` from `test`.`v1` explain select /*+ no_merge(v1) */ * from v1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(`v1`@`select#1`) */ `v1`.`a` AS `a` from `test`.`v1` drop view v1; # hint OVERRIDES optimizer_switch set optimizer_switch="derived_merge=off"; explain select * from (select * from t1) as dt; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `dt`.`a` AS `a` from (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` explain select /*+ merge(dt) */ * from (select * from t1) as dt; 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 /*+ MERGE(`dt`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` explain select /*+ no_merge(dt) */ * from (select * from t1) as dt; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(`dt`@`select#1`) */ `dt`.`a` AS `a` from (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` create view v1 as (select * from t1); explain select * from v1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `v1`.`a` AS `a` from `test`.`v1` explain select /*+ merge(v1) */ * from v1; 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 /*+ MERGE(`v1`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` explain select /*+ no_merge(v1) */ * from v1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(`v1`@`select#1`) */ `v1`.`a` AS `a` from `test`.`v1` drop view v1; set optimizer_switch=default; # Can apply to certain derived tables create table t2(a int, b int); create table t3 like t2; explain select /*+ no_merge(dt) merge(dt2) */ * from (select * from t1) as dt, (select * from t2) as dt2; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(`dt`@`select#1`) MERGE(`dt2`@`select#1`) */ `dt`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` join `test`.`t2` # Or to all: explain select /*+ no_merge() */ * from (select * from t1) as dt, (select * from t2) as dt2; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 3 DERIVED t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(@`select#1`) */ `dt`.`a` AS `a`,`dt2`.`a` AS `a`,`dt2`.`b` AS `b` from (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` join (/* select#3 */ select `test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b` from `test`.`t2`) `dt2` # And be specified in outer blocks, with naming: explain select /*+ no_merge(dt@qb1) merge(dt2@qb1) */ * from t1 where a = (select /*+ qb_name(qb1) */ 3 from (select * from t1) as dt, (select * from t2) as dt2); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 2 SUBQUERY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 2 SUBQUERY NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 3 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(`dt`@`qb1`) MERGE(`dt2`@`qb1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = (/* select#2 */ select /*+ QB_NAME(`qb1`) */ 3 from (/* select#3 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` join `test`.`t2`)) # with another syntax: explain select /*+ no_merge(@qb1 dt) merge(@qb1 dt2) */ * from t1 where a = (select /*+ qb_name(qb1) */ 3 from (select * from t1) as dt, (select * from t2) as dt2); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 2 SUBQUERY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 2 SUBQUERY NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 3 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ NO_MERGE(`dt`@`qb1`) MERGE(`dt2`@`qb1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = (/* select#2 */ select /*+ QB_NAME(`qb1`) */ 3 from (/* select#3 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` join `test`.`t2`)) # A hint can list more than one table explain select /*+ merge(dt2) no_merge(dt,dt3) */ * from (select * from t1) as dt, (select * from t2) as dt2, (select * from t3) as dt3; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 Using join buffer (Block Nested Loop) 4 DERIVED t3 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select /*+ MERGE(`dt2`@`select#1`) NO_MERGE(`dt`@`select#1`) NO_MERGE(`dt3`@`select#1`) */ `dt`.`a` AS `a`,`test`.`t2`.`a` AS `a`,`test`.`t2`.`b` AS `b`,`dt3`.`a` AS `a`,`dt3`.`b` AS `b` from (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` join `test`.`t2` join (/* select#4 */ select `test`.`t3`.`a` AS `a`,`test`.`t3`.`b` AS `b` from `test`.`t3`) `dt3` # Merge hint OVERRIDES heuristics, for example the one which # materializes when user variables are set. explain select * from ( select * from t1 where (1,a,2) = ( select @n:=@n+1, t2.a, sum(t2.b) from (select @n:=1) as dt, t2 group by t2.a ) ) as dt2 ; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 3 UNCACHEABLE SUBQUERY NULL system NULL NULL NULL NULL 1 100.00 Using temporary 3 UNCACHEABLE SUBQUERY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Warning 1287 Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'. Warning 1287 Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'. Note 1003 /* select#1 */ select `dt2`.`a` AS `a` from (/* select#2 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((1,`test`.`t1`.`a`,2) = (/* select#3 */ select (@n:=((@`n`) + 1)),`test`.`t2`.`a`,sum(`test`.`t2`.`b`) from `test`.`t2` group by `test`.`t2`.`a`))) `dt2` explain select /*+ merge(dt2) */ * from ( select * from t1 where (1,a,2) = ( select @n:=@n+1, t2.a, sum(t2.b) from (select @n:=1) as dt, t2 group by t2.a ) ) as dt2 ; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t1 NULL ALL NULL NULL NULL NULL 1 100.00 Using where 3 UNCACHEABLE SUBQUERY NULL system NULL NULL NULL NULL 1 100.00 Using temporary 3 UNCACHEABLE SUBQUERY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 4 DERIVED NULL NULL NULL NULL NULL NULL NULL NULL NULL No tables used Warnings: Warning 1287 Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'. Warning 1287 Setting user variables within expressions is deprecated and will be removed in a future release. Consider alternatives: 'SET variable=expression, ...', or 'SELECT expression(s) INTO variables(s)'. Note 1003 /* select#1 */ select /*+ MERGE(`dt2`@`select#1`) */ `test`.`t1`.`a` AS `a` from `test`.`t1` where ((1,`test`.`t1`.`a`,2) = (/* select#3 */ select (@n:=((@`n`) + 1)),`test`.`t2`.`a`,sum(`test`.`t2`.`b`) from `test`.`t2` group by `test`.`t2`.`a`)) # ALGORITHM clause overrides heuristics too create view v1 as select (select t1.a from t1 where t1.a=t2.a) from t2; explain select * from v1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 NULL 2 DERIVED t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 3 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 1 100.00 Using where Warnings: Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #2 Note 1003 /* select#1 */ select `v1`.`(select t1.a from t1 where t1.a=t2.a)` AS `(select t1.a from t1 where t1.a=t2.a)` from `test`.`v1` drop view v1; create algorithm=merge view v1 as select (select t1.a from t1 where t1.a=t2.a) from t2; explain select * from v1; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 PRIMARY t2 NULL ALL NULL NULL NULL NULL 1 100.00 NULL 3 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 1 100.00 Using where Warnings: Note 1276 Field or reference 'test.t2.a' of SELECT #3 was resolved in SELECT #2 Note 1003 /* select#1 */ select (/* select#3 */ select `test`.`t1`.`a` from `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`a`)) AS `(select t1.a from t1 where t1.a=t2.a)` from `test`.`t2` drop view v1; # Hint for index is useless and should be ignored select /*+ no_mrr(dt idx1) */ * from (select 1 from t1 limit 1) dt; 1 Warnings: Warning 3128 Unresolved name `dt`@`select#1` `idx1` for NO_MRR hint select /*+ no_mrr(dt idx1) */ * from (select 1 from t1) dt; 1 Warnings: Warning 3128 Unresolved name `dt`@`select#1` `idx1` for NO_MRR hint # Hint for UPDATE insert into t1 values(1),(2); create view v1 as select * from t1 where a <> 0; delete from t3; insert into t3 values(1,1),(2,2); explain update t3, v1 set t3.a=v1.a+10 where t3.a-v1.a=0; 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 50.00 Using where 1 UPDATE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1003 update `test`.`t3` join `test`.`t1` set `test`.`t3`.`a` = (`test`.`t1`.`a` + 10) where (((`test`.`t3`.`a` - `test`.`t1`.`a`) = 0) and (`test`.`t1`.`a` <> 0)) update t3, v1 set t3.a=v1.a+10 where t3.a-v1.a=0; select * from t3; a b 11 1 12 2 delete from t3; insert into t3 values(1,1),(2,2); explain update /*+ no_merge(v1) */ t3, v1 set t3.a=v1.a+10 where t3.a-v1.a=0; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t3 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 Using where 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 2 50.00 Using where Warnings: Note 1003 update /*+ NO_MERGE(`v1`@`select#1`) */ `test`.`t3` join `test`.`v1` set `test`.`t3`.`a` = (`v1`.`a` + 10) where ((`test`.`t3`.`a` - `v1`.`a`) = 0) update /*+ no_merge(v1) */ t3, v1 set t3.a=v1.a+10 where t3.a-v1.a=0; select * from t3; a b 11 1 12 2 # Update v1 delete from t3; insert into t3 values(1,1),(2,2); delete from t1; insert into t1 values(1),(2); explain update t3, v1 set v1.a=t3.a+10 where t3.a-v1.a=0; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t1 NULL ALL NULL NULL NULL NULL 2 50.00 Using where 1 SIMPLE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1003 update `test`.`t3` join `test`.`t1` set `test`.`t1`.`a` = (`test`.`t3`.`a` + 10) where (((`test`.`t3`.`a` - `test`.`t1`.`a`) = 0) and (`test`.`t1`.`a` <> 0)) update t3, v1 set v1.a=t3.a+10 where t3.a-v1.a=0; select * from t1; a 11 12 delete from t1; insert into t1 values(1),(2); update /*+ no_merge(v1) */ t3, v1 set v1.a=t3.a+10 where t3.a-v1.a=0; ERROR HY000: The target table v1 of the UPDATE is not updatable select * from t1; a 1 2 # A derived table in UPDATE delete from t1; insert into t1 values(1),(2); delete from t3; insert into t3 values(1,1),(2,2); explain update t3, (select * from t1) dt set t3.a=dt.a+10 where t3.a-dt.a=0; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t3 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1003 update `test`.`t3` join `test`.`t1` set `test`.`t3`.`a` = (`test`.`t1`.`a` + 10) where ((`test`.`t3`.`a` - `test`.`t1`.`a`) = 0) update t3, (select * from t1) dt set t3.a=dt.a+10 where t3.a-dt.a=0; select * from t3; a b 11 1 12 2 delete from t3; insert into t3 values(1,1),(2,2); explain update /*+ no_merge(dt) */ t3, (select * from t1) dt set t3.a=dt.a+10 where t3.a-dt.a=0; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t3 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 Using where 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 2 100.00 NULL Warnings: Note 1003 update /*+ NO_MERGE(`dt`@`select#1`) */ `test`.`t3` join (/* select#2 */ select straight_join `test`.`t1`.`a` AS `a` from `test`.`t1`) `dt` set `test`.`t3`.`a` = (`dt`.`a` + 10) where ((`test`.`t3`.`a` - `dt`.`a`) = 0) update /*+ no_merge(dt) */ t3, (select * from t1) dt set t3.a=dt.a+10 where t3.a-dt.a=0; select * from t3; a b 11 1 12 2 # A derived table in first-level subquery of UPDATE, the update # target not being in the derived table. Before the WL, the # derived table would always be materialized; now it's only # heuristic and can be overridden. delete from t1; insert into t1 values(1),(2); delete from t3; insert into t3 values(1,1),(2,2); explain update t3 set b=NULL where a in (select /*+ qb_name(sub) */ a from (select * from t1 where a>1) dt); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using where 2 DEPENDENT SUBQUERY NULL index_subquery 5 func 2 100.00 Using index 3 DERIVED t1 NULL ALL NULL NULL NULL NULL 2 50.00 Using where Warnings: Note 1003 update `test`.`t3` set `test`.`t3`.`b` = NULL where (`test`.`t3`.`a`,(((`test`.`t3`.`a`) in dt on ))) update t3 set b=NULL where a in (select /*+ qb_name(sub) */ a from (select * from t1 where a>1) dt); select * from t3; a b 1 1 2 NULL delete from t3; insert into t3 values(1,1),(2,2); explain update /*+ merge(dt@sub) */ t3 set b=NULL where a in (select /*+ qb_name(sub) */ a from (select * from t1 where a>1) dt); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using where 2 DEPENDENT SUBQUERY t1 NULL ALL NULL NULL NULL NULL 2 50.00 Using where Warnings: Note 1003 update /*+ MERGE(`dt`@`sub`) */ `test`.`t3` set `test`.`t3`.`b` = NULL where (`test`.`t3`.`a`,(/* select#2 */ select /*+ QB_NAME(`sub`) */ 1 from `test`.`t1` where (((`test`.`t3`.`a`) = `test`.`t1`.`a`) and (`test`.`t1`.`a` > 1)))) update /*+ merge(dt@sub) */ t3 set b=NULL where a in (select /*+ qb_name(sub) */ a from (select * from t1 where a>1) dt); select * from t3; a b 1 1 2 NULL # A derived table in UPDATE, the update target being in the # derived table. delete from t3; insert into t3 values(1,1),(2,2); explain update t3 set b=NULL where a in (select /*+ qb_name(sub) */ a from (select * from t3 where b>1) dt); id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 UPDATE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using where 2 DEPENDENT SUBQUERY NULL index_subquery 5 func 2 100.00 NULL 3 DERIVED t3 NULL ALL NULL NULL NULL NULL 2 50.00 Using where Warnings: Note 1003 update `test`.`t3` set `test`.`t3`.`b` = NULL where (`test`.`t3`.`a`,(((`test`.`t3`.`a`) in dt on ))) update t3 set b=NULL where a in (select /*+ qb_name(sub) */ a from (select * from t3 where b>1) dt); select * from t3; a b 1 1 2 NULL delete from t3; insert into t3 values(1,1),(2,2); # The heuristic which materializes, intends to allow the query; # if you disable it, the query cannot run: update /*+ merge(dt@sub) */ t3 set b=NULL where a in (select /*+ qb_name(sub) */ a from (select * from t3 where b>1) dt); ERROR HY000: You can't specify target table 't3' for update in FROM clause select * from t3; a b 1 1 2 2 # DELETE. delete from t3; insert into t3 values(1,1),(2,2); explain delete t3.* from t3, v1 where t3.a-v1.a=0; 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 50.00 Using where 1 DELETE t3 NULL ALL NULL NULL NULL NULL 2 100.00 Using where Warnings: Note 1003 delete `test`.`t3` from `test`.`t3` join `test`.`t1` where (((`test`.`t3`.`a` - `test`.`t1`.`a`) = 0) and (`test`.`t1`.`a` <> 0)) delete t3.* from t3, v1 where t3.a-v1.a=0; select * from t3; a b delete from t3; insert into t3 values(1,1),(2,2); explain delete /*+ no_merge(v1) */ t3.* from t3, v1 where t3.a-v1.a=0; id select_type table partitions type possible_keys key key_len ref rows filtered Extra 1 DELETE t3 NULL ALL NULL NULL NULL NULL 2 100.00 NULL 1 PRIMARY NULL ALL NULL NULL NULL NULL 2 100.00 Using where 2 DERIVED t1 NULL ALL NULL NULL NULL NULL 2 50.00 Using where Warnings: Note 1003 delete /*+ NO_MERGE(`v1`@`select#1`) */ `test`.`t3` from `test`.`t3` join `test`.`v1` where ((`test`.`t3`.`a` - `v1`.`a`) = 0) delete /*+ no_merge(v1) */ t3.* from t3, v1 where t3.a-v1.a=0; select * from t3; a b drop view v1; drop table t1,t2,t3; # # 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