1
drop table if exists t1,t2,t3,t4;
2
set @save_storage_engine= @@storage_engine;
3
set storage_engine=InnoDB;
4
create table t1(a int);
9
) ENGINE=InnoDB DEFAULT CHARSET=latin1
10
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
11
create table t2(a int);
12
insert into t2 select A.a + 10*(B.a + 10*C.a) from t1 A, t1 B, t1 C;
14
a char(8) not null, b char(8) not null, filler char(200),
17
insert into t3 select @a:=concat('c-', 1000+ A.a, '=w'), @a, 'filler' from t2 A;
18
insert into t3 select concat('c-', 1000+A.a, '=w'), concat('c-', 2000+A.a, '=w'),
20
insert into t3 select concat('c-', 1000+A.a, '=w'), concat('c-', 3000+A.a, '=w'),
22
select a,filler from t3 where a >= 'c-9011=w';
24
select a,filler from t3 where a >= 'c-1011=w' and a <= 'c-1015=w';
41
select a,filler from t3 where (a>='c-1011=w' and a <= 'c-1013=w') or
42
(a>='c-1014=w' and a <= 'c-1015=w');
59
insert into t3 values ('c-1013=z', 'c-1013=z', 'err');
60
insert into t3 values ('a-1014=w', 'a-1014=w', 'err');
61
select a,filler from t3 where (a>='c-1011=w' and a <= 'c-1013=w') or
62
(a>='c-1014=w' and a <= 'c-1015=w');
79
delete from t3 where b in ('c-1013=z', 'a-1014=w');
80
select a,filler from t3 where a='c-1011=w' or a='c-1012=w' or a='c-1013=w' or
81
a='c-1014=w' or a='c-1015=w';
98
insert into t3 values ('c-1013=w', 'del-me', 'inserted');
99
select a,filler from t3 where a='c-1011=w' or a='c-1012=w' or a='c-1013=w' or
100
a='c-1014=w' or a='c-1015=w';
118
delete from t3 where b='del-me';
119
alter table t3 add primary key(b);
120
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1018=w') or
121
b IN ('c-1019=w', 'c-1020=w', 'c-1021=w',
122
'c-1022=w', 'c-1023=w', 'c-1024=w');
138
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1020=w') or
139
b IN ('c-1021=w', 'c-1022=w', 'c-1023=w');
154
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1018=w') or
155
b IN ('c-1019=w', 'c-1020=w') or
156
(b>='c-1021=w' and b<= 'c-1023=w');
171
create table t4 (a varchar(10), b int, c char(10), filler char(200),
173
insert into t4 (filler) select concat('NULL-', 15-a) from t2 order by a limit 15;
174
insert into t4 (a,b,c,filler)
175
select 'b-1',NULL,'c-1', concat('NULL-', 15-a) from t2 order by a limit 15;
176
insert into t4 (a,b,c,filler)
177
select 'b-1',NULL,'c-222', concat('NULL-', 15-a) from t2 order by a limit 15;
178
insert into t4 (a,b,c,filler)
179
select 'bb-1',NULL,'cc-2', concat('NULL-', 15-a) from t2 order by a limit 15;
180
insert into t4 (a,b,c,filler)
181
select 'zz-1',NULL,'cc-2', 'filler-data' from t2 order by a limit 500;
183
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
184
or c='no-such-row2');
185
id select_type table type possible_keys key key_len ref rows Extra
186
1 SIMPLE t4 range idx1 idx1 29 NULL 16 Using index condition; Using MRR
187
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
188
or c='no-such-row2');
190
NULL NULL NULL NULL-15
191
NULL NULL NULL NULL-14
192
NULL NULL NULL NULL-13
193
NULL NULL NULL NULL-12
194
NULL NULL NULL NULL-11
195
NULL NULL NULL NULL-10
196
NULL NULL NULL NULL-9
197
NULL NULL NULL NULL-8
198
NULL NULL NULL NULL-7
199
NULL NULL NULL NULL-6
200
NULL NULL NULL NULL-5
201
NULL NULL NULL NULL-4
202
NULL NULL NULL NULL-3
203
NULL NULL NULL NULL-2
204
NULL NULL NULL NULL-1
206
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
207
id select_type table type possible_keys key key_len ref rows Extra
208
1 SIMPLE t4 range idx1 idx1 29 NULL 32 Using index condition; Using MRR
209
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
226
bb-1 NULL cc-2 NULL-15
227
bb-1 NULL cc-2 NULL-14
228
bb-1 NULL cc-2 NULL-13
229
bb-1 NULL cc-2 NULL-12
230
bb-1 NULL cc-2 NULL-11
231
bb-1 NULL cc-2 NULL-10
232
bb-1 NULL cc-2 NULL-9
233
bb-1 NULL cc-2 NULL-8
234
bb-1 NULL cc-2 NULL-7
235
bb-1 NULL cc-2 NULL-6
236
bb-1 NULL cc-2 NULL-5
237
bb-1 NULL cc-2 NULL-4
238
bb-1 NULL cc-2 NULL-3
239
bb-1 NULL cc-2 NULL-2
240
bb-1 NULL cc-2 NULL-1
241
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');
258
bb-1 NULL cc-2 NULL-15
259
bb-1 NULL cc-2 NULL-14
260
bb-1 NULL cc-2 NULL-13
261
bb-1 NULL cc-2 NULL-12
262
bb-1 NULL cc-2 NULL-11
263
bb-1 NULL cc-2 NULL-10
264
bb-1 NULL cc-2 NULL-9
265
bb-1 NULL cc-2 NULL-8
266
bb-1 NULL cc-2 NULL-7
267
bb-1 NULL cc-2 NULL-6
268
bb-1 NULL cc-2 NULL-5
269
bb-1 NULL cc-2 NULL-4
270
bb-1 NULL cc-2 NULL-3
271
bb-1 NULL cc-2 NULL-2
272
bb-1 NULL cc-2 NULL-1
273
set storage_engine= @save_storage_engine;
274
drop table t1, t2, t3, t4;
275
set @read_rnd_buffer_size_save= @@read_rnd_buffer_size;
276
set read_rnd_buffer_size=64;
277
create table t1(a int);
278
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
279
create table t2(a char(8), b char(8), c char(8), filler char(100), key(a,b,c) ) engine=InnoDB;
280
insert into t2 select
281
concat('a-', 1000 + A.a, '-a'),
282
concat('b-', 1000 + B.a, '-b'),
283
concat('c-', 1000 + C.a, '-c'),
285
from t1 A, t1 B, t1 C;
287
select count(length(a) + length(filler)) from t2 where a>='a-1000-a' and a <'a-1001-a';
288
id select_type table type possible_keys key key_len ref rows Extra
289
1 SIMPLE t2 range a a 9 NULL 99 Using index condition; Using MRR
290
select count(length(a) + length(filler)) from t2 where a>='a-1000-a' and a <'a-1001-a';
291
count(length(a) + length(filler))
294
create table t2 (a char(100), b char(100), c char(100), d int,
295
filler char(10), key(d), primary key (a,b,c)) engine= innodb;
296
insert into t2 select A.a, B.a, B.a, A.a, 'filler' from t1 A, t1 B;
297
explain select * from t2 force index (d) where d < 10;
298
id select_type table type possible_keys key key_len ref rows Extra
299
1 SIMPLE t2 range d d 5 NULL 47 Using index condition; Using MRR
302
set @@read_rnd_buffer_size= @read_rnd_buffer_size_save;
303
create table t1 (f1 int not null, f2 int not null,f3 int not null, f4 char(1), primary key (f1,f2), key ix(f3))Engine=InnoDB;
304
select * from t1 where (f3>=5 and f3<=10) or (f3>=1 and f3<=4);