~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/subselect_mat.result

  • Committer: Monty Taylor
  • Date: 2009-04-14 19:16:51 UTC
  • mto: (997.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 994.
  • Revision ID: mordred@inaugust.com-20090414191651-ltbww6hpqks8k7qk
Clarified instructions in README.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
drop table if exists t1, t2, t3, t1i, t2i, t3i;
2
 
create table t1 (a1 char(8), a2 char(8));
3
 
create temporary table t2 (b1 char(8), b2 char(8)) ENGINE=MyISAM;
4
 
create table t3 (c1 char(8), c2 char(8));
 
2
create table t1 (a1 char(8), a2 char(8)) ENGINE=MyISAM;
 
3
create table t2 (b1 char(8), b2 char(8)) ENGINE=MyISAM;
 
4
create table t3 (c1 char(8), c2 char(8)) ENGINE=MyISAM;
5
5
insert into t1 values ('1 - 00', '2 - 00');
6
6
insert into t1 values ('1 - 01', '2 - 01');
7
7
insert into t1 values ('1 - 02', '2 - 02');
14
14
insert into t3 values ('1 - 02', '2 - 02');
15
15
insert into t3 values ('1 - 03', '2 - 03');
16
16
insert into t3 values ('1 - 04', '2 - 04');
17
 
create temporary table t1i (a1 char(8), a2 char(8)) ENGINE=MyISAM;
18
 
create table t2i (b1 char(8), b2 char(8));
19
 
create temporary table t3i (c1 char(8), c2 char(8)) ENGINE=MyISAM;
 
17
create table t1i (a1 char(8), a2 char(8)) ENGINE=MyISAM;
 
18
create table t2i (b1 char(8), b2 char(8)) ENGINE=MyISAM;
 
19
create table t3i (c1 char(8), c2 char(8)) ENGINE=MyISAM;
20
20
create index it1i1 on t1i (a1);
21
21
create index it1i2 on t1i (a2);
22
22
create index it1i3 on t1i (a1, a2);
29
29
insert into t1i select * from t1;
30
30
insert into t2i select * from t2;
31
31
insert into t3i select * from t3;
32
 
/********************************************************************
 
32
set @@optimizer_switch=no_semijoin;
 
33
/******************************************************************************
33
34
* Simple tests.
34
 
********************************************************************/
 
35
******************************************************************************/
35
36
# non-indexed nullable fields
36
37
explain extended
37
38
select * from t1 where a1 in (select b1 from t2 where b1 > '0');
38
39
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
39
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
40
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
 
40
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
41
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where
41
42
Warnings:
42
43
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (select `test`.`t2`.`b1` AS `b1` from `test`.`t2` where (`test`.`t2`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key)))
43
44
select * from t1 where a1 in (select b1 from t2 where b1 > '0');
47
48
explain extended
48
49
select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
49
50
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
50
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
51
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where; Using temporary; Using filesort
 
51
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
52
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where; Using temporary; Using filesort
52
53
Warnings:
53
54
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>(`test`.`t1`.`a1`,`test`.`t1`.`a1` in ( <materialize> (select `test`.`t2`.`b1` AS `b1` from `test`.`t2` where (`test`.`t2`.`b1` > '0') group by `test`.`t2`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key)))
54
55
select * from t1 where a1 in (select b1 from t2 where b1 > '0' group by b1);
58
59
explain extended
59
60
select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2);
60
61
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
61
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
62
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where; Using temporary; Using filesort
 
62
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
63
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where; Using temporary; Using filesort
63
64
Warnings:
64
65
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where (`test`.`t2`.`b1` > '0') group by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key)))
65
66
select * from t1 where (a1, a2) in (select b1, b2 from t2 where b1 > '0' group by b1, b2);
69
70
explain extended
70
71
select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
71
72
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
72
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
73
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where; Using temporary; Using filesort
 
73
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
74
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where; Using temporary; Using filesort
74
75
Warnings:
75
76
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,min(`test`.`t2`.`b2`) AS `min(b2)` from `test`.`t2` where (`test`.`t2`.`b1` > '0') group by `test`.`t2`.`b1` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key)))
76
77
select * from t1 where (a1, a2) in (select b1, min(b2) from t2 where b1 > '0' group by b1);
80
81
explain extended
81
82
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
82
83
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
83
 
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    #       100.00  Using where; Using index
84
 
