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 X Using where
79
1 SIMPLE t1 ref a,b a 5 const 3 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 X Using where
82
1 SIMPLE t1 ref a,b a 5 const 3 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 X Using where
85
1 SIMPLE t1 ref a,b a 5 const 3 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 X Using where
88
1 SIMPLE t1 ref a,b a 5 const 1 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 X Using where
91
1 SIMPLE t1 ALL NULL NULL NULL NULL 12 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 X Using where
94
1 SIMPLE t1 range a,b a 5 NULL 5 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 X Using where
97
1 SIMPLE t1 ref_or_null a,b a 5 const 4 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 X Using where
100
1 SIMPLE t1 ref a,b a 5 const 3 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 X Using where
103
1 SIMPLE t1 ref a,b a 5 const 3 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 X Using where
106
1 SIMPLE t1 range a a 5 NULL 1 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 X Using where
109
1 SIMPLE t1 range a,b a 5 NULL 4 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 X Using where
112
1 SIMPLE t1 range a a 5 NULL 1 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 X Using where
115
1 SIMPLE t1 range b b 12 NULL 1 Using where
116
116
select * from t1 where a is null;
155
154
1 SIMPLE t1 ref_or_null a,b a 10 const,const 2 Using index
156
155
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 2 Using where; Using index
161
1 SIMPLE t1 ref_or_null a,b a 5 const 4 Using where; Using index
162
162
select * from t1 where (a = 7 or a is null) and (b=7 or b is null);
165
167
explain select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
166
168
id select_type table type possible_keys key key_len ref rows Extra
167
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
168
170
select * from t1 where (a = 7 or a is null) and (a = 7 or a is null);
171
177
create table t2 (a int);
172
178
insert into t2 values (7),(8);
173
179
explain select * from t2 straight_join t1 where t1.a=t2.a and b is null;
174
180
id select_type table type possible_keys key key_len ref rows Extra
175
1 SIMPLE t2 ALL NULL NULL NULL NULL X
176
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
177
183
drop index b on t1;
178
184
explain select * from t2,t1 where t1.a=t2.a and b is null;
179
185
id select_type table type possible_keys key key_len ref rows Extra
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
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
182
188
select * from t2,t1 where t1.a=t2.a and b is null;
186
192
explain select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
187
193
id select_type table type possible_keys key key_len ref rows Extra
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
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
190
196
select * from t2,t1 where t1.a=t2.a and (b= 7 or b is null);
195
202
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
196
203
id select_type table type possible_keys key key_len ref rows Extra
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
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
199
206
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and b= 7;
202
212
explain select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
203
213
id select_type table type possible_keys key key_len ref rows Extra
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
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
206
216
select * from t2,t1 where (t1.a=t2.a or t1.a is null) and (b= 7 or b is null);
211
224
insert into t2 values (null),(6);
212
225
delete from t1 where a=8;
213
226
explain select * from t2,t1 where t1.a=t2.a or t1.a is null;
214
227
id select_type table type possible_keys key key_len ref rows Extra
215
1 SIMPLE t1 system a NULL NULL NULL X
216
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
217
230
explain select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
218
231
id select_type table type possible_keys key key_len ref rows Extra
219
1 SIMPLE t1 system a NULL NULL NULL X
220
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
221
234
select * from t2,t1 where t1.a<=>t2.a or (t1.a is null and t1.b <> 9);
224
245
drop table t1,t2;
225
246
CREATE TABLE t1 (
226
id int NOT NULL auto_increment,
227
uniq_id int default NULL,
247
id int(10) unsigned NOT NULL auto_increment,
248
uniq_id int(10) unsigned default NULL,
228
249
PRIMARY KEY (id),
229
250
UNIQUE KEY idx1 (uniq_id)
231
252
CREATE TABLE t2 (
232
id int NOT NULL auto_increment,
233
uniq_id int default NULL,
253
id int(10) unsigned NOT NULL auto_increment,
254
uniq_id int(10) unsigned default NULL,
236
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);
237
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);
238
259
explain select id from t1 where uniq_id is null;
239
260
id select_type table type possible_keys key key_len ref rows Extra
240
1 SIMPLE t1 ref idx1 idx1 5 const 5 Using where
261
1 SIMPLE t1 ref idx1 idx1 5 const 5 Using index condition
241
262
explain select id from t1 where uniq_id =1;
242
263
id select_type table type possible_keys key key_len ref rows Extra
243
264
1 SIMPLE t1 const idx1 idx1 5 const 1