1 # include/index_merge_ror.inc
3 # ROR-index_merge tests.
6 # $engine_type -- storage engine to be tested
7 # has to be set before sourcing this script.
9 # Note: The comments/expectations refer to MyISAM.
10 # They might be not valid for other storage engines.
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
18 --echo #---------------- ROR-index_merge tests -----------------------
20 eval SET SESSION STORAGE_ENGINE = $engine_type;
23 drop table if exists t0,t1,t2;
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,
32 st_b int not null default 0,
33 swt1b int not null default 0,
34 swt2b int not null default 0,
36 /* fields/keys for row retrieval tests */
42 /* make rows much bigger then keys */
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),
57 key stb_swt1a_2b(st_b,swt1b,swt2a),
58 key stb_swt1b(st_b,swt1b),
68 create table t0 as select * from t1;
70 --echo # Printing of many insert into t0 values (....) disabled.
74 eval insert into t0 values (1, 2, 3, 1, 2, 3, 0, 0, 0, 0, 'data1', 'data2', 'data3', 'data4', 'data5', 'data6');
79 alter table t1 disable keys;
81 --echo # Printing of many insert into t1 select .... from t0 disabled.
91 eval insert into t1 select $1, $2, $3, $1 ,$2, $3, key1, key2, key3, key4, filler1, filler2, filler3, filler4, filler5, filler6 from t0;
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');
107 eval insert into t1 (key1, key2, key3, key4, filler1) values (100, -1, 100, -1,'key1-key3');
113 eval insert into t1 (key1, key2, key3, key4, filler1) values (-1, 100, -1, 100,'key2-key4');
117 alter table t1 enable keys;
118 select count(*) from t1;
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;
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');
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;
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;
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;
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;
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;
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;
160 # ROR-union(ROR-intersection) with one of ROR-intersection giving empty
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;
165 delete from t1 where key3=100 and key4=100;
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;
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;
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');
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;
184 insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, -1, 200,'key4');
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;
189 insert into t1 (key1, key2, key3, key4, filler1) values (-1, -1, 200, -1,'key3');
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;
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;
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;
206 # Check that keys that don't improve selectivity are skipped.
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;
213 explain select * from t1 where st_b=1 and swt1b=1 and swt2b=1;
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;
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;
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;
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;
226 explain select * from t1
227 where st_a=1 and swt1a=1 and swt2a=1 and st_b=1 and swt1b=1;
229 explain select * from t1
230 where st_a=1 and swt1a=1 and st_b=1 and swt1b=1 and swt1b=1;
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;
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;
240 # 'Partially' covered fields test
255 eval insert into t2 values (repeat(char($1+64), 8),repeat(char($1+64), 8),'filler1', 'filler2');
258 insert into t2 select * from t2;
259 insert into t2 select * from t2;
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';
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';
272 insert into t2 values ('ab', 'ab', 'uh', 'oh');
273 explain select a from t2 where a='ab';
277 # BUG#25048 - ERROR 126 : Incorrect key file for table '.XXXX.MYI'; try to
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;