~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
# include/index_merge_ror.inc
2
#
3
#  ROR-index_merge tests.
4
#
5
# The variable
6
#     $engine_type       -- storage engine to be tested
7
# has to be set before sourcing this script.
8
#
9
# Note: The comments/expectations refer to MyISAM.
10
#       They might be not valid for other storage engines.
11
#
12
# Last update:
13
# 2006-08-02 ML test refactored
14
#               old name was t/index_merge_ror.test
15
#               main code went into include/index_merge_ror.inc
16
#
17
18
--echo #---------------- ROR-index_merge tests -----------------------
19
20
eval SET SESSION STORAGE_ENGINE = $engine_type;
21
22
--disable_warnings
23
drop table if exists  t0,t1,t2;
24
--enable_warnings
25
create table t1
26
(
27
  /* Field names reflect value(rowid) distribution, st=STairs, swt= SaWTooth */
28
  st_a int not null default 0,
29
  swt1a int not null default 0,
30
  swt2a int not null default 0,
31
32
  st_b int not null default 0,
33
  swt1b int not null default 0,
34
  swt2b int not null default 0,
35
36
  /* fields/keys for row retrieval tests */
37
  key1 int,
38
  key2 int,
39
  key3 int,
40
  key4 int,
41
42
  /* make rows much bigger then keys */
43
  filler1 char (200),
44
  filler2 char (200),
45
  filler3 char (200),
46
  filler4 char (200),
47
  filler5 char (200),
48
  filler6 char (200),
49
50
  /* order of keys is important */
51
  key sta_swt12a(st_a,swt1a,swt2a),
52
  key sta_swt1a(st_a,swt1a),
53
  key sta_swt2a(st_a,swt2a),
54
  key sta_swt21a(st_a,swt2a,swt1a),
55
56
  key st_a(st_a),
57
  key stb_swt1a_2b(st_b,swt1b,swt2a),
58
  key stb_swt1b(st_b,swt1b),
59
  key st_b(st_b),
60
61
  key(key1),
62
  key(key2),
63
  key(key3),
64
  key(key4)
65
) ;
66
67
# Fill table
68
create table t0 as select * from t1;
69
--disable_query_log
70
--echo # Printing of many insert into t0 values (....) disabled.
71
let $cnt=1000;
72
while ($cnt)
73
{
74
  eval insert into t0 values (1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 'data1', 'data2', 'data3', 'data4', 'data5', 'data6');
75
  dec $cnt;
76
}
77
--enable_query_log
78
79
alter table t1 disable keys;
80
--disable_query_log
81
--echo # Printing of many insert into t1 select .... from t0 disabled.
82
let $1=4;
83
while ($1)
84
{
85
  let $2=4;
86
  while ($2)
87
  {
88
    let $3=4;
89
    while ($3)
90
    {
91
      eval insert into t1 select $1, $2, $3, $1 ,$2, $3, key1, key2, key3, key4, filler1, filler2, filler3, filler4, filler5, filler6 from t0;
92
      dec $3;
93
    }
94
    dec $2;
95
  }
96
 dec $1;
97
}
98
99
--echo # Printing of many insert into t1 (...) values (....) disabled.
100
# Row retrieval tests
101
# -1 is used for values 'out of any range we are using'
102
# insert enough rows for index intersection to be used for (key1,key2)
103
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 100, 100,'key1-key2-key3-key4');
104
let $cnt=400;
105
while ($cnt)
106
{
107
  eval insert into t1 (key1, key2, key3, key4, filler1) values (100, -1, 100, -1,'key1-key3');
108
  dec $cnt;
109
}
110
let $cnt=400;
111
while ($cnt)
112
{
113
  eval insert into t1 (key1, key2, key3, key4, filler1) values (-1, 100, -1, 100,'key2-key4');
114
  dec $cnt;
115
}
116
--enable_query_log
117
alter table t1 enable keys;
118
select count(*) from t1;
119
120
# One row results tests for cases where a single row matches all conditions
121
explain select key1,key2 from t1 where key1=100 and key2=100;
122
select key1,key2 from t1 where key1=100 and key2=100;
123
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
124
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
125
126
# Several-rows results
127
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, -1, -1, 'key1-key2');
128
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 100, 100, 'key4-key3');
129
130
#  ROR-intersection, not covering
131
explain select key1,key2,filler1 from t1 where key1=100 and key2=100;
132
select key1,key2,filler1 from t1 where key1=100 and key2=100;
133
134
#  ROR-intersection, covering
135
explain select key1,key2 from t1 where key1=100 and key2=100;
136
select key1,key2 from t1 where key1=100 and key2=100;
137
138
#  ROR-union of ROR-intersections
139
explain select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
140
select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
141
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
142
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
143
144
#  3-way ROR-intersection
145
explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
146
select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100;
147
148
#  ROR-union(ROR-intersection, ROR-range)
149
insert into t1 (key1,key2,key3,key4,filler1) values (101,101,101,101, 'key1234-101');
150
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101;
151
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101;
152
153
# Run some ROR updates/deletes
154
select key1,key2, filler1 from t1 where key1=100 and key2=100;
155
update t1 set filler1='to be deleted' where key1=100 and key2=100;
156
update t1 set key1=200,key2=200 where key1=100 and key2=100;
157
delete from t1 where key1=200 and key2=200;
158
select key1,key2,filler1 from t1 where key2=100 and key2=200;
159
160
# ROR-union(ROR-intersection) with one of ROR-intersection giving empty
161
# results
162
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
163
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
164
165
delete from t1 where key3=100 and key4=100;
166
167
# ROR-union with all ROR-intersections giving empty results
168
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
169
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100;
170
171
# ROR-intersection with empty result
172
explain select key1,key2 from t1 where key1=100 and key2=100;
173
select key1,key2 from t1 where key1=100 and key2=100;
174
175
# ROR-union tests with various cases.
176
#  All scans returning duplicate rows:
177
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-1');
178
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-2');
179
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-3');
180
181
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
182
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
183
184
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, -1, 200,'key4');
185
186
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
187
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
188
189
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 200, -1,'key3');
190
191
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
192
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200;
193
194
##
195
## Optimizer tests
196
##
197
198
# Check that the shortest key is used for ROR-intersection, covering and non-covering.
199
explain select * from t1 where st_a=1 and st_b=1;
200
explain select st_a,st_b from t1 where st_a=1 and st_b=1;
201
202
# Check if "ingore index" syntax works
203
explain select st_a from t1 ignore index (st_a) where st_a=1 and st_b=1;
204
205
# Do many tests
206
# Check that keys that don't improve selectivity are skipped.
207
#
208
209
# Different value on 32 and 64 bit
210
--replace_result sta_swt12a sta_swt21a sta_swt12a, sta_swt12a,
211
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1;
212
213
explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1;
214
215
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
216
217
explain select * from t1 ignore index (sta_swt21a, stb_swt1a_2b)
218
  where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
