1
by brian
clean slate |
1 |
drop table if exists t0, t1, t2, t10, t11, t12;
|
2 |
create table t0 (a int);
|
|
3 |
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
|
4 |
create table t1(a int, b int);
|
|
5 |
insert into t1 values (0,0),(1,1),(2,2);
|
|
6 |
create table t2 as select * from t1;
|
|
7 |
create table t11(a int, b int);
|
|
8 |
create table t10 (pk int, a int, primary key(pk));
|
|
9 |
insert into t10 select a,a from t0;
|
|
10 |
create table t12 like t10;
|
|
11 |
insert into t12 select * from t10;
|
|
12 |
Flattened because of dependency, t10=func(t1)
|
|
13 |
explain select * from t1 where a in (select pk from t10);
|
|
14 |
id select_type table type possible_keys key key_len ref rows Extra
|
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
15 |
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
|
16 |
2 SUBQUERY t10 index NULL PRIMARY 4 NULL 10 Using index
|
|
1
by brian
clean slate |
17 |
select * from t1 where a in (select pk from t10);
|
18 |
a b
|
|
19 |
0 0
|
|
20 |
1 1
|
|
21 |
2 2
|
|
22 |
A confluent case of dependency
|
|
23 |
explain select * from t1 where a in (select a from t10 where pk=12);
|
|
24 |
id select_type table type possible_keys key key_len ref rows Extra
|
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
25 |
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
|
26 |
2 SUBQUERY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables
|
|
1
by brian
clean slate |
27 |
select * from t1 where a in (select a from t10 where pk=12);
|
28 |
a b
|
|
29 |
An empty table inside
|
|
30 |
explain select * from t1 where a in (select a from t11);
|
|
31 |
id select_type table type possible_keys key key_len ref rows Extra
|
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
32 |
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
|
33 |
2 SUBQUERY t11 ALL NULL NULL NULL NULL 1
|
|
1
by brian
clean slate |
34 |
select * from t1 where a in (select a from t11);
|
35 |
a b
|
|
36 |
explain select * from t1 where a in (select pk from t10) and b in (select pk from t10);
|
|
37 |
id select_type table type possible_keys key key_len ref rows Extra
|
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
38 |
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
|
39 |
3 SUBQUERY t10 index NULL PRIMARY 4 NULL 10 Using index
|
|
40 |
2 SUBQUERY t10 index NULL PRIMARY 4 NULL 10 Using index
|
|
1
by brian
clean slate |
41 |
select * from t1 where a in (select pk from t10) and b in (select pk from t10);
|
42 |
a b
|
|
43 |
0 0
|
|
44 |
1 1
|
|
45 |
2 2
|
|
46 |
flattening a nested subquery
|
|
47 |
explain select * from t1 where a in (select pk from t10 where t10.a in (select pk from t12));
|
|
48 |
id select_type table type possible_keys key key_len ref rows Extra
|
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
49 |
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where
|
50 |
2 SUBQUERY t10 ALL NULL NULL NULL NULL 10 Using where
|
|
51 |
3 SUBQUERY t12 index NULL PRIMARY 4 NULL 10 Using index
|
|
1
by brian
clean slate |
52 |
select * from t1 where a in (select pk from t10 where t10.a in (select pk from t12));
|
53 |
a b
|
|
54 |
0 0
|
|
55 |
1 1
|
|
56 |
2 2
|
|
57 |
flattening subquery w/ several tables
|
|
58 |
explain extended select * from t1 where a in (select t10.pk from t10, t12 where t12.pk=t10.a);
|
|
59 |
id select_type table type possible_keys key key_len ref rows filtered Extra
|
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
60 |
1 PRIMARY t1 ALL NULL NULL NULL NULL 3 100.00 Using where
|
61 |
2 SUBQUERY t10 ALL NULL NULL NULL NULL 10 100.00
|
|
62 |
2 SUBQUERY t12 eq_ref PRIMARY PRIMARY 4 test.t10.a 1 100.00 Using index
|
|
1
by brian
clean slate |
63 |
Warnings:
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
64 |
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t10`.`pk` AS `pk` from `test`.`t10` join `test`.`t12` where (`test`.`t12`.`pk` = `test`.`t10`.`a`) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key)))
|
1
by brian
clean slate |
65 |
subqueries within outer joins go into ON expr.
|
814.1.5
by Jay Pipes
Fixes crash in optimizer where LEFT JOIN was mixing with a subselect. |
66 |
select * from
|
67 |
t1 left join t2 on (t2.a= t1.a and t2.a in (select pk from t10))
|
|
68 |
where t1.a < 5;
|
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
69 |
a b a b
|
70 |
0 0 0 0
|
|
71 |
1 1 1 1
|
|
72 |
2 2 2 2
|
|
2141.4.2
by Andrew Hutchings
Implicit joins of the form "SELECT * FROM t1, t2" without WHERE or ON now error. |
73 |
insert into t1 select (A.a + 10 * B.a),1 from t0 A CROSS JOIN t0 B;
|
1
by brian
clean slate |
74 |
explain extended select * from t1 where a in (select pk from t10 where pk<3);
|
75 |
id select_type table type possible_keys key key_len ref rows filtered Extra
|
|
76 |
1 PRIMARY t1 ALL NULL NULL NULL NULL 103 100.00 Using where
|
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
77 |
2 SUBQUERY t10 range PRIMARY PRIMARY 4 NULL 3 100.00 Using where; Using index
|
1
by brian
clean slate |
78 |
Warnings:
|
1100.2.1
by Brian Aker
First pass through removing most of the semi_join code. |
79 |
Note 1003 select `test`.`t1`.`a` AS `a`,`test`.`t1`.`b` AS `b` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a`,`test`.`t1`.`a` in ( <materialize> (select `test`.`t10`.`pk` AS `pk` from `test`.`t10` where (`test`.`t10`.`pk` < 3) ), <primary_index_lookup>(`test`.`t1`.`a` in <temporary table> on distinct_key)))
|
1
by brian
clean slate |
80 |
drop table t0, t1;
|
81 |
drop table t10, t11, t12;
|
|
1119.4.12
by Stewart Smith
make subselect_sj test not leave tables behind |
82 |
drop table t2;
|