summaryrefslogtreecommitdiff
path: root/mysql-test/r/maria_mrr.result
blob: 0dd7746bc4bc8a4b7b841218d49f3790a2e50507 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
drop table if exists t1,t2,t3,t4;
set @save_storage_engine= @@storage_engine;
set storage_engine=aria;
create table t1(a int);
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
  `a` int(11) DEFAULT NULL
) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2(a int);
insert into t2 select A.a + 10*(B.a + 10*C.a) from t1 A, t1 B, t1 C;
create table t3 (
a char(8) not null, b char(8) not null, filler char(200),
key(a)
);
insert into t3 select @a:=concat('c-', 1000+ A.a, '=w'), @a, 'filler' from t2 A;
insert into t3 select concat('c-', 1000+A.a, '=w'), concat('c-', 2000+A.a, '=w'), 
'filler-1' from t2 A;
insert into t3 select concat('c-', 1000+A.a, '=w'), concat('c-', 3000+A.a, '=w'), 
'filler-2' from t2 A;
select a,filler from t3 where a >= 'c-9011=w';
a	filler
select a,filler from t3 where a >= 'c-1011=w' and a <= 'c-1015=w';
a	filler
c-1011=w	filler
c-1012=w	filler
c-1013=w	filler
c-1014=w	filler
c-1015=w	filler
c-1011=w	filler-1
c-1012=w	filler-1
c-1013=w	filler-1
c-1014=w	filler-1
c-1015=w	filler-1
c-1011=w	filler-2
c-1012=w	filler-2
c-1013=w	filler-2
c-1014=w	filler-2
c-1015=w	filler-2
select a,filler from t3 where (a>='c-1011=w' and a <= 'c-1013=w') or
(a>='c-1014=w' and a <= 'c-1015=w');
a	filler
c-1011=w	filler
c-1012=w	filler
c-1013=w	filler
c-1014=w	filler
c-1015=w	filler
c-1011=w	filler-1
c-1012=w	filler-1
c-1013=w	filler-1
c-1014=w	filler-1
c-1015=w	filler-1
c-1011=w	filler-2
c-1012=w	filler-2
c-1013=w	filler-2
c-1014=w	filler-2
c-1015=w	filler-2
insert into t3 values ('c-1013=z', 'c-1013=z', 'err');
insert into t3 values ('a-1014=w', 'a-1014=w', 'err');
select a,filler from t3 where (a>='c-1011=w' and a <= 'c-1013=w') or
(a>='c-1014=w' and a <= 'c-1015=w');
a	filler
c-1011=w	filler
c-1012=w	filler
c-1013=w	filler
c-1014=w	filler
c-1015=w	filler
c-1011=w	filler-1
c-1012=w	filler-1
c-1013=w	filler-1
c-1014=w	filler-1
c-1015=w	filler-1
c-1011=w	filler-2
c-1012=w	filler-2
c-1013=w	filler-2
c-1014=w	filler-2
c-1015=w	filler-2
delete from t3 where b in ('c-1013=z', 'a-1014=w');
select a,filler from t3 where a='c-1011=w' or a='c-1012=w' or a='c-1013=w' or
a='c-1014=w' or a='c-1015=w';
a	filler
c-1011=w	filler
c-1012=w	filler
c-1013=w	filler
c-1014=w	filler
c-1015=w	filler
c-1011=w	filler-1
c-1012=w	filler-1
c-1013=w	filler-1
c-1014=w	filler-1
c-1015=w	filler-1
c-1011=w	filler-2
c-1012=w	filler-2
c-1013=w	filler-2
c-1014=w	filler-2
c-1015=w	filler-2
insert into t3 values ('c-1013=w', 'del-me', 'inserted');
select a,filler from t3 where a='c-1011=w' or a='c-1012=w' or a='c-1013=w' or
a='c-1014=w' or a='c-1015=w';
a	filler
c-1011=w	filler
c-1012=w	filler
c-1013=w	filler
c-1014=w	filler
c-1015=w	filler
c-1011=w	filler-1
c-1012=w	filler-1
c-1013=w	filler-1
c-1014=w	filler-1
c-1015=w	filler-1
c-1011=w	filler-2
c-1012=w	filler-2
c-1013=w	filler-2
c-1014=w	filler-2
c-1015=w	filler-2
c-1013=w	inserted
delete from t3 where b='del-me';
alter table t3 add primary key(b);
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1018=w') or 
b IN ('c-1019=w', 'c-1020=w', 'c-1021=w', 
'c-1022=w', 'c-1023=w', 'c-1024=w');
b	filler
c-1011=w	filler
c-1012=w	filler
c-1013=w	filler
c-1014=w	filler
c-1015=w	filler
c-1016=w	filler
c-1017=w	filler
c-1018=w	filler
c-1019=w	filler
c-1020=w	filler
c-1021=w	filler
c-1022=w	filler
c-1023=w	filler
c-1024=w	filler
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1020=w') or 
b IN ('c-1021=w', 'c-1022=w', 'c-1023=w');
b	filler
c-1011=w	filler
c-1012=w	filler
c-1013=w	filler
c-1014=w	filler
c-1015=w	filler
c-1016=w	filler
c-1017=w	filler
c-1018=w	filler
c-1019=w	filler
c-1020=w	filler
c-1021=w	filler
c-1022=w	filler
c-1023=w	filler
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1018=w') or 
b IN ('c-1019=w', 'c-1020=w') or 
(b>='c-1021=w' and b<= 'c-1023=w');
b	filler
c-1011=w	filler
c-1012=w	filler
c-1013=w	filler
c-1014=w	filler
c-1015=w	filler
c-1016=w	filler
c-1017=w	filler
c-1018=w	filler
c-1019=w	filler
c-1020=w	filler
c-1021=w	filler
c-1022=w	filler
c-1023=w	filler
create table t4 (a varchar(10), b int, c char(10), filler char(200),
key idx1 (a, b, c));
insert into t4 (filler) select concat('NULL-', 15-a) from t2 order by a limit 15;
insert into t4 (a,b,c,filler) 
select 'b-1',NULL,'c-1', concat('NULL-', 15-a) from t2 order by a limit 15;
insert into t4 (a,b,c,filler) 
select 'b-1',NULL,'c-222', concat('NULL-', 15-a) from t2 order by a limit 15;
insert into t4 (a,b,c,filler) 
select 'bb-1',NULL,'cc-2', concat('NULL-', 15-a) from t2 order by a limit 15;
insert into t4 (a,b,c,filler) 
select 'zz-1',NULL,'cc-2', 'filler-data' from t2 order by a limit 500;
explain 
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
                                                      or c='no-such-row2');
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	range	idx1	idx1	29	NULL	16	Using index condition; Using MRR
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
                                                    or c='no-such-row2');