2       SUBQUERY        t2i     index   it2i1,it2i3     it2i1   35      NULL    #       40.00   Using where; Using index
 
84
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    3       100.00  Using where; Using index
 
85
2       SUBQUERY        t2i     index   it2i1,it2i3     it2i1   35      NULL    5       100.00  Using where; Using index
85
86
Warnings:
86
87
Note    1003    select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (select `test`.`t2i`.`b1` AS `b1` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key)))
87
88
select * from t1i where a1 in (select b1 from t2i where b1 > '0');
91
92
explain extended
92
93
select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
93
94
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
94
 
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    #       100.00  Using where; Using index
95
 
2       SUBQUERY        t2i     range   it2i1,it2i3     it2i1   35      NULL    #       100.00  Using where; Using index for group-by
 
95
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    3       100.00  Using where; Using index
 
96
2       SUBQUERY        t2i     range   it2i1,it2i3     it2i1   35      NULL    3       100.00  Using where; Using index for group-by
96
97
Warnings:
97
98
Note    1003    select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>(`test`.`t1i`.`a1`,`test`.`t1i`.`a1` in ( <materialize> (select `test`.`t2i`.`b1` AS `b1` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key)))
98
99
select * from t1i where a1 in (select b1 from t2i where b1 > '0' group by b1);
102
103
explain extended
103
104
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
104
105
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
105
 
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    #       100.00  Using where; Using index
106
 
2       SUBQUERY        t2i     index   it2i1,it2i3     it2i3   70      NULL    #       40.00   Using where; Using index
 
106
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    3       100.00  Using where; Using index
 
107
2       SUBQUERY        t2i     index   it2i1,it2i3     it2i3   70      NULL    5       100.00  Using where; Using index
107
108
Warnings:
108
109
Note    1003    select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key)))
109
110
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0');
113
114
explain extended
114
115
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
115
116
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
116
 
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    #       100.00  Using where; Using index
117
 
2       SUBQUERY        t2i     range   it2i1,it2i3     it2i3   70      NULL    #       100.00  Using where; Using index for group-by
 
117
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    3       100.00  Using where; Using index
 
118
2       SUBQUERY        t2i     range   it2i1,it2i3     it2i3   70      NULL    3       100.00  Using where; Using index for group-by
118
119
Warnings:
119
120
Note    1003    select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1`,`test`.`t2i`.`b2` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key)))
120
121
select * from t1i where (a1, a2) in (select b1, b2 from t2i where b1 > '0' group by b1, b2);
124
125
explain extended
125
126
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
126
127
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
127
 
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    #       100.00  Using where; Using index
128
 
2       SUBQUERY        t2i     range   it2i1,it2i3     it2i3   70      NULL    #       100.00  Using where; Using index for group-by
 
128
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    3       100.00  Using where; Using index
 
129
2       SUBQUERY        t2i     range   it2i1,it2i3     it2i3   70      NULL    3       100.00  Using where; Using index for group-by
129
130
Warnings:
130
131
Note    1003    select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,min(`test`.`t2i`.`b2`) AS `min(b2)` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') group by `test`.`t2i`.`b1` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key)))
131
132
select * from t1i where (a1, a2) in (select b1, min(b2) from t2i where b1 > '0' group by b1);
135
136
explain extended
136
137
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
137
138
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
138
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
139
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  
 
139
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
140
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    5       100.00  
140
141
Warnings:
141
142
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` order by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key)))
142
143
select * from t1 where (a1, a2) in (select b1, b2 from t2 order by b1, b2);
146
147
explain extended
147
148
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
148
149
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
149
 
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    #       100.00  Using where; Using index
150
 
2       SUBQUERY        t2i     index   NULL    it2i3   70      NULL    #       100.00  Using index
 
150
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    3       100.00  Using where; Using index
 
