1 PRIMARY t12 eq_ref PRIMARY PRIMARY 4 test.t10.a 1 100.00 Using index
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t12` join `test`.`t1` where ((`test`.`t10`.`pk` = `test`.`t1`.`a`) and (`test`.`t12`.`pk` = `test`.`t10`.`a`))
subqueries within outer joins go into ON expr.
explAin extended
select * from t1 left join (t2 A, t2 B) on ( A.A= t1.A And B.A in (select pk from t10));
id select_type tABle type possiBle_keys key key_len ref rows filtered ExtrA
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY A ALL NULL NULL NULL NULL 3 100.00 Using where; Using join Buffer
1 PRIMARY B ALL NULL NULL NULL NULL 3 100.00 Using where; Using join Buffer
2 DEPENDENT SUBQUERY t10 unique_suBquery PRIMARY PRIMARY 4 func 1 100.00 Using index
Warnings:
Note 1003 select `test`.`t1`.`A` AS `A`,`test`.`t1`.`B` AS `B`,`test`.`A`.`A` AS `A`,`test`.`A`.`B` AS `B`,`test`.`B`.`A` AS `A`,`test`.`B`.`B` AS `B` from `test`.`t1` left join (`test`.`t2` `A` join `test`.`t2` `B`) on(((`test`.`A`.`A` = `test`.`t1`.`A`) And <in_optimizer>(`test`.`B`.`A`,<exists>(<primAry_index_lookup>(<cAche>(`test`.`B`.`A`) in t10 on PRIMARY))))) where 1
t2 should be wrapped into OJ-nest, so we have "t1 LJ (t2 J t10)"
explAin extended
select * from t1 left join t2 on (t2.A= t1.A And t2.A in (select pk from t10));
id select_type tABle type possiBle_keys key key_len ref rows filtered ExtrA
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00
1 PRIMARY t2 ALL NULL NULL NULL NULL 3 100.00 Using where; Using join Buffer
2 DEPENDENT SUBQUERY t10 unique_suBquery PRIMARY PRIMARY 4 func 1 100.00 Using index
Warnings:
Note 1003 select `test`.`t1`.`A` AS `A`,`test`.`t1`.`B` AS `B`,`test`.`t2`.`A` AS `A`,`test`.`t2`.`B` AS `B` from `test`.`t1` left join `test`.`t2` on(((`test`.`t2`.`A` = `test`.`t1`.`A`) And <in_optimizer>(`test`.`t2`.`A`,<exists>(<primAry_index_lookup>(<cAche>(`test`.`t2`.`A`) in t10 on PRIMARY))))) where 1
we shouldn't flatten if we're going to get a join of > MAX_TABLES.
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY s00 ALL NULL NULL NULL NULL 3 Using where
1 PRIMARY s01 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s02 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s03 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s04 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s05 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s06 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s07 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s08 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s09 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s10 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s11 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s12 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s13 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s14 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s15 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s16 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s17 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s18 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s19 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s20 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s21 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s22 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s23 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s24 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s25 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s26 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s27 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s28 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s29 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s30 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s31 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s32 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s33 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s34 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s35 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s36 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s37 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s38 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s39 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s40 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s41 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s42 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s43 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s44 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s45 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s46 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s47 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s48 ALL NULL NULL NULL NULL 3 Using join buffer
1 PRIMARY s49 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m00 ALL NULL NULL NULL NULL 3 Using where
2 DEPENDENT SUBQUERY m01 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m02 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m03 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m04 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m05 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m06 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m07 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m08 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m09 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m10 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m11 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m12 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m13 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m14 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m15 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m16 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m17 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m18 ALL NULL NULL NULL NULL 3 Using join buffer
2 DEPENDENT SUBQUERY m19 ALL NULL NULL NULL NULL 3 Using where; Using join buffer
select * from
t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
where t1.a < 5;
a b a b
0 0 0 0
1 1 1 1
2 2 2 2
prepare s1 from
' select * from
t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
where t1.a < 5';
execute s1;
a b a b
0 0 0 0
1 1 1 1
2 2 2 2
execute s1;
a b a b
0 0 0 0
1 1 1 1
2 2 2 2
insert into t1 select (A.a + 10 * B.a),1 from t0 A, t0 B;
explain extended select * from t1 where a in (select pk from t10 where pk<3);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t10 range PRIMARY PRIMARY 4 NULL 4 100.00 Using where; Using index
1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where; Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t10` join `test`.`t1` where ((`test`.`t1`.`a` = `test`.`t10`.`pk`) and (`test`.`t10`.`pk` < 3))
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select 1 from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))))
Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t1`.`a` = `test`.`t2`.`c`) and <nop>(<in_optimizer>(`test`.`t2`.`d`,<exists>(select 1 from `test`.`t3` where ((`test`.`t1`.`b` = `test`.`t3`.`e`) and (<cache>(`test`.`t2`.`d`) >= `test`.`t3`.`e`))))))
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (a, b) IN (SELECT a, b FROM t2 WHERE pk > 0);
pk
2
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, c) IN (SELECT b, c FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Using MRR; FirstMatch(t1); Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`c` = `test`.`t1`.`c`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (b, c) IN (SELECT b, c FROM t2 WHERE pk > 0);
pk
1
2
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, d) IN (SELECT b, d FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Using MRR; FirstMatch(t1); Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`d` = `test`.`t1`.`d`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (b, d) IN (SELECT b, d FROM t2 WHERE pk > 0);
pk
2
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, e) IN (SELECT b, e FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Using MRR; FirstMatch(t1); Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`e` = `test`.`t1`.`e`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (b, e) IN (SELECT b, e FROM t2 WHERE pk > 0);
pk
1
2
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, f) IN (SELECT b, f FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Using MRR; FirstMatch(t1); Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`f` = `test`.`t1`.`f`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (b, f) IN (SELECT b, f FROM t2 WHERE pk > 0);
pk
1
2
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, g) IN (SELECT b, g FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Using MRR; FirstMatch(t1); Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`g` = `test`.`t1`.`g`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (b, g) IN (SELECT b, g FROM t2 WHERE pk > 0);
pk
1
2
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, h) IN (SELECT b, h FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Using MRR; FirstMatch(t1); Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`h` = `test`.`t1`.`h`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (b, h) IN (SELECT b, h FROM t2 WHERE pk > 0);
pk
1
2
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, i) IN (SELECT b, i FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Using MRR; FirstMatch(t1); Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`i` = `test`.`t1`.`i`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (b, i) IN (SELECT b, i FROM t2 WHERE pk > 0);
pk
1
2
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, j) IN (SELECT b, j FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Using MRR; FirstMatch(t1); Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`j` = `test`.`t1`.`j`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (b, j) IN (SELECT b, j FROM t2 WHERE pk > 0);
pk
1
2
EXPLAIN EXTENDED SELECT pk FROM t1 WHERE (b, k) IN (SELECT b, k FROM t2 WHERE pk > 0);
id select_type table type possible_keys key key_len ref rows filtered Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY t2 range PRIMARY PRIMARY 4 NULL 2 100.00 Using index condition; Using where; Using MRR; FirstMatch(t1); Using join buffer
Warnings:
Note 1003 select `test`.`t1`.`pk` AS `pk` from `test`.`t1` semi join (`test`.`t2`) where ((`test`.`t2`.`k` = `test`.`t1`.`k`) and (`test`.`t2`.`b` = `test`.`t1`.`b`) and (`test`.`t2`.`pk` > 0))
SELECT pk FROM t1 WHERE (b, k) IN (SELECT b, k FROM t2 WHERE pk > 0);
# result on a query with a materialized semi-join.
#
CREATE TABLE `t1` (
`pk` int(11) NOT NULL AUTO_INCREMENT,
`varchar_key` varchar(1) NOT NULL,
`varchar_nokey` varchar(1) NOT NULL,
PRIMARY KEY (`pk`),
KEY `varchar_key` (`varchar_key`)
);
INSERT INTO `t1` VALUES (11,'m','m'),(12,'j','j'),(13,'z','z'),(14,'a','a'),(15,'',''),(16,'e','e'),(17,'t','t'),(19,'b','b'),(20,'w','w'),(21,'m','m'),(23,'',''),(24,'w','w'),(26,'e','e'),(27,'e','e'),(28,'p','p');
CREATE TABLE `t2` (
`varchar_nokey` varchar(1) NOT NULL
);
INSERT INTO `t2` VALUES ('v'),('u'),('n'),('l'),('h'),('u'),('n'),('j'),('k'),('e'),('i'),('u'),('n'),('b'),('x'),(''),('q'),('u');
EXPLAIN EXTENDED SELECT varchar_nokey
FROM t2
WHERE ( `varchar_nokey` , `varchar_nokey` ) IN (
SELECT `varchar_key` , `varchar_nokey`
FROM t1
WHERE `varchar_nokey` < 'n' XOR `pk` ) ;
id select_type table type possible_keys key key_len ref rows filtered Extra