a	b	c	filler
NULL	NULL	NULL	NULL-15
NULL	NULL	NULL	NULL-14
NULL	NULL	NULL	NULL-13
NULL	NULL	NULL	NULL-12
NULL	NULL	NULL	NULL-11
NULL	NULL	NULL	NULL-10
NULL	NULL	NULL	NULL-9
NULL	NULL	NULL	NULL-8
NULL	NULL	NULL	NULL-7
NULL	NULL	NULL	NULL-6
NULL	NULL	NULL	NULL-5
NULL	NULL	NULL	NULL-4
NULL	NULL	NULL	NULL-3
NULL	NULL	NULL	NULL-2
NULL	NULL	NULL	NULL-1
explain 
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t4	range	idx1	idx1	29	NULL	32	Using index condition; Using MRR
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
a	b	c	filler
b-1	NULL	c-1	NULL-15
b-1	NULL	c-1	NULL-14
b-1	NULL	c-1	NULL-13
b-1	NULL	c-1	NULL-12
b-1	NULL	c-1	NULL-11
b-1	NULL	c-1	NULL-10
b-1	NULL	c-1	NULL-9
b-1	NULL	c-1	NULL-8
b-1	NULL	c-1	NULL-7
b-1	NULL	c-1	NULL-6
b-1	NULL	c-1	NULL-5
b-1	NULL	c-1	NULL-4
b-1	NULL	c-1	NULL-3
b-1	NULL	c-1	NULL-2
b-1	NULL	c-1	NULL-1
bb-1	NULL	cc-2	NULL-15
bb-1	NULL	cc-2	NULL-14
bb-1	NULL	cc-2	NULL-13
bb-1	NULL	cc-2	NULL-12
bb-1	NULL	cc-2	NULL-11
bb-1	NULL	cc-2	NULL-10
bb-1	NULL	cc-2	NULL-9
bb-1	NULL	cc-2	NULL-8
bb-1	NULL	cc-2	NULL-7
bb-1	NULL	cc-2	NULL-6
bb-1	NULL	cc-2	NULL-5
bb-1	NULL	cc-2	NULL-4
bb-1	NULL	cc-2	NULL-3
bb-1	NULL	cc-2	NULL-2
bb-1	NULL	cc-2	NULL-1
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');
a	b	c	filler
b-1	NULL	c-1	NULL-15
b-1	NULL	c-1	NULL-14
b-1	NULL	c-1	NULL-13
b-1	NULL	c-1	NULL-12
b-1	NULL	c-1	NULL-11
b-1	NULL	c-1	NULL-10
b-1	NULL	c-1	NULL-9
b-1	NULL	c-1	NULL-8
b-1	NULL	c-1	NULL-7
b-1	NULL	c-1	NULL-6
b-1	NULL	c-1	NULL-5
b-1	NULL	c-1	NULL-4
b-1	NULL	c-1	NULL-3
b-1	NULL	c-1	NULL-2
b-1	NULL	c-1	NULL-1
bb-1	NULL	cc-2	NULL-15
bb-1	NULL	cc-2	NULL-14
bb-1	NULL	cc-2	NULL-13
bb-1	NULL	cc-2	NULL-12
bb-1	NULL	cc-2	NULL-11
bb-1	NULL	cc-2	NULL-10
bb-1	NULL	cc-2	NULL-9
bb-1	NULL	cc-2	NULL-8
bb-1	NULL	cc-2	NULL-7
bb-1	NULL	cc-2	NULL-6
bb-1	NULL	cc-2	NULL-5
bb-1	NULL	cc-2	NULL-4
bb-1	NULL	cc-2	NULL-3
bb-1	NULL	cc-2	NULL-2
bb-1	NULL	cc-2	NULL-1
drop table t1, t2, t3, t4;
create table t1 (a int, b int not null,unique key (a,b),index(b));
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);
create table t2 like t1;
insert into t2 select * from t1;
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));
select * from t1 where a is null;
a	b	c
NULL	7	0
NULL	9	0
NULL	9	0
select * from t1 where (a is null or a > 0 and a < 3) and b > 7 limit 3;
a	b	c
NULL	9	0
NULL	9	0
select * from t1 where a is null and b=9 or a is null and b=7 limit 3;
a	b	c
NULL	7	0
NULL	9	0
NULL	9	0
drop table t1, t2;
set storage_engine= @save_storage_engine;
CREATE TABLE t1(
pk int NOT NULL, i int NOT NULL, v varchar(1) NOT NULL,
PRIMARY KEY (pk), INDEX idx (v, i)
) ENGINE=ARIA;
INSERT INTO t1 VALUES 
(1,9,'x'), (2,5,'g'), (3,1,'o'), (4,0,'g'), (5,1,'v'),
(6,190,'m'), (7,6,'x'), (8,3,'c'), (9,4,'z'), (10,3,'i'),
(11,186,'x'), (12,1,'g'), (13,8,'q'), (14,226,'m'), (15,133,'p');
CREATE TABLE t2(
pk int NOT NULL, i int NOT NULL, v varchar(1) NOT NULL,
PRIMARY KEY (pk), INDEX idx (v, i)
) ENGINE=ARIA;
INSERT INTO t2 SELECT * FROM t1;
INSERT INTO t2 VALUES (77, 333, 'z');
CREATE TABLE t3(
pk int NOT NULL, i int NOT NULL, v varchar(1) NOT NULL,
PRIMARY KEY (pk), INDEX idx (v, i)
) ENGINE=ARIA;
INSERT INTO t3 SELECT * FROM t1;
INSERT INTO t3 VALUES (88, 442, 'y'), (99, 445, 'w') ;
SELECT COUNT(t1.v) FROM t1, t2 IGNORE INDEX (idx), t3 IGNORE INDEX (idx)
WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0;
COUNT(t1.v)
120
EXPLAIN 
SELECT COUNT(t1.v) FROM t1, t2 IGNORE INDEX (idx), t3 IGNORE INDEX (idx)
WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	index	NULL	idx	7	NULL	15	Using index
1	SIMPLE	t2	ALL	PRIMARY	NULL	NULL	NULL	16	Using where; Using join buffer
1	SIMPLE	t3	ALL	PRIMARY	NULL	NULL	NULL	17	Using where; Using join buffer
SELECT COUNT(t1.v) FROM t1, t2, t3 
WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0;
COUNT(t1.v)
120
EXPLAIN 
SELECT COUNT(t1.v) FROM t1, t2, t3
WHERE t3.v = t2.v AND t3.i < t2.i AND t3.pk > 0 AND t2.pk > 0;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	index	NULL	idx	7	NULL	15	Using index
1	SIMPLE	t2	ALL	PRIMARY,idx	NULL	NULL	NULL	16	Using where; Using join buffer
1	SIMPLE	t3	ref	PRIMARY,idx	idx	3	test.t2.v	2	Using index condition; Using where
DROP TABLE t1,t2,t3;
#
# Bug #669420: MRR for Range checked for each record
#
CREATE TABLE t1 (
pk int NOT NULL PRIMARY KEY,
j int NOT NULL,
i int NOT NULL,
v varchar(1) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
INDEX i (i),
INDEX vi (v,i)
) ENGINE=ARIA;
INSERT INTO t1 VALUES (10,3,8,'v'),(11,3,8,'f');
CREATE TABLE t2 (
pk int NOT NULL PRIMARY KEY,
j int  NOT NULL,
i int  NOT NULL,
v varchar(1) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
INDEX i (i),
INDEX vi (v,i)
) ENGINE=ARIA;
INSERT INTO t2 VALUES (10,9,3,'i'),(11,101,186,'x'),(12,0,1,'g');
SET SESSION join_cache_level=0;
EXPLAIN 
SELECT t1.i, t2.i, t2.v, t3.pk, t3.v FROM t1, t2, t2 t3
WHERE t2.i != 0 AND t3.pk >= t2.i AND t3.v >= t2.v;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	index	NULL	i	4	NULL	2	Using index
1	SIMPLE	t2	index	i,vi	vi	7	NULL	3	Using where; Using index
1	SIMPLE	t3	ALL	PRIMARY,vi	NULL	NULL	NULL	3	Range checked for each record (index map: 0x5)
SELECT t1.i, t2.i, t2.v, t3.pk, t3.v FROM t1, t2, t2 t3
WHERE t2.i != 0 AND t3.pk >= t2.i AND t3.v >= t2.v;
i	i	v	pk	v
8	1	g	10	i
8	1	g	11	x
8	1	g	12	g
8	3	i	10	i
8	3	i	11	x
8	1	g	10	i
8	1	g	11	x
8	1	g	12	g
8	3	i	10	i
8	3	i	11	x
SET SESSION join_cache_level=1;
EXPLAIN 
SELECT t1.i, t2.i, t2.v, t3.pk, t3.v FROM t1, t2, t2 t3
WHERE t2.i != 0 AND t3.pk >= t2.i AND t3.v >= t2.v;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t1	index	NULL	i	4	NULL	2	Using index
1	SIMPLE	t2	index	i,vi	vi	7	NULL	3	Using where; Using index; Using join buffer
1	SIMPLE	t3	ALL	PRIMARY,vi	NULL	NULL	NULL	3	Range checked for each record (index map: 0x5)
SELECT t1.i, t2.i, t2.v, t3.pk, t3.v FROM t1, t2, t2 t3
WHERE t2.i != 0 AND t3.pk >= t2.i AND t3.v >= t2.v;
i	i	v	pk	v
8	3	i	10	i
8	3	i	11	x
8	3	i	10	i
8	3	i	11	x
8	1	g	10	i
8	1	g	11	x
8	1	g	12	g
8	1	g	10	i
8	1	g	11	x
8	1	g	12	g
SET SESSION join_cache_level=DEFAULT;
DROP TABLE t1,t2;
CREATE TABLE t1 (
pk int NOT NULL PRIMARY KEY,
j int NOT NULL,
i int NOT NULL,
v varchar(1) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
INDEX i (i)
) ENGINE=ARIA;
INSERT INTO t1 VALUES 
(10,3,8,'v'),(11,3,8,'f'),(12,3,5,'v'),(13,2,8,'s'),(14,1,8,'a'),
(15,0,6,'p'),(16,8,7,'z'),(17,5,2,'a'),(18,9,5,'h'),(19,5,7,'h'),
(20,4,2,'v'),(21,2,9,'v'),(22,33,142,'b'),(23,5,3,'y'),(24,1,0,'v'),
(25,9,3,'m'),(26,1,5,'z'),(27,3,9,'n'),(28,8,1,'d'),(29,231,107,'a');
SET SESSION join_cache_level = 0;
EXPLAIN
SELECT s.i f FROM t1 t, t1 s WHERE s.i >= t.i AND s.pk < t.j;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t	ALL	i	NULL	NULL	NULL	20	
1	SIMPLE	s	ALL	PRIMARY,i	NULL	NULL	NULL	20	Range checked for each record (index map: 0x3)
SELECT s.i f FROM t1 t, t1 s WHERE s.i >= t.i AND s.pk < t.j;
f
142
142
107
EXPLAIN
SELECT s.i f FROM t1 t, t1 s WHERE s.i >= t.i AND s.pk < t.j GROUP BY f;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	t	ALL	i	NULL	NULL	NULL	20	Using temporary; Using filesort
1	SIMPLE	s	ALL	PRIMARY,i	NULL	NULL	NULL	20	Range checked for each record (index map: 0x3)
SELECT s.i f FROM t1 t, t1 s WHERE s.i >= t.i AND s.pk < t.j GROUP BY f;
f
107
142
EXPLAIN
SELECT s.i f FROM t1 t, t1 s WHERE s.i >= t.i AND s.pk < t.j GROUP BY f LIMIT 1;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
1	SIMPLE	s	ALL	PRIMARY,i	NULL	NULL	NULL	20	Using temporary; Using filesort
1	SIMPLE	t	ALL	i	NULL	NULL	NULL	20	Using where
SELECT s.i f FROM t1 t, t1 s WHERE s.i >= t.i AND s.pk < t.j GROUP BY f LIMIT 1;
f
107
SET SESSION join_cache_level=DEFAULT;
DROP TABLE t1;