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; |
|
910.4.13
by Stewart Smith
batch up more INSERTs into transactions to help tests run quicker. |
72 |
begin; |
1
by brian
clean slate |
73 |
while ($cnt) |
74 |
{
|
|
75 |
eval insert into t0 values (1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 'data1', 'data2', 'data3', 'data4', 'data5', 'data6'); |
|
76 |
dec $cnt; |
|
77 |
}
|
|
910.4.13
by Stewart Smith
batch up more INSERTs into transactions to help tests run quicker. |
78 |
commit; |
1
by brian
clean slate |
79 |
--enable_query_log |
80 |
||
81 |
alter table t1 disable keys; |
|
82 |
--disable_query_log |
|
83 |
--echo # Printing of many insert into t1 select .... from t0 disabled. |
|
84 |
let $1=4; |
|
910.4.13
by Stewart Smith
batch up more INSERTs into transactions to help tests run quicker. |
85 |
begin; |
1
by brian
clean slate |
86 |
while ($1) |
87 |
{
|
|
88 |
let $2=4; |
|
89 |
while ($2) |
|
90 |
{
|
|
91 |
let $3=4; |
|
92 |
while ($3) |
|
93 |
{
|
|
94 |
eval insert into t1 select $1, $2, $3, $1 ,$2, $3, key1, key2, key3, key4, filler1, filler2, filler3, filler4, filler5, filler6 from t0; |
|
95 |
dec $3; |
|
96 |
}
|
|
97 |
dec $2; |
|
98 |
}
|
|
99 |
dec $1; |
|
100 |
}
|
|
910.4.13
by Stewart Smith
batch up more INSERTs into transactions to help tests run quicker. |
101 |
commit; |
1
by brian
clean slate |
102 |
--echo # Printing of many insert into t1 (...) values (....) disabled. |
103 |
# Row retrieval tests |
|
104 |
# -1 is used for values 'out of any range we are using' |
|
105 |
# insert enough rows for index intersection to be used for (key1,key2) |
|
910.4.13
by Stewart Smith
batch up more INSERTs into transactions to help tests run quicker. |
106 |
begin; |
1
by brian
clean slate |
107 |
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 100, 100,'key1-key2-key3-key4'); |
108 |
let $cnt=400; |
|
109 |
while ($cnt) |
|
110 |
{
|
|
111 |
eval insert into t1 (key1, key2, key3, key4, filler1) values (100, -1, 100, -1,'key1-key3'); |
|
112 |
dec $cnt; |
|
113 |
}
|
|
114 |
let $cnt=400; |
|
115 |
while ($cnt) |
|
116 |
{
|
|
117 |
eval insert into t1 (key1, key2, key3, key4, filler1) values (-1, 100, -1, 100,'key2-key4'); |
|
118 |
dec $cnt; |
|
119 |
}
|
|
910.4.13
by Stewart Smith
batch up more INSERTs into transactions to help tests run quicker. |
120 |
commit; |
1
by brian
clean slate |
121 |
--enable_query_log |
122 |
alter table t1 enable keys; |
|
123 |
select count(*) from t1; |
|
124 |
||
125 |
# One row results tests for cases where a single row matches all conditions |
|
126 |
explain select key1,key2 from t1 where key1=100 and key2=100; |
|
127 |
select key1,key2 from t1 where key1=100 and key2=100; |
|
128 |
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
129 |
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
130 |
||
131 |
# Several-rows results |
|
132 |
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, -1, -1, 'key1-key2'); |
|
133 |
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 100, 100, 'key4-key3'); |
|
134 |
||
135 |
# ROR-intersection, not covering |
|
136 |
explain select key1,key2,filler1 from t1 where key1=100 and key2=100; |
|
137 |
select key1,key2,filler1 from t1 where key1=100 and key2=100; |
|
138 |
||
139 |
# ROR-intersection, covering |
|
140 |
explain select key1,key2 from t1 where key1=100 and key2=100; |
|
141 |
select key1,key2 from t1 where key1=100 and key2=100; |
|
142 |
||
143 |
# ROR-union of ROR-intersections |
|
144 |
explain select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
145 |
select key1,key2,key3,key4 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
146 |
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
147 |
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
148 |
||
149 |
# 3-way ROR-intersection |
|
150 |
explain select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100; |
|
151 |
select key1,key2,key3 from t1 where key1=100 and key2=100 and key3=100; |
|
152 |
||
153 |
# ROR-union(ROR-intersection, ROR-range) |
|
154 |
insert into t1 (key1,key2,key3,key4,filler1) values (101,101,101,101, 'key1234-101'); |
|
155 |
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101; |
|
156 |
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=101; |
|
157 |
||
158 |
# Run some ROR updates/deletes |
|
159 |
select key1,key2, filler1 from t1 where key1=100 and key2=100; |
|
160 |
update t1 set filler1='to be deleted' where key1=100 and key2=100; |
|
161 |
update t1 set key1=200,key2=200 where key1=100 and key2=100; |
|
162 |
delete from t1 where key1=200 and key2=200; |
|
163 |
select key1,key2,filler1 from t1 where key2=100 and key2=200; |
|
164 |
||
165 |
# ROR-union(ROR-intersection) with one of ROR-intersection giving empty |
|
166 |
# results |
|
167 |
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
168 |
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
169 |
||
170 |
delete from t1 where key3=100 and key4=100; |
|
171 |
||
172 |
# ROR-union with all ROR-intersections giving empty results |
|
173 |
explain select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
174 |
select key1,key2,key3,key4,filler1 from t1 where key1=100 and key2=100 or key3=100 and key4=100; |
|
175 |
||
176 |
# ROR-intersection with empty result |
|
177 |
explain select key1,key2 from t1 where key1=100 and key2=100; |
|
178 |
select key1,key2 from t1 where key1=100 and key2=100; |
|
179 |
||
180 |
# ROR-union tests with various cases. |
|
181 |
# All scans returning duplicate rows: |
|
182 |
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-1'); |
|
183 |
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-2'); |
|
184 |
insert into t1 (key1, key2, key3, key4, filler1) values (100, 100, 200, 200,'key1-key2-key3-key4-3'); |
|
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, -1, 200,'key4'); |
|
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 |
insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 200, -1,'key3'); |
|
195 |
||
196 |
explain select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200; |
|
197 |
select key1,key2,key3,key4,filler1 from t1 where key3=200 or (key1=100 and key2=100) or key4=200; |
|
198 |
||
199 |
##
|
|
200 |
## Optimizer tests |
|
201 |
##
|
|
202 |
||
203 |
# Check that the shortest key is used for ROR-intersection, covering and non-covering. |
|
204 |
explain select * from t1 where st_a=1 and st_b=1; |
|
205 |
explain select st_a,st_b from t1 where st_a=1 and st_b=1; |
|
206 |
||
207 |
# Check if "ingore index" syntax works |
|
208 |
explain select st_a from t1 ignore index (st_a) where st_a=1 and st_b=1; |
|
209 |
||
210 |
# Do many tests |
|
211 |
# Check that keys that don't improve selectivity are skipped. |
|
212 |
#
|
|
213 |
||
214 |
# Different value on 32 and 64 bit |
|
215 |
--replace_result sta_swt12a sta_swt21a sta_swt12a, sta_swt12a, |
|
216 |
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1; |
|
217 |
||
218 |
explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1; |
|
219 |
||
220 |
explain select * from t1 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; |
|
221 |
||
222 |
explain select * from t1 ignore index (sta_swt21a, stb_swt1a_2b) |
|
223 |
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; |
|
224 |
||
225 |
explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b) |
|
226 |
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; |
|
227 |
||
228 |
explain select * from t1 ignore index (sta_swt21a, sta_swt12a, stb_swt1a_2b, stb_swt1b) |
|
229 |
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1 and swt2b=1; |
|
230 |
||
231 |
explain select * from t1 |
|
232 |
where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1; |
|
233 |
||
234 |
explain select * from t1 |
|
235 |
where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1; |
|
236 |
||
237 |
explain select st_a from t1 |
|
238 |
where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1; |
|
239 |
||
240 |
explain select st_a from t1 |
|
241 |
where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1; |
|
242 |
||
243 |
drop table t0,t1; |
|
244 |
||
245 |
# 'Partially' covered fields test |
|
246 |
||
247 |
create table t2 ( |
|
248 |
a char(10), |
|
249 |
b char(10), |
|
250 |
filler1 char(255), |
|
251 |
filler2 char(255), |
|
252 |
key(a(5)), |
|
253 |
key(b(5)) |
|
254 |
);
|
|
255 |
||
256 |
--disable_query_log |
|
257 |
let $1=8; |
|
910.4.13
by Stewart Smith
batch up more INSERTs into transactions to help tests run quicker. |
258 |
begin; |
1
by brian
clean slate |
259 |
while ($1) |
260 |
{
|
|
261 |
eval insert into t2 values (repeat(char($1+64), 8),repeat(char($1+64), 8),'filler1', 'filler2'); |
|
262 |
dec $1; |
|
263 |
}
|
|
264 |
insert into t2 select * from t2; |
|
265 |
insert into t2 select * from t2; |
|
910.4.13
by Stewart Smith
batch up more INSERTs into transactions to help tests run quicker. |
266 |
commit; |
1
by brian
clean slate |
267 |
--enable_query_log |
268 |
||
269 |
# The table row buffer is reused. Fill it with rows that don't match. |
|
270 |
select count(a) from t2 where a='BBBBBBBB'; |
|
271 |
select count(a) from t2 where b='BBBBBBBB'; |
|
272 |
||
273 |
# BUG#1: |
|
274 |
--replace_result a a_or_b b a_or_b |
|
275 |
explain select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA'; |
|
276 |
select count(a) from t2 where a='AAAAAAAA' and b='AAAAAAAA'; |
|
277 |
select count(a) from t2 ignore index(a,b) where a='AAAAAAAA' and b='AAAAAAAA'; |
|
278 |
||
279 |
insert into t2 values ('ab', 'ab', 'uh', 'oh'); |
|
280 |
explain select a from t2 where a='ab'; |
|
281 |
drop table t2; |
|
282 |
||
283 |
#
|
|
284 |
# BUG#25048 - ERROR 126 : Incorrect key file for table '.XXXX.MYI'; try to |
|
285 |
# repair it |
|
286 |
#
|
|
287 |
CREATE TABLE t1(c1 INT, c2 INT DEFAULT 0, c3 CHAR(255) DEFAULT '', |
|
288 |
KEY(c1), KEY(c2), KEY(c3)); |
|
289 |
INSERT INTO t1(c1) VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0), |
|
290 |
(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0),(0); |
|
291 |
INSERT INTO t1 VALUES(0,0,0); |
|
292 |
CREATE TABLE t2(c1 int); |
|
293 |
INSERT INTO t2 VALUES(1); |
|
294 |
DELETE t1 FROM t1,t2 WHERE t1.c1=0 AND t1.c2=0; |
|
295 |
SELECT * FROM t1; |
|
296 |
DROP TABLE t1,t2; |