1
1
drop table if exists t1,t2;
2
create table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
2
create temporary table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
3
3
insert ignore into t1 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(null,7),(9,9),(8,8),(7,7),(null,9),(null,9),(6,6);
4
4
explain select * from t1 where a is null;
5
5
id select_type table type possible_keys key key_len ref rows Extra
76
76
alter table t1 modify b blob not null, add c int not null, drop key a, add unique key (a,b(20),c), drop key b, add key (b(10));
77
77
explain select * from t1 where a is null and b = 2;
78
78
id select_type table type possible_keys key key_len ref rows Extra
79
1 SIMPLE t1 ref a,b a 5 const 3 Using where
79
1 SIMPLE t1 ref a,b a 5 const X Using where
80
80
explain select * from t1 where a is null and b = 2 and c=0;
81
81
id select_type table type possible_keys key key_len ref rows Extra
82
1 SIMPLE t1 ref a,b a 5 const 3 Using where
82
1 SIMPLE t1 ref a,b a 5 const X Using where
83
83
explain select * from t1 where a is null and b = 7 and c=0;
84
84
id select_type table type possible_keys key key_len ref rows Extra
85
1 SIMPLE t1 ref a,b a 5 const 3 Using where
85
1 SIMPLE t1 ref a,b a 5 const X Using where
86
86
explain select * from t1 where a=2 and b = 2;
87
87
id select_type table type possible_keys key key_len ref rows Extra
88
1 SIMPLE t1 ref a,b a 5 const 1 Using where
88
1 SIMPLE t1 ref a,b a 5 const X Using where
89
89
explain select * from t1 where a<=>b limit 2;
90
90
id select_type table type possible_keys key key_len ref rows Extra
91
1 SIMPLE t1 ALL NULL NULL NULL NULL 12 Using where
91
1 SIMPLE t1 ALL NULL NULL NULL NULL X Using where
92
92
explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 and c=0 limit 3;
93
93
id select_type table type possible_keys key key_len ref rows Extra
94
1 SIMPLE t1 range a,b a 5 NULL 5 Using where
94
1 SIMPLE t1 range a,b a 5 NULL X Using where
95
95
explain select * from t1 where (a is null or a = 7) and b=7 and c=0;
96
96
id select_type table type possible_keys key key_len ref rows Extra
97
1 SIMPLE t1 ref_or_null a,b a 5 const 4 Using where
97
1 SIMPLE t1 ref_or_null a,b a 5 const X Using where
98
98
explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
99
99
id select_type table type possible_keys key key_len ref rows Extra
100
1 SIMPLE t1 ref a,b a 5 const 3 Using where
100
1 SIMPLE t1 ref a,b a 5 const X Using where
101
101
explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
102
102
id select_type table type possible_keys key key_len ref rows Extra
103
1 SIMPLE t1 ref a,b a 5 const 3 Using where
103
1 SIMPLE t1 ref a,b a 5 const X Using where
104
104
explain select * from t1 where a > 1 and a < 3 limit 1;
105
105
id select_type table type possible_keys key key_len ref rows Extra
106
1 SIMPLE t1 range a a 5 NULL 1 Using where
106
1 SIMPLE t1 range a a 5 NULL X Using where
107
107
explain select * from t1 where a is null and b=7 or a > 1 and a < 3 limit 1;
108
108
id select_type table type possible_keys key key_len ref rows Extra
109
1 SIMPLE t1 range a,b a 5 NULL 4 Using where
109
1 SIMPLE t1 range a,b a 5 NULL X Using where
110
110
explain select * from t1 where a > 8 and a < 9;
111
111
id select_type table type possible_keys key key_len ref rows Extra
112
1 SIMPLE t1 range a a 5 NULL 1 Using where
112
1 SIMPLE t1 range a a 5 NULL X Using where
113
113
explain select * from t1 where b like "6%";
114
114
id select_type table type possible_keys key key_len ref rows Extra
115
1 SIMPLE t1 range b b 12 NULL 1 Using where
115
1 SIMPLE t1 range b b 12 NULL X Using where
116
116
select * from t1 where a is null;
154
155
1 SIMPLE t1 ref_or_null a,b a 10 const,const 2 Using index
155
156
select * from t1 where a = 7 and (b=7 or b is null);
159
159
explain select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
160
160
id select_type table type possible_keys key key_len ref rows Extra
161
1 SIMPLE t1 ref_or_null a,b a 5 const 4 Using where; Using index
161
1 SIMPLE t1 ref_or_null a,b a 5 const 2 Using where; Using index
162
162
select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
167
165
explain select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
168
166
id select_type table type possible_keys key key_len ref rows Extra
169
1 SIMPLE t1 ref_or_null a a 5 const 5 Using index
167
1 SIMPLE t1 ref_or_null a a 5 const 2 Using index
170
168
select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
177
171
create table t2 (a int);
178
172
insert into t2 values (7),(8);
179
173
explain select * from t2 straight_join t1 where t1.a=t2.a and b is null;
180
174
id select_type table type possible_keys key key_len ref rows Extra
181
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
182
1 SIMPLE t1 ref a,b a 10 test.t2.a,const 2 Using where; Using index
175
1 SIMPLE t2 ALL NULL NULL NULL NULL X
176
1 SIMPLE t1 ref a,b b 5 const X Using where
183
177
drop index b on t1;
184
178
explain select * from t2,t1 where t1.a=t2.a and b is null;
185
179
id select_type table type possible_keys key key_len ref rows Extra
186
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
187
1 SIMPLE t1 ref a a 10 test.t2.a,const 2 Using where; Using index
180
1 SIMPLE t2 ALL NULL NULL NULL NULL X
181
1 SIMPLE t1 ref a a 10 test.t2.a,const X Using where; Using index
188
182
select * from t2,t1 where t1.a=t2.a and b is null;
192
186
explain select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
193
187
id select_type table type possible_keys key key_len ref rows Extra
194
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
195
1 SIMPLE t1 ref_or_null a a 10 test.t2.a,const 4 Using index
188
1 SIMPLE t2 ALL NULL NULL NULL NULL X
189
1 SIMPLE t1 ref_or_null a a 10 test.t2.a,const X Using index
196
190
select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
202
195
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
203
196
id select_type table type possible_keys key key_len ref rows Extra
204
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
205
1 SIMPLE t1 ref_or_null a a 10 test.t2.a,const 4 Using index
197
1 SIMPLE t2 ALL NULL NULL NULL NULL X
198
1 SIMPLE t1 ref_or_null a a 10 test.t2.a,const X Using index
206
199
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
212
202
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
213
203
id select_type table type possible_keys key key_len ref rows Extra
214
1 SIMPLE t2 ALL NULL NULL NULL NULL 2
215
1 SIMPLE t1 ref_or_null a a 5 test.t2.a 4 Using where; Using index
204
1 SIMPLE t2 ALL NULL NULL NULL NULL X
205
1 SIMPLE t1 ref_or_null a a 5 test.t2.a X Using where; Using index
216
206
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
224
211
insert into t2 values (null),(6);
225
212
delete from t1 where a=8;
226
213
explain select * from t2,t1 where t1.a=t2.a or t1.a is null;
227
214
id select_type table type possible_keys key key_len ref rows Extra
228
1 SIMPLE t2 ALL NULL NULL NULL NULL 4
229
1 SIMPLE t1 ref_or_null a a 5 test.t2.a 4 Using index
215
1 SIMPLE t1 system a NULL NULL NULL X
216
1 SIMPLE t2 ALL NULL NULL NULL NULL X Using where
230
217
explain select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
231
218
id select_type table type possible_keys key key_len ref rows Extra
232
1 SIMPLE t2 ALL NULL NULL NULL NULL 4
233
1 SIMPLE t1 ref_or_null a a 5 test.t2.a 4 Using where; Using index
219
1 SIMPLE t1 system a NULL NULL NULL X
220
1 SIMPLE t2 ALL NULL NULL NULL NULL X Using where
234
221
select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
245
224
drop table t1,t2;
247
id int(10) unsigned NOT NULL auto_increment,
248
uniq_id int(10) unsigned default NULL,
225
CREATE TEMPORARY TABLE t1 (
226
id int NOT NULL auto_increment,
227
uniq_id int default NULL,
249
228
PRIMARY KEY (id),
250
229
UNIQUE KEY idx1 (uniq_id)
253
id int(10) unsigned NOT NULL auto_increment,
254
uniq_id int(10) unsigned default NULL,
231
CREATE TEMPORARY TABLE t2 (
232
id int NOT NULL auto_increment,
233
uniq_id int default NULL,
257
236
INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
258
237
INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
259
238
explain select id from t1 where uniq_id is null;
260
239
id select_type table type possible_keys key key_len ref rows Extra
261
1 SIMPLE t1 ref idx1 idx1 5 const 5 Using index condition
240
1 SIMPLE t1 ref idx1 idx1 5 const 5 Using where
262
241
explain select id from t1 where uniq_id =1;
263
242
id select_type table type possible_keys key key_len ref rows Extra
264
243
1 SIMPLE t1 const idx1 idx1 5 const 1