219
220
explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b)
221
  where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
222
223
explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b, stb_swt1b)
224
  where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1;
225
226
explain select * from t1
227
  where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1;
228
229
explain select * from t1
230
  where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
231
232
explain select st_a from t1
233
  where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
234
235
explain select st_a from t1
236
  where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
237
238
drop table t0,t1;
239
240
# 'Partially' covered fields test
241
242
create table t2 (
243
  a char(10),
244
  b char(10),
245
  filler1 char(255),
246
  filler2 char(255),
247
  key(a(5)),
248
  key(b(5))
249
);
250
251
--disable_query_log
252
let $1=8;
253
while ($1)
254
{
255
  eval insert into t2 values (repeat(char($1+64), 8),repeat(char($1+64), 8),'filler1', 'filler2');
256
  dec $1;
257
}
258
insert into t2 select * from t2;
259
insert into t2 select * from t2;
260
--enable_query_log
261
262
# The table row buffer is reused. Fill it with rows that don't match.
263
select count(a) from t2 where a='BBBBBBBB';
264
select count(a) from t2 where b='BBBBBBBB';
265
266
# BUG#1:
267
--replace_result a a_or_b b a_or_b
268
explain select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA';
269
select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA';
270
select count(a) from t2 ignore index(a,b) where a='AAAAAAAA' and b='AAAAAAAA';
271
272
insert into t2 values ('ab', 'ab', 'uh', 'oh');
273
explain select a from t2 where a='ab';
274
drop table t2;
275
276
#
277
# BUG#25048 - ERROR 126 : Incorrect key file for table '.XXXX.MYI'; try to
278
#             repair it
279
#
280
CREATE TABLE t1(c1 INT, c2 INT DEFAULT 0, c3 CHAR(255) DEFAULT '',
281
KEY(c1), KEY(c2), KEY(c3));
282
INSERT INTO t1(c1) VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),
283
(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0);
284
INSERT INTO t1 VALUES(0,0,0);
285
CREATE TABLE t2(c1 int);
286
INSERT INTO t2 VALUES(1);
287
DELETE t1 FROM t1,t2 WHERE t1.c1=0 AND t1.c2=0;
288
SELECT * FROM t1;
289
DROP TABLE t1,t2;