151
2       SUBQUERY        t2i     index   NULL    it2i3   70      NULL    5       100.00  Using index
151
152
Warnings:
152
153
Note    1003    select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` order by `test`.`t2i`.`b1`,`test`.`t2i`.`b2` ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key)))
153
154
select * from t1i where (a1, a2) in (select b1, b2 from t2i order by b1, b2);
160
161
(a1, a2) in (select c1, c2 from t3
161
162
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
162
163
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
163
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
164
 
3       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
165
 
4       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    #       40.00   Using where; Using index
166
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
 
164
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
165
3       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
166
4       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    5       100.00  Using where; Using index
 
167
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where
167
168
Warnings:
168
169
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where (`test`.`t2`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key))))
169
170
select * from t1
179
180
(a1, a2) in (select c1, c2 from t3i
180
181
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
181
182
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
182
 
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    #       100.00  Using where; Using index
183
 
3       SUBQUERY        t3i     index   NULL    it3i3   70      NULL    #       100.00  Using where; Using index
184
 
4       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    #       40.00   Using where; Using index
185
 
2       SUBQUERY        t2i     index   it2i1,it2i3     it2i3   70      NULL    #       40.00   Using where; Using index
 
183
1       PRIMARY t1i     index   NULL    it1i3   70      NULL    3       100.00  Using where; Using index
 
184
3       SUBQUERY        t3i     index   NULL    it3i3   70      NULL    4       100.00  Using where; Using index
 
185
4       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    5       100.00  Using where; Using index
 
186
2       SUBQUERY        t2i     index   it2i1,it2i3     it2i3   70      NULL    5       100.00  Using where; Using index
186
187
Warnings:
187
188
Note    1003    select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where (<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key))) and <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t3i`.`c1` AS `c1`,`test`.`t3i`.`c2` AS `c2` from `test`.`t3i` where <in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key))))
188
189
select * from t1i
200
201
(a1, a2) in (select c1, c2 from t3
201
202
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
202
203
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
203
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
204
 
5       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
205
 
6       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    #       40.00   Using where; Using index
206
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
207
 
4       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
208
 
3       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
 
204
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
205
5       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
206
6       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    5       100.00  Using where; Using index
 
207
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where
 
208
4       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
209
3       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
209
210
Warnings:
210
211
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key)))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key))))
211
212
select * from t1
224
225
(a1, a2) in (select c1, c2 from t3 t3c
225
226
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
226
227
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
227
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
228
 
5       SUBQUERY        t3c     ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
229
 
6       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    #       40.00   Using where; Using index
230
 
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
231
 
4       SUBQUERY        t3b     ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
232
 
3       DEPENDENT SUBQUERY      t3a     ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
 
228
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
229
5       SUBQUERY        t3c     ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
230
6       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    5       100.00  Using where; Using index
 
231
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where
 
232
4       SUBQUERY        t3b     ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
233
3       DEPENDENT SUBQUERY      t3a     ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
233
234
Warnings:
234
235
Note    1276    Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1
235
236
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where ((<in_optimizer>(`test`.`t2`.`b2`,<exists>(select 1 AS `Not_used` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`)))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` AS `c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key)))) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3c`.`c1` AS `c1`,`test`.`t3c`.`c2` AS `c2` from `test`.`t3` `t3c` where <in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),(`test`.`t3c`.`c1`,`test`.`t3c`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3c`.`c1` in <temporary table> on distinct_key))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key))))
256
257
(a1, a2) in (select c1, c2 from t3i
257
258
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')));
258
259
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
259
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
260
 
5       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
261
 
6       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    #       40.00   Using where; Using index
262
 
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where; Using temporary; Using filesort
263
 
4       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
264
 
3       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
265
 
7       UNION   t1i     index   NULL    it1i3   70      NULL    #       100.00  Using where; Using index
266
 
9       SUBQUERY        t3i     index   NULL    it3i3   70      NULL    #       100.00  Using where; Using index
267
 
10      SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    #       40.00   Using where; Using index
268
 
8       SUBQUERY        t2i     index   it2i1,it2i3     it2i3   70      NULL    #       40.00   Using where; Using index
269
 
NULL    UNION RESULT    <union1,7>      ALL     NULL    NULL    NULL    NULL    #       NULL    
 
260
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
261
5       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
262
6       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    5       100.00  Using where; Using index
 
263
2       SUBQUERY        t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where; Using temporary; Using filesort
 
264
4       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
265
3       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
266
7       UNION   t1i     index   NULL    it1i3   70      NULL    3       100.00  Using where; Using index
 
267
9       SUBQUERY        t3i     index   NULL    it3i3   70      NULL    4       100.00  Using where; Using index
 
268
10      SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    5       100.00  Using where; Using index
 
269
8       SUBQUERY        t2i     index   it2i1,it2i3     it2i3   70      NULL    5       100.00  Using where; Using index
 
270
NULL    UNION RESULT    <union1,7>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
270
271
Warnings:
271
272
Note    1003    (select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where (<in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%02') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3`.`c2` AS `c2` from `test`.`t3` where (`test`.`t3`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key)))) group by `test`.`t2`.`b1`,`test`.`t2`.`b2` ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key))))) union (select `test`.`t1i`.`a1` AS `a1`,`test`.`t1i`.`a2` AS `a2` from `test`.`t1i` where (<in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b1` > '0') ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key))) and <in_optimizer>((`test`.`t1i`.`a1`,`test`.`t1i`.`a2`),(`test`.`t1i`.`a1`,`test`.`t1i`.`a2`) in ( <materialize> (select `test`.`t3i`.`c1` AS `c1`,`test`.`t3i`.`c2` AS `c2` from `test`.`t3i` where <in_optimizer>((`test`.`t3i`.`c1`,`test`.`t3i`.`c2`),(`test`.`t3i`.`c1`,`test`.`t3i`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3i`.`c1` in <temporary table> on distinct_key))) ), <primary_index_lookup>(`test`.`t1i`.`a1` in <temporary table> on distinct_key)))))
272
273
(select * from t1
290
291
(a1, a2) in (select c1, c2 from t3
291
292
where (c1, c2) in (select b1, b2 from t2i where b2 > '0'));
292
293
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
293
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
294
 
4       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
295
 
5       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    #       40.00   Using where; Using index
296
 
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
297
 
3       DEPENDENT UNION t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
298
 
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    #       NULL    
 
294
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
295
4       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
296
5       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    5       100.00  Using where; Using index
 
297
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
298
3       DEPENDENT UNION t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where
 
299
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
299
300
Warnings:
300
301
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),(`test`.`t1`.`a1`,`test`.`t1`.`a2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key))) ), <primary_index_lookup>(`test`.`t1`.`a1` in <temporary table> on distinct_key))))
301
302
select * from t1
312
313
where (c1, c2) in (select b1, b2 from t2i where b2 > '0')) and
313
314
a1 = c1;
314
315
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
315
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
316
 
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where; Using join buffer
317
 
4       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
318
 
5       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    #       40.00   Using where; Using index
319
 
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
320
 
3       DEPENDENT UNION t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
321
 
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    #       NULL    
 
316
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
317
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where; Using join buffer
 
318
4       SUBQUERY        t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
319
5       SUBQUERY        t2i     index   it2i2   it2i3   70      NULL    5       100.00  Using where; Using index
 
320
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
321
3       DEPENDENT UNION t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where
 
322
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
322
323
Warnings:
323
324
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2`,`test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t1` join `test`.`t3` where ((`test`.`t3`.`c1` = `test`.`t1`.`a1`) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t1`.`a1`) = `test`.`t1`.`a1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t1`.`a2`)) union select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>((`test`.`t3`.`c1`,`test`.`t3`.`c2`),(`test`.`t3`.`c1`,`test`.`t3`.`c2`) in ( <materialize> (select `test`.`t2i`.`b1` AS `b1`,`test`.`t2i`.`b2` AS `b2` from `test`.`t2i` where (`test`.`t2i`.`b2` > '0') ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key))) ), <primary_index_lookup>(`test`.`t3`.`c1` in <temporary table> on distinct_key))))
324
325
select * from t1, t3
329
330
a1      a2      c1      c2
330
331
1 - 01  2 - 01  1 - 01  2 - 01
331
332
1 - 02  2 - 02  1 - 02  2 - 02
332
 
/*********************************************************************
 
333
/******************************************************************************
333
334
* Negative tests, where materialization should not be applied.
334
 
**********************************************************************/
 
335
******************************************************************************/
335
336
# UNION in a subquery
336
337
explain extended
337
338
select * from t3
338
339
where c1 in (select a1 from t1 where a1 > '0' UNION select b1 from t2 where b1 < '9');
339
340
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
340
 
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
341
 
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
342
 
3       DEPENDENT UNION t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
343
 
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    #       NULL    
 
341
1       PRIMARY t3      ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
342
2       DEPENDENT SUBQUERY      t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
343
3       DEPENDENT UNION t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where
 
344
NULL    UNION RESULT    <union2,3>      ALL     NULL    NULL    NULL    NULL    NULL    NULL    
344
345
Warnings:
345
346
Note    1003    select `test`.`t3`.`c1` AS `c1`,`test`.`t3`.`c2` AS `c2` from `test`.`t3` where <in_optimizer>(`test`.`t3`.`c1`,<exists>(select 1 AS `Not_used` from `test`.`t1` where ((`test`.`t1`.`a1` > '0') and (<cache>(`test`.`t3`.`c1`) = `test`.`t1`.`a1`)) union select 1 AS `Not_used` from `test`.`t2` where ((`test`.`t2`.`b1` < '9') and (<cache>(`test`.`t3`.`c1`) = `test`.`t2`.`b1`))))
346
347
select * from t3
357
358
(a1, a2) in (select c1, c2 from t3 t3c
358
359
where (c1, c2) in (select b1, b2 from t2i where b2 > '0' or b2 = a2));
359
360
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
360
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
361
 
5       DEPENDENT SUBQUERY      t3c     ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
362
 
6       DEPENDENT SUBQUERY      t2i     index_subquery  it2i1,it2i2,it2i3       it2i3   70      func,func       #       100.00  Using index; Using where
363
 
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
364
 
4       SUBQUERY        t3b     ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
365
 
3       DEPENDENT SUBQUERY      t3a     ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
 
361
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
362
5       DEPENDENT SUBQUERY      t3c     ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
363
6       DEPENDENT SUBQUERY      t2i     index_subquery  it2i1,it2i2,it2i3       it2i3   70      func,func       2       100.00  Using index; Using where
 
364
2       DEPENDENT SUBQUERY      t2      ALL     NULL    NULL    NULL    NULL    5       100.00  Using where
 
365
4       SUBQUERY        t3b     ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
 
366
3       DEPENDENT SUBQUERY      t3a     ALL     NULL    NULL    NULL    NULL    4       100.00  Using where
366
367
Warnings:
367
368
Note    1276    Field or reference 'test.t1.a1' of SELECT #3 was resolved in SELECT #1
368
369
Note    1276    Field or reference 'test.t1.a2' of SELECT #6 was resolved in SELECT #1
369
370
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where (<in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t2`.`b1` AS `b1`,`test`.`t2`.`b2` AS `b2` from `test`.`t2` where ((<in_optimizer>(`test`.`t2`.`b2`,<exists>(select 1 AS `Not_used` from `test`.`t3` `t3a` where ((`test`.`t3a`.`c1` = `test`.`t1`.`a1`) and (<cache>(`test`.`t2`.`b2`) = `test`.`t3a`.`c2`)))) or <in_optimizer>(`test`.`t2`.`b2`,`test`.`t2`.`b2` in ( <materialize> (select `test`.`t3b`.`c2` AS `c2` from `test`.`t3` `t3b` where (`test`.`t3b`.`c2` like '%03') ), <primary_index_lookup>(`test`.`t2`.`b2` in <temporary table> on distinct_key)))) and (<cache>(`test`.`t1`.`a1`) = `test`.`t2`.`b1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t2`.`b2`)))) and <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select `test`.`t3c`.`c1` AS `c1`,`test`.`t3c`.`c2` AS `c2` from `test`.`t3` `t3c` where (<in_optimizer>((`test`.`t3c`.`c1`,`test`.`t3c`.`c2`),<exists>(<index_lookup>(<cache>(`test`.`t3c`.`c1`) in t2i on it2i3 where (((`test`.`t2i`.`b2` > '0') or (`test`.`t2i`.`b2` = `test`.`t1`.`a2`)) and (<cache>(`test`.`t3c`.`c1`) = `test`.`t2i`.`b1`) and (<cache>(`test`.`t3c`.`c2`) = `test`.`t2i`.`b2`))))) and (<cache>(`test`.`t1`.`a1`) = `test`.`t3c`.`c1`) and (<cache>(`test`.`t1`.`a2`) = `test`.`t3c`.`c2`)))))
370
 
