1
1
drop table if exists t1,t2;
2
create temporary table t1 (a int, b int not null,unique key (a,b),index(b)) engine=myisam;
2
create 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
72
72
select * from t1 where a > 8 and a < 9;
74
74
create table t2 like t1;
75
ERROR HY000: Can't create table 'test.t2' (errno: 138)
76
create temporary table t2 like t1;
79
t2 CREATE TEMPORARY TABLE `t2` (
82
UNIQUE KEY `a` (`a`,`b`),
85
75
insert into t2 select * from t1;
86
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));
87
77
explain select * from t1 where a is null and b = 2;
88
78
id select_type table type possible_keys key key_len ref rows Extra
89
1 SIMPLE t1 ref a,b a 5 const X Using where
79
1 SIMPLE t1 ref a,b a 5 const 3 Using where
90
80
explain select * from t1 where a is null and b = 2 and c=0;
91
81
id select_type table type possible_keys key key_len ref rows Extra
92
1 SIMPLE t1 ref a,b a 5 const X Using where
82
1 SIMPLE t1 ref a,b a 5 const 3 Using where
93
83
explain select * from t1 where a is null and b = 7 and c=0;
94
84
id select_type table type possible_keys key key_len ref rows Extra
95
1 SIMPLE t1 ref a,b a 5 const X Using where
85
1 SIMPLE t1 ref a,b a 5 const 3 Using where
96
86
explain select * from t1 where a=2 and b = 2;
97
87
id select_type table type possible_keys key key_len ref rows Extra
98
1 SIMPLE t1 ref a,b a 5 const X Using where
88
1 SIMPLE t1 ref a,b a 5 const 1 Using where
99
89
explain select * from t1 where a<=>b limit 2;
100
90
id select_type table type possible_keys key key_len ref rows Extra
101
1 SIMPLE t1 ALL NULL NULL NULL NULL X Using where
91
1 SIMPLE t1 ALL NULL NULL NULL NULL 12 Using where
102
92
explain select * from t1 where (a is null or a > 0 and a < 3) and b < 5 and c=0 limit 3;
103
93
id select_type table type possible_keys key key_len ref rows Extra
104
1 SIMPLE t1 range a,b a 5 NULL X Using where
94
1 SIMPLE t1 range a,b a 5 NULL 5 Using where
105
95
explain select * from t1 where (a is null or a = 7) and b=7 and c=0;
106
96
id select_type table type possible_keys key key_len ref rows Extra
107
1 SIMPLE t1 ref_or_null a,b a 5 const X Using where
97
1 SIMPLE t1 ref_or_null a,b a 5 const 4 Using where
108
98
explain select * from t1 where (a is null and b>a) or a is null and b=7 limit 2;
109
99
id select_type table type possible_keys key key_len ref rows Extra
110
1 SIMPLE t1 ref a,b a 5 const X Using where
100
1 SIMPLE t1 ref a,b a 5 const 3 Using where
111
101
explain select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
112
102
id select_type table type possible_keys key key_len ref rows Extra
113
1 SIMPLE t1 ref a,b a 5 const X Using where
103
1 SIMPLE t1 ref a,b a 5 const 3 Using where
114
104
explain select * from t1 where a > 1 and a < 3 limit 1;
115
105
id select_type table type possible_keys key key_len ref rows Extra
116
1 SIMPLE t1 range a a 5 NULL X Using where
106
1 SIMPLE t1 range a a 5 NULL 1 Using where
117
107
explain select * from t1 where a is null and b=7 or a > 1 and a < 3 limit 1;
118
108
id select_type table type possible_keys key key_len ref rows Extra
119
1 SIMPLE t1 range a,b a 5 NULL X Using where
109
1 SIMPLE t1 range a,b a 5 NULL 4 Using where
120
110
explain select * from t1 where a > 8 and a < 9;
121
111
id select_type table type possible_keys key key_len ref rows Extra
122
1 SIMPLE t1 range a a 5 NULL X Using where
112
1 SIMPLE t1 range a a 5 NULL 1 Using where
123
113
explain select * from t1 where b like "6%";
124
114
id select_type table type possible_keys key key_len ref rows Extra
125
1 SIMPLE t1 range b b 12 NULL X Using where
115
1 SIMPLE t1 range b b 12 NULL 1 Using where
126
116
select * from t1 where a is null;
165
154
1 SIMPLE t1 ref_or_null a,b a 10 const,const 2 Using index
166
155
select * from t1 where a = 7 and (b=7 or b is null);
169
159
explain select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
170
160
id select_type table type possible_keys key key_len ref rows Extra
171
1 SIMPLE t1 ref_or_null a,b a 5 const 2 Using where; Using index
161
1 SIMPLE t1 ref_or_null a,b a 5 const 4 Using where; Using index
172
162
select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
175
167
explain select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
176
168
id select_type table type possible_keys key key_len ref rows Extra
177
1 SIMPLE t1 ref_or_null a a 5 const 2 Using index
169
1 SIMPLE t1 ref_or_null a a 5 const 5 Using index
178
170
select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
181
177
create table t2 (a int);
182
178
insert into t2 values (7),(8);
183
179
explain select * from t2 straight_join t1 where t1.a=t2.a and b is null;
184
180
id select_type table type possible_keys key key_len ref rows Extra
185
1 SIMPLE t2 ALL NULL NULL NULL NULL X
186
1 SIMPLE t1 ref a,b b 5 const X Using where
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
187
183
drop index b on t1;
188
184
explain select * from t2,t1 where t1.a=t2.a and b is null;
189
185
id select_type table type possible_keys key key_len ref rows Extra
190
1 SIMPLE t2 ALL NULL NULL NULL NULL X
191
1 SIMPLE t1 ref a a 10 test.t2.a,const X Using where; Using index
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
192
188
select * from t2,t1 where t1.a=t2.a and b is null;
196
192
explain select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
197
193
id select_type table type possible_keys key key_len ref rows Extra
198
1 SIMPLE t2 ALL NULL NULL NULL NULL X
199
1 SIMPLE t1 ref_or_null a a 10 test.t2.a,const X Using index
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
200
196
select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
205
202
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
206
203
id select_type table type possible_keys key key_len ref rows Extra
207
1 SIMPLE t2 ALL NULL NULL NULL NULL X
208
1 SIMPLE t1 ref_or_null a a 10 test.t2.a,const X Using index
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
209
206
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
212
212
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
213
213
id select_type table type possible_keys key key_len ref rows Extra
214
1 SIMPLE t2 ALL NULL NULL NULL NULL X
215
1 SIMPLE t1 ref_or_null a a 5 test.t2.a X Using where; Using index
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
216
216
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
221
224
insert into t2 values (null),(6);
222
225
delete from t1 where a=8;
223
226
explain select * from t2,t1 where t1.a=t2.a or t1.a is null;
224
227
id select_type table type possible_keys key key_len ref rows Extra
225
1 SIMPLE t1 system a NULL NULL NULL X
226
1 SIMPLE t2 ALL NULL NULL NULL NULL X Using where
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
227
230
explain select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
228
231
id select_type table type possible_keys key key_len ref rows Extra
229
1 SIMPLE t1 system a NULL NULL NULL X
230
1 SIMPLE t2 ALL NULL NULL NULL NULL X Using where
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
231
234
select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
234
245
drop table t1,t2;
235
CREATE TEMPORARY TABLE t1 (
236
id int NOT NULL auto_increment,
237
uniq_id int default NULL,
247
id int(10) unsigned NOT NULL auto_increment,
248
uniq_id int(10) unsigned default NULL,
238
249
PRIMARY KEY (id),
239
250
UNIQUE KEY idx1 (uniq_id)
241
CREATE TEMPORARY TABLE t2 (
242
id int NOT NULL auto_increment,
243
uniq_id int default NULL,
253
id int(10) unsigned NOT NULL auto_increment,
254
uniq_id int(10) unsigned default NULL,
246
257
INSERT INTO t1 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
247
258
INSERT INTO t2 VALUES (1,NULL),(2,NULL),(3,1),(4,2),(5,NULL),(6,NULL),(7,3),(8,4),(9,NULL),(10,NULL);
248
259
explain select id from t1 where uniq_id is null;
249
260
id select_type table type possible_keys key key_len ref rows Extra
250
1 SIMPLE t1 ref idx1 idx1 5 const 5 Using where
261
1 SIMPLE t1 ref idx1 idx1 5 const 5 Using index condition
251
262
explain select id from t1 where uniq_id =1;
252
263
id select_type table type possible_keys key key_len ref rows Extra
253
264
1 SIMPLE t1 const idx1 idx1 5 const 1