1
drop table if exists t1, t2, t3;
2
set @read_rnd_buffer_size_save= @@read_rnd_buffer_size;
3
set read_rnd_buffer_size=79;
4
select @@read_rnd_buffer_size;
7
create table t1(a int);
10
t1 CREATE TABLE `t1` (
11
`a` int(11) DEFAULT NULL
12
) ENGINE=MyISAM DEFAULT CHARSET=latin1
13
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
14
create table t2(a int);
15
insert into t2 select A.a + 10*(B.a + 10*C.a) from t1 A, t1 B, t1 C;
17
a char(8) not null, b char(8) not null, filler char(200),
20
insert into t3 select @a:=concat('c-', 1000+ A.a, '=w'), @a, 'filler' from t2 A;
21
insert into t3 select concat('c-', 1000+A.a, '=w'), concat('c-', 2000+A.a, '=w'),
23
insert into t3 select concat('c-', 1000+A.a, '=w'), concat('c-', 3000+A.a, '=w'),
25
select a,filler from t3 where a >= 'c-9011=w';
27
select a,filler from t3 where a >= 'c-1011=w' and a <= 'c-1015=w';
44
select a,filler from t3 where (a>='c-1011=w' and a <= 'c-1013=w') or
45
(a>='c-1014=w' and a <= 'c-1015=w');
62
insert into t3 values ('c-1013=z', 'c-1013=z', 'err');
63
insert into t3 values ('a-1014=w', 'a-1014=w', 'err');
64
select a,filler from t3 where (a>='c-1011=w' and a <= 'c-1013=w') or
65
(a>='c-1014=w' and a <= 'c-1015=w');
82
delete from t3 where b in ('c-1013=z', 'a-1014=w');
83
select a,filler from t3 where a='c-1011=w' or a='c-1012=w' or a='c-1013=w' or
84
a='c-1014=w' or a='c-1015=w';
101
insert into t3 values ('c-1013=w', 'del-me', 'inserted');
102
select a,filler from t3 where a='c-1011=w' or a='c-1012=w' or a='c-1013=w' or
103
a='c-1014=w' or a='c-1015=w';
121
delete from t3 where b='del-me';
122
alter table t3 add primary key(b);
123
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1018=w') or
124
b IN ('c-1019=w', 'c-1020=w', 'c-1021=w',
125
'c-1022=w', 'c-1023=w', 'c-1024=w');
141
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1020=w') or
142
b IN ('c-1021=w', 'c-1022=w', 'c-1023=w');
157
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1018=w') or
158
b IN ('c-1019=w', 'c-1020=w') or
159
(b>='c-1021=w' and b<= 'c-1023=w');
174
create table t4 (a varchar(10), b int, c char(10), filler char(200),
176
insert into t4 (filler) select concat('NULL-', 15-a) from t2 order by a limit 15;
177
insert into t4 (a,b,c,filler)
178
select 'b-1',NULL,'c-1', concat('NULL-', 15-a) from t2 order by a limit 15;
179
insert into t4 (a,b,c,filler)
180
select 'b-1',NULL,'c-222', concat('NULL-', 15-a) from t2 order by a limit 15;
181
insert into t4 (a,b,c,filler)
182
select 'bb-1',NULL,'cc-2', concat('NULL-', 15-a) from t2 order by a limit 15;
183
insert into t4 (a,b,c,filler)
184
select 'zz-1',NULL,'cc-2', 'filler-data' from t2 order by a limit 500;
186
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
187
or c='no-such-row2');
188
id select_type table type possible_keys key key_len ref rows Extra
189
1 SIMPLE t4 range idx1 idx1 29 NULL 10 Using index condition; Using MRR
190
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
191
or c='no-such-row2');
193
NULL NULL NULL NULL-15
194
NULL NULL NULL NULL-14
195
NULL NULL NULL NULL-13
196
NULL NULL NULL NULL-12
197
NULL NULL NULL NULL-11
198
NULL NULL NULL NULL-10
199
NULL NULL NULL NULL-9
200
NULL NULL NULL NULL-8
201
NULL NULL NULL NULL-7
202
NULL NULL NULL NULL-6
203
NULL NULL NULL NULL-5
204
NULL NULL NULL NULL-4
205
NULL NULL NULL NULL-3
206
NULL NULL NULL NULL-2
207
NULL NULL NULL NULL-1
209
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
210
id select_type table type possible_keys key key_len ref rows Extra
211
1 SIMPLE t4 range idx1 idx1 29 NULL 21 Using index condition; Using MRR
212
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
229
bb-1 NULL cc-2 NULL-15
230
bb-1 NULL cc-2 NULL-14
231
bb-1 NULL cc-2 NULL-13
232
bb-1 NULL cc-2 NULL-12
233
bb-1 NULL cc-2 NULL-11
234
bb-1 NULL cc-2 NULL-10
235
bb-1 NULL cc-2 NULL-9
236
bb-1 NULL cc-2 NULL-8
237
bb-1 NULL cc-2 NULL-7
238
bb-1 NULL cc-2 NULL-6
239
bb-1 NULL cc-2 NULL-5
240
bb-1 NULL cc-2 NULL-4
241
bb-1 NULL cc-2 NULL-3
242
bb-1 NULL cc-2 NULL-2
243
bb-1 NULL cc-2 NULL-1
244
select * from t4 ignore index(idx1) where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
261
bb-1 NULL cc-2 NULL-15
262
bb-1 NULL cc-2 NULL-14
263
bb-1 NULL cc-2 NULL-13
264
bb-1 NULL cc-2 NULL-12
265
bb-1 NULL cc-2 NULL-11
266
bb-1 NULL cc-2 NULL-10
267
bb-1 NULL cc-2 NULL-9
268
bb-1 NULL cc-2 NULL-8
269
bb-1 NULL cc-2 NULL-7
270
bb-1 NULL cc-2 NULL-6
271
bb-1 NULL cc-2 NULL-5
272
bb-1 NULL cc-2 NULL-4
273
bb-1 NULL cc-2 NULL-3
274
bb-1 NULL cc-2 NULL-2
275
bb-1 NULL cc-2 NULL-1
276
set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
277
drop table t1, t2, t3, t4;
279
ID int(10) unsigned NOT NULL AUTO_INCREMENT,
280
col1 int(10) unsigned DEFAULT NULL,
281
key1 int(10) unsigned NOT NULL DEFAULT '0',
282
key2 int(10) unsigned DEFAULT NULL,
285
col2 smallint(6) DEFAULT '100',
286
col3 enum('headers','bodyandsubject') NOT NULL DEFAULT 'bodyandsubject',
287
col4 tinyint(3) unsigned NOT NULL DEFAULT '0',
291
) ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8;
292
INSERT INTO t1 VALUES
293
(1,NULL,1130,NULL,'Hello',NULL,100,'bodyandsubject',0),
294
(2,NULL,1130,NULL,'bye',NULL,100,'bodyandsubject',0),
295
(3,NULL,1130,NULL,'red',NULL,100,'bodyandsubject',0),
296
(4,NULL,1130,NULL,'yellow',NULL,100,'bodyandsubject',0),
297
(5,NULL,1130,NULL,'blue',NULL,100,'bodyandsubject',0);
298
select * FROM t1 WHERE key1=1130 AND col1 IS NULL ORDER BY text1;
299
ID col1 key1 key2 text1 text2 col2 col3 col4
300
5 NULL 1130 NULL blue NULL 100 bodyandsubject 0
301
2 NULL 1130 NULL bye NULL 100 bodyandsubject 0
302
1 NULL 1130 NULL Hello NULL 100 bodyandsubject 0
303
3 NULL 1130 NULL red NULL 100 bodyandsubject 0
304
4 NULL 1130 NULL yellow NULL 100 bodyandsubject 0