2
create table t1(a int);
4
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
5
create table t2(a int);
6
insert into t2 select A.a + 10*(B.a + 10*C.a) from t1 A, t1 B, t1 C;
10
a char(8) not null, b char(8) not null, filler char(200),
13
insert into t3 select @a:=concat('c-', 1000+ A.a, '=w'), @a, 'filler' from t2 A;
14
insert into t3 select concat('c-', 1000+A.a, '=w'), concat('c-', 2000+A.a, '=w'),
16
insert into t3 select concat('c-', 1000+A.a, '=w'), concat('c-', 3000+A.a, '=w'),
19
# Test empty result set
20
select a,filler from t3 where a >= 'c-9011=w';
22
# Ok, t3.ref_length=6, limit is 64 => 10 elements fit into the buffer
23
# Test the cases when buffer gets exhausted at different points in source
26
# 1. Split is in the middle of the range
27
select a,filler from t3 where a >= 'c-1011=w' and a <= 'c-1015=w';
29
# 2. Split is at range edge
30
select a,filler from t3 where (a>='c-1011=w' and a <= 'c-1013=w') or
31
(a>='c-1014=w' and a <= 'c-1015=w');
33
# 3. Split is at range edge, with some rows between ranges.
34
insert into t3 values ('c-1013=z', 'c-1013=z', 'err');
35
insert into t3 values ('a-1014=w', 'a-1014=w', 'err');
37
select a,filler from t3 where (a>='c-1011=w' and a <= 'c-1013=w') or
38
(a>='c-1014=w' and a <= 'c-1015=w');
39
delete from t3 where b in ('c-1013=z', 'a-1014=w');
41
# 4. Split is within the equality range.
42
select a,filler from t3 where a='c-1011=w' or a='c-1012=w' or a='c-1013=w' or
43
a='c-1014=w' or a='c-1015=w';
45
# 5. Split is at the edge of equality range.
46
insert into t3 values ('c-1013=w', 'del-me', 'inserted');
47
select a,filler from t3 where a='c-1011=w' or a='c-1012=w' or a='c-1013=w' or
48
a='c-1014=w' or a='c-1015=w';
49
delete from t3 where b='del-me';
51
# PK tests are not included here.
53
alter table t3 add primary key(b);
56
# 6. Split is between 'unique' PK ranges
57
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1018=w') or
58
b IN ('c-1019=w', 'c-1020=w', 'c-1021=w',
59
'c-1022=w', 'c-1023=w', 'c-1024=w');
61
# 7. Between non-uniq and uniq range
62
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1020=w') or
63
b IN ('c-1021=w', 'c-1022=w', 'c-1023=w');
65
# 8. Between uniq and non-uniq range
66
select b,filler from t3 where (b>='c-1011=w' and b<= 'c-1018=w') or
67
b IN ('c-1019=w', 'c-1020=w') or
68
(b>='c-1021=w' and b<= 'c-1023=w');
69
## End of PK scan tests
72
# Now try different keypart types and special values
74
create table t4 (a varchar(10), b int, c char(10), filler char(200),
77
# insert buffer_size * 1.5 all-NULL tuples
78
insert into t4 (filler) select concat('NULL-', 15-a) from t2 order by a limit 15;
80
insert into t4 (a,b,c,filler)
81
select 'b-1',NULL,'c-1', concat('NULL-', 15-a) from t2 order by a limit 15;
82
insert into t4 (a,b,c,filler)
83
select 'b-1',NULL,'c-222', concat('NULL-', 15-a) from t2 order by a limit 15;
84
insert into t4 (a,b,c,filler)
85
select 'bb-1',NULL,'cc-2', concat('NULL-', 15-a) from t2 order by a limit 15;
86
insert into t4 (a,b,c,filler)
87
select 'zz-1',NULL,'cc-2', 'filler-data' from t2 order by a limit 500;
90
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
92
select * from t4 where a IS NULL and b IS NULL and (c IS NULL or c='no-such-row1'
96
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
97
select * from t4 where (a ='b-1' or a='bb-1') and b IS NULL and (c='c-1' or c='cc-2');
99
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');