DROP TABLE t1i, t2i, t3i;
371
371
explain extended
372
372
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
373
373
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
374
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using where
375
 
2       DEPENDENT SUBQUERY      NULL    NULL    NULL    NULL    NULL    NULL    #       NULL    No tables used
 
374
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using where
 
375
2       DEPENDENT SUBQUERY      NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
376
376
Warnings:
377
377
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` where <in_optimizer>((`test`.`t1`.`a1`,`test`.`t1`.`a2`),<exists>(select '1 - 01' AS `1 - 01`,'2 - 01' AS `2 - 01` having ((<cache>(`test`.`t1`.`a1`) = '1 - 01') and (<cache>(`test`.`t1`.`a2`) = '2 - 01'))))
378
378
select * from t1 where (a1, a2) in (select '1 - 01', '2 - 01');
388
388
0
389
389
0
390
390
/* GROUP BY clause */
391
 
create temporary table columns (col int key) ENGINE=MyISAM;
 
391
create table columns (col int key) ENGINE=MyISAM;
392
392
insert into columns values (1), (2);
393
393
explain extended
394
394
select * from t1 group by (select col from columns limit 1);
395
395
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
396
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  
397
 
2       SUBQUERY        columns index   NULL    PRIMARY 4       NULL    #       100.00  Using index
 
396
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  
 
397
2       SUBQUERY        columns index   NULL    PRIMARY 4       NULL    2       100.00  Using index
398
398
Warnings:
399
399
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by (select `test`.`columns`.`col` AS `col` from `test`.`columns` limit 1)
400
400
select * from t1 group by (select col from columns limit 1);
403
403
explain extended
404
404
select * from t1 group by (a1 in (select col from columns));
405
405
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
406
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  Using temporary; Using filesort
407
 
2       DEPENDENT SUBQUERY      columns unique_subquery PRIMARY PRIMARY 4       func    #       100.00  Using index; Using where; Full scan on NULL key
 
406
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  Using temporary; Using filesort
 
407
2       DEPENDENT SUBQUERY      columns unique_subquery PRIMARY PRIMARY 4       func    1       100.00  Using index; Using where; Full scan on NULL key
408
408
Warnings:
409
409
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` group by <in_optimizer>(`test`.`t1`.`a1`,<exists>(<primary_index_lookup>(<cache>(`test`.`t1`.`a1`) in columns on PRIMARY where trigcond((<cache>(`test`.`t1`.`a1`) = `test`.`columns`.`col`)))))
410
410
select * from t1 group by (a1 in (select col from columns));
414
414
explain extended
415
415
select * from t1 order by (select col from columns limit 1);
416
416
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
417
 
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    #       100.00  
418
 
