~drizzle-trunk/drizzle/development

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