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` (
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 91 NULL 16 Using where; 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');
194
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
195
id select_type table type possible_keys key key_len ref rows Extra
196
1 SIMPLE t4 ALL idx1 NULL NULL NULL 178 Using where
197
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
214
bb-1 NULL cc-2 NULL-15
215
bb-1 NULL cc-2 NULL-14
216
bb-1 NULL cc-2 NULL-13
217
bb-1 NULL cc-2 NULL-12
218
bb-1 NULL cc-2 NULL-11
219
bb-1 NULL cc-2 NULL-10
220
bb-1 NULL cc-2 NULL-9
221
bb-1 NULL cc-2 NULL-8
222
bb-1 NULL cc-2 NULL-7
223
bb-1 NULL cc-2 NULL-6
224
bb-1 NULL cc-2 NULL-5
225
bb-1 NULL cc-2 NULL-4
226
bb-1 NULL cc-2 NULL-3
227
bb-1 NULL cc-2 NULL-2
228
bb-1 NULL cc-2 NULL-1
229
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');
246
bb-1 NULL cc-2 NULL-15
247
bb-1 NULL cc-2 NULL-14
248
bb-1 NULL cc-2 NULL-13
249
bb-1 NULL cc-2 NULL-12
250
bb-1 NULL cc-2 NULL-11
251
bb-1 NULL cc-2 NULL-10
252
bb-1 NULL cc-2 NULL-9
253
bb-1 NULL cc-2 NULL-8
254
bb-1 NULL cc-2 NULL-7
255
bb-1 NULL cc-2 NULL-6
256
bb-1 NULL cc-2 NULL-5
257
bb-1 NULL cc-2 NULL-4
258
bb-1 NULL cc-2 NULL-3
259
bb-1 NULL cc-2 NULL-2
260
bb-1 NULL cc-2 NULL-1
261
set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
262
drop table t1, t2, t3, t4;
264
ID int NOT NULL AUTO_INCREMENT,
265
col1 int DEFAULT NULL,
266
key1 int NOT NULL DEFAULT '0',
267
key2 int DEFAULT NULL,
270
col2 int DEFAULT '100',
271
col3 enum('headers','bodyandsubject') NOT NULL DEFAULT 'bodyandsubject',
272
col4 int NOT NULL DEFAULT '0',
276
) ENGINE=MyISAM AUTO_INCREMENT=6;
277
INSERT INTO t1 VALUES
278
(1,NULL,1130,NULL,'Hello',NULL,100,'bodyandsubject',0),
279
(2,NULL,1130,NULL,'bye',NULL,100,'bodyandsubject',0),
280
(3,NULL,1130,NULL,'red',NULL,100,'bodyandsubject',0),
281
(4,NULL,1130,NULL,'yellow',NULL,100,'bodyandsubject',0),
282
(5,NULL,1130,NULL,'blue',NULL,100,'bodyandsubject',0);
283
select * FROM t1 WHERE key1=1130 AND col1 IS NULL ORDER BY text1;
284
ID col1 key1 key2 text1 text2 col2 col3 col4
285
5 NULL 1130 NULL blue NULL 100 bodyandsubject 0
286
2 NULL 1130 NULL bye NULL 100 bodyandsubject 0
287
1 NULL 1130 NULL Hello NULL 100 bodyandsubject 0
288
3 NULL 1130 NULL red NULL 100 bodyandsubject 0
289
4 NULL 1130 NULL yellow NULL 100 bodyandsubject 0