2       SUBQUERY        columns index   NULL    PRIMARY 4       NULL    #       100.00  Using index
 
417
1       PRIMARY t1      ALL     NULL    NULL    NULL    NULL    3       100.00  
 
418
2       SUBQUERY        columns index   NULL    PRIMARY 4       NULL    2       100.00  Using index
419
419
Warnings:
420
420
Note    1003    select `test`.`t1`.`a1` AS `a1`,`test`.`t1`.`a2` AS `a2` from `test`.`t1` order by (select `test`.`columns`.`col` AS `col` from `test`.`columns` limit 1)
421
421
select * from t1 order by (select col from columns limit 1);
423
423
1 - 00  2 - 00
424
424
1 - 01  2 - 01
425
425
1 - 02  2 - 02
426
 
DROP TABLE columns;
427
426
/******************************************************************************
428
427
* Column types/sizes that affect materialization.
429
428
******************************************************************************/
431
430
Test that BLOBs are not materialized (except when arguments of some functions).
432
431
*/
433
432
# force materialization to be always considered
 
433
set @@optimizer_switch=no_semijoin;
434
434
set @prefix_len = 6;
435
435
set @blob_len = 16;
436
436
set @suffix_len = @blob_len - @prefix_len;
437
 
create temporary table t1_16 (a1 blob, a2 blob) ENGINE=MyISAM;
438
 
create temporary table t2_16 (b1 blob, b2 blob) ENGINE=MyISAM;
439
 
create temporary table t3_16 (c1 blob, c2 blob) ENGINE=MyISAM;
 
437
create table t1_16 (a1 blob, a2 blob) ENGINE=MyISAM;
 
438
create table t2_16 (b1 blob, b2 blob) ENGINE=MyISAM;
 
439
create table t3_16 (c1 blob, c2 blob) ENGINE=MyISAM;
440
440
insert into t1_16 values
441
441
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
442
442
insert into t1_16 values
547
547
drop table t1_16, t2_16, t3_16;
548
548
set @blob_len = 512;
549
549
set @suffix_len = @blob_len - @prefix_len;
550
 
create temporary table t1_512 (a1 blob, a2 blob) ENGINE=MyISAM;
551
 
create temporary table t2_512 (b1 blob, b2 blob) ENGINE=MyISAM;
552
 
create temporary table t3_512 (c1 blob, c2 blob) ENGINE=MyISAM;
 
550
create table t1_512 (a1 blob, a2 blob) ENGINE=MyISAM;
 
551
create table t2_512 (b1 blob, b2 blob) ENGINE=MyISAM;
 
552
create table t3_512 (c1 blob, c2 blob) ENGINE=MyISAM;
553
553
insert into t1_512 values
554
554
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
555
555
insert into t1_512 values
644
644
drop table t1_512, t2_512, t3_512;
645
645
set @blob_len = 1024;
646
646
set @suffix_len = @blob_len - @prefix_len;
647
 
create temporary table t1_1024 (a1 blob, a2 blob) ENGINE=MyISAM;
648
 
create temporary table t2_1024 (b1 blob, b2 blob) ENGINE=MyISAM;
649
 
create temporary table t3_1024 (c1 blob, c2 blob) ENGINE=MyISAM;
 
647
create table t1_1024 (a1 blob, a2 blob) ENGINE=MyISAM;
 
648
create table t2_1024 (b1 blob, b2 blob) ENGINE=MyISAM;
 
649
create table t3_1024 (c1 blob, c2 blob) ENGINE=MyISAM;
650
650
insert into t1_1024 values
651
651
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
652
652
insert into t1_1024 values
741
741
drop table t1_1024, t2_1024, t3_1024;
742
742
set @blob_len = 1025;
743
743
set @suffix_len = @blob_len - @prefix_len;
744
 
create temporary table t1_1025 (a1 blob, a2 blob) ENGINE=MyISAM;
745
 
create temporary table t2_1025 (b1 blob, b2 blob) ENGINE=MyISAM;
746
 
create temporary table t3_1025 (c1 blob, c2 blob) ENGINE=MyISAM;
 
744
create table t1_1025 (a1 blob, a2 blob) ENGINE=MyISAM;
 
745
create table t2_1025 (b1 blob, b2 blob) ENGINE=MyISAM;
 
746
create table t3_1025 (c1 blob, c2 blob) ENGINE=MyISAM;
747
747
insert into t1_1025 values
748
748
(concat('1 - 00', repeat('x', @suffix_len)), concat('2 - 00', repeat('x', @suffix_len)));
749
749
insert into t1_1025 values
840
840
/******************************************************************************
841
841
* Test the cache of the left operand of IN.
842
842
******************************************************************************/
843
 
# Test that default values of Cached_item are not used for comparison
844
 
create temporary table t1 (s1 int) ENGINE=MyISAM;
845
 
create temporary table t2 (s2 int) ENGINE=MyISAM;
 
843
set @@optimizer_switch=no_semijoin;
 
844
create table t1 (s1 int) ENGINE=MyISAM;
 
845
create table t2 (s2 int) ENGINE=MyISAM;
846
846
insert into t1 values (5),(1),(0);
847
847
insert into t2 values (0), (1);
848
848
select s2 from t2 where s2 in (select s1 from t1);
850
850
0
851
851
1
852
852
drop table t1, t2;
853
 
create temporary table t1 (a int not null, b int not null) ENGINE=MyISAM;
854
 
create temporary table t2 (c int not null, d int not null) ENGINE=MyISAM;
855
 
create temporary table t3 (e int not null) ENGINE=MyISAM;
 
853
create table t1 (a int not null, b int not null) ENGINE=MyISAM;
 
854
create table t2 (c int not null, d int not null) ENGINE=MyISAM;
 
855
create table t3 (e int not null) ENGINE=MyISAM;
856
856
insert into t1 values (1,10);
857
857
insert into t1 values (1,20);
858
858
insert into t1 values (2,10);