1 # include/index_merge2.inc
6 # $engine_type -- storage engine to be tested
7 # has to be set before sourcing this script.
9 # Note: The comments/expectations refer to InnoDB.
10 # They might be not valid for other storage engines.
13 # 2006-08-02 ML test refactored
14 # old name was t/index_merge_innodb.test
15 # main code went into include/index_merge2.inc
18 --echo #---------------- Index merge
test 2 -------------------------------------------
20 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
23 drop
table if exists t1,t2;
39 eval insert into t1 values (200-$1, $1);
51 explain select * from t1 where key1 < 5 or key2 > 197;
53 select * from t1 where key1 < 5 or key2 > 197;
55 explain select * from t1 where key1 < 3 or key2 > 195;
56 select * from t1 where key1 < 3 or key2 > 195;
58 # Primary key as case-sensitive string with \0s.
59 # also make primary key be longer then max. index length of MyISAM.
60 alter
table t1 add str1 char (255) not null,
61 add zeroval
int not null default 0,
62 add str2
char (255) not null,
63 add str3
char (255) not null;
65 update t1 set str1='aaa', str2='bbb', str3=concat(key2, '-', key1 div 2, '_' ,if(key1 mod 2 = 0, 'a', '
A'));
67 alter
table t1 add primary key (str1, zeroval, str2, str3);
75 explain select * from t1 where key1 < 5 or key2 > 197;
77 select * from t1 where key1 < 5 or key2 > 197;
79 explain select * from t1 where key1 < 3 or key2 > 195;
80 select * from t1 where key1 < 3 or key2 > 195;
85 pk integer not null auto_increment primary key,
87 key2 integer not null,
97 eval insert into t1 (key1, key2, filler) values ($1/4, $1/8, 'filler-data');
103 -- disable_result_log
108 explain select pk from t1 where key1 = 1 and key2 = 1;
109 select pk from t1 where key2 = 1 and key1 = 1;
110 select pk from t1 ignore
index(key1,key2) where key2 = 1 and key1 = 1;
112 # More tests for BUG#5401.
115 pk
int primary key auto_increment,
127 index i1(key1a, key1b),
128 index i2(key2a, key2b),
129 index i3(key3a, key3b)
132 create
table t2 (a
int);
133 insert into t2 values (0),(1),(2),(3),(4),(NULL);
135 insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b)
136 select A.a, B.a, C.a, D.a, C.a, D.a from t2 A,t2 B,t2 C, t2 D;
137 insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b)
138 select key1a, key1b, key2a, key2b, key3a, key3b from t1;
139 insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b)
140 select key1a, key1b, key2a, key2b, key3a, key3b from t1;
142 select count(*) from t1;
145 -- disable_result_log
150 if ($index_merge_random_rows_in_EXPLAIN)
154 explain select count(*) from t1 where
155 key1a = 2 and key1b is null and key2a = 2 and key2b is null;
157 select count(*) from t1 where
158 key1a = 2 and key1b is null and key2a = 2 and key2b is null;
160 if ($index_merge_random_rows_in_EXPLAIN)
164 explain select count(*) from t1 where
165 key1a = 2 and key1b is null and key3a = 2 and key3b is null;
167 select count(*) from t1 where
168 key1a = 2 and key1b is null and key3a = 2 and key3b is null;
176 index idx2 (id1,id2),
179 insert into t1 values(1,
'20040101'), (2,
'20040102');
180 select * from t1 where id1 = 1 and id2=
'20040101';
185 drop
view if exists v1;
188 `oid`
int(11)
unsigned NOT NULL auto_increment,
189 `fk_bbk_niederlassung`
int(11)
unsigned NOT NULL,
190 `fk_wochentag`
int(11)
unsigned NOT NULL,
191 `uhrzeit_von` time NOT NULL COMMENT
'HH:MM',
192 `uhrzeit_bis` time NOT NULL COMMENT
'HH:MM',
193 `geloescht` tinyint(4) NOT NULL,
194 `version`
int(5) NOT NULL,
196 KEY `fk_bbk_niederlassung` (`fk_bbk_niederlassung`),
197 KEY `fk_wochentag` (`fk_wochentag`),
198 KEY `ix_version` (`version`)
199 ) DEFAULT CHARSET=latin1;
201 insert into t1 values
202 (1, 38, 1, '08:00:00', '13:00:00', 0, 1),
203 (2, 38, 2, '08:00:00', '13:00:00', 0, 1),
204 (3, 38, 3, '08:00:00', '13:00:00', 0, 1),
205 (4, 38, 4, '08:00:00', '13:00:00', 0, 1),
206 (5, 38, 5, '08:00:00', '13:00:00', 0, 1),
207 (6, 38, 5, '08:00:00', '13:00:00', 1, 2),
208 (7, 38, 3, '08:00:00', '13:00:00', 1, 2),
209 (8, 38, 1, '08:00:00', '13:00:00', 1, 2),
210 (9, 38, 2, '08:00:00', '13:00:00', 1, 2),
211 (10, 38, 4, '08:00:00', '13:00:00', 1, 2),
212 (11, 38, 1, '08:00:00', '13:00:00', 0, 3),
213 (12, 38, 2, '08:00:00', '13:00:00', 0, 3),
214 (13, 38, 3, '08:00:00', '13:00:00', 0, 3),
215 (14, 38, 4, '08:00:00', '13:00:00', 0, 3),
216 (15, 38, 5, '08:00:00', '13:00:00', 0, 3),
217 (16, 38, 4, '08:00:00', '13:00:00', 0, 4),
218 (17, 38, 5, '08:00:00', '13:00:00', 0, 4),
219 (18, 38, 1, '08:00:00', '13:00:00', 0, 4),
220 (19, 38, 2, '08:00:00', '13:00:00', 0, 4),
221 (20, 38, 3, '08:00:00', '13:00:00', 0, 4),
222 (21, 7, 1, '08:00:00', '13:00:00', 0, 1),
223 (22, 7, 2, '08:00:00', '13:00:00', 0, 1),
224 (23, 7, 3, '08:00:00', '13:00:00', 0, 1),
225 (24, 7, 4, '08:00:00', '13:00:00', 0, 1),
226 (25, 7, 5, '08:00:00', '13:00:00', 0, 1);
231 zeit1.fk_bbk_niederlassung AS fk_bbk_niederlassung,
232 zeit1.fk_wochentag AS fk_wochentag,
233 zeit1.uhrzeit_von AS uhrzeit_von,
234 zeit1.uhrzeit_bis AS uhrzeit_bis,
235 zeit1.geloescht AS geloescht,
236 zeit1.version AS version
241 (select max(zeit2.version) AS `max(version)`
244 ((zeit1.fk_bbk_niederlassung = zeit2.fk_bbk_niederlassung) and
245 (zeit1.fk_wochentag = zeit2.fk_wochentag) and
246 (zeit1.uhrzeit_von = zeit2.uhrzeit_von) and
247 (zeit1.uhrzeit_bis = zeit2.uhrzeit_bis)
251 and (zeit1.geloescht = 0);
253 select * from v1 where oid = 21;
258 t_cpac varchar(2) NOT NULL,
259 t_vers varchar(4) NOT NULL,
260 t_rele varchar(2) NOT NULL,
261 t_cust varchar(4) NOT NULL,
262 filler1
char(250)
default NULL,
263 filler2
char(250)
default NULL,
264 PRIMARY
KEY (t_cpac,t_vers,t_rele,t_cust),
265 UNIQUE
KEY IX_4 (t_cust,t_cpac,t_vers,t_rele),
266 KEY IX_5 (t_vers,t_rele,t_cust)
269 insert into t1 values
270 (
'tm',
'2.5 ',
'a ',
' ',
'',
''), (
'tm',
'2.5U',
'a ',
'stnd',
'',
''),
271 (
'da',
'3.3 ',
'b ',
' ',
'',
''), (
'da',
'3.3U',
'b ',
'stnd',
'',
''),
272 (
'tl',
'7.6 ',
'a ',
' ',
'',
''), (
'tt',
'7.6 ',
'a ',
' ',
'',
''),
273 (
'bc',
'B61 ',
'a ',
' ',
'',
''), (
'bp',
'B61 ',
'a ',
' ',
'',
''),
274 (
'ca',
'B61 ',
'a ',
' ',
'',
''), (
'ci',
'B61 ',
'a ',
' ',
'',
''),
275 (
'cp',
'B61 ',
'a ',
' ',
'',
''), (
'dm',
'B61 ',
'a ',
' ',
'',
''),
276 (
'ec',
'B61 ',
'a ',
' ',
'',
''), (
'ed',
'B61 ',
'a ',
' ',
'',
''),
277 (
'fm',
'B61 ',
'a ',
' ',
'',
''), (
'nt',
'B61 ',
'a ',
' ',
'',
''),
278 (
'qm',
'B61 ',
'a ',
' ',
'',
''), (
'tc',
'B61 ',
'a ',
' ',
'',
''),
279 (
'td',
'B61 ',
'a ',
' ',
'',
''), (
'tf',
'B61 ',
'a ',
' ',
'',
''),
280 (
'tg',
'B61 ',
'a ',
' ',
'',
''), (
'ti',
'B61 ',
'a ',
' ',
'',
''),
281 (
'tp',
'B61 ',
'a ',
' ',
'',
''), (
'ts',
'B61 ',
'a ',
' ',
'',
''),
282 (
'wh',
'B61 ',
'a ',
' ',
'',
''), (
'bc',
'B61U',
'a ',
'stnd',
'',
''),
283 (
'bp',
'B61U',
'a ',
'stnd',
'',
''), (
'ca',
'B61U',
'a ',
'stnd',
'',
''),
284 (
'ci',
'B61U',
'a ',
'stnd',
'',
''), (
'cp',
'B61U',
'a ',
'stnd',
'',
''),
285 (
'dm',
'B61U',
'a ',
'stnd',
'',
''), (
'ec',
'B61U',
'a ',
'stnd',
'',
''),
286 (
'fm',
'B61U',
'a ',
'stnd',
'',
''), (
'nt',
'B61U',
'a ',
'stnd',
'',
''),
287 (
'qm',
'B61U',
'a ',
'stnd',
'',
''), (
'tc',
'B61U',
'a ',
'stnd',
'',
''),
288 (
'td',
'B61U',
'a ',
'stnd',
'',
''), (
'tf',
'B61U',
'a ',
'stnd',
'',
''),
289 (
'tg',
'B61U',
'a ',
'stnd',
'',
''), (
'ti',
'B61U',
'a ',
'stnd',
'',
''),
290 (
'tp',
'B61U',
'a ',
'stnd',
'',
''), (
'ts',
'B61U',
'a ',
'stnd',
'',
''),
291 (
'wh',
'B61U',
'a ',
'stnd',
'',
'');
292 show create
table t1;
294 select t_vers,t_rele,t_cust,filler1 from t1 where t_vers =
'7.6';
295 select t_vers,t_rele,t_cust,filler1 from t1 where t_vers =
'7.6'
296 and t_rele=
'a' and t_cust =
' ';
300 # BUG#19021: Crash in index_merge/ROR-intersection optimizer under
301 # specific circumstances.
303 pk
int(11) not null auto_increment,
304 a
int(11) not null
default '0',
305 b
int(11) not null
default '0',
306 c
int(11) not null
default '0',
308 filler1 datetime, filler2 varchar(15),
311 kp1 varchar(4), kp2 varchar(7),
312 kp3 varchar(2), kp4 varchar(4),
319 key idx3(kp1,kp2,kp3,kp4,kp5)
320 ) default charset=latin1;
322 set @fill= uncompress(unhex(concat(
323 'F91D0000789CDD993D6FDB301086F7FE0A6D4E0105B8E3F1335D5BA028DA0EEDE28E1D320408',
324 '52A0713BF4D7571FB62C51A475924839080307B603E77DEE787C8FA41F9E9EEF7F1F8A87A7C3',
325 'AFE280C5DF9F8F7FEE9F8B1B2CB114D6902E918455245DB91300FA16E42D5201FA4EE29DA05D',
326 'B9FB3718A33718A3FA8C30AEFAFDE1F317D016AA67BA7A60FDE45BF5F8BA7B5BDE8812AA9F1A',
327 '069DB03C9804346644F3A3A6A1338DB572756A3C4D1BCC804CABF912C654AE9BB855A2B85962',
328 '3A479259CAE6A86C0411D01AE5483581EDCBD9A39C45252D532E533979EB9F82E971D979BDB4',
329 '8531105670740AFBFD1E34AAB0029E4AD0A1D46A6D0946A21A16038A5CD965CD2D524673F712',
330 '20C304477315CE18405EAF9BD0AFFEAC74FDA14F1FBF5BD34C769D73FBBEDF4750ADD4E5A99C',
331 '5C8DC04934AFA275D483D536D174C11B12AF27F8F888B41B6FC9DBA569E1FD7BD72D698130B7',
332 '91B23A98803512B3D31881E8DCDA2AC1754E3644C4BB3A8466750B911681274A39E35E8624B7',
333 '444A42AC1213F354758E3CF1A4CDD5A688C767CF1B11ABC5867CB15D8A18E0B91E9EC275BB94',
334 '58F33C2936F64690D55BC29E4A293D95A798D84217736CEAAA538CE1354269EE2162053FBC66',
335 '496D90CB53323CB279D3A6AF651B4B22B9E430743D83BE48E995A09D4FC9871C22D8D189B945',
336 '706911BCB8C3C774B9C08D2FC6ED853ADACA37A14A4CB2E027630E5B80ECACD939431B1CDF62',
337 '7D71487536EA2C678F59685E91F4B6C144BCCB94C1EBA9FA6F5552DDCA4E4539BE326A2720CB',
338 '45ED028EB3616AC93C46E775FEA9FA6DA7CFCEC6DEBA5FCD1F915EED4D983BDDB881528AD9AB',
339 '43C1576F29AAB35BDFBC21D422F52B307D350589D45225A887AC46C8EDD72D99EC3ED2E1BCEF',
340 '7AF26FC4C74097B6768A5EDAFA660CC64278F7E63F99AC954B')));
341 prepare x from @fill;
343 deallocate prepare x;
346 SELECT COUNT(*) FROM t1 WHERE b = 0 AND a = 0 AND c = 13286427 AND
347 kp1='279' AND kp2='ELM0678' AND kp3='6' AND kp4='10' AND kp5 = 'R ';
351 # BUG#21277: Index Merge/sort_union: wrong query results
355 key2
int not null
default 0,
356 key3
int not null
default 0
359 insert into t1(key1) values (1),(2),(3),(4),(5),(6),(7),(8);
365 eval insert into t1 (key1) select key1+@d from t1;
372 update t1 set key2=key1,key3=key1;
375 -- disable_result_log
380 if ($index_merge_random_rows_in_EXPLAIN)
384 # to test the bug, the following must use "sort_union":
385 explain select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40);
386 select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40);
390 --echo # Bug#56423: Different count with SELECT and CREATE SELECT queries
403 INSERT INTO t1 VALUES
410 -- disable_result_log
418 WHERE c = 1 AND b = 1 AND d = 1;
420 CREATE
TABLE t2 ( a INT )
423 WHERE c = 1 AND b = 1 AND d = 1;
430 INSERT INTO t1 VALUES (1, 2), (1, 2), (1, 2), (1, 2);
431 SELECT * FROM t1 FORCE INDEX(a, b) WHERE a = 1 AND b = 2;
435 --echo
# Code coverage of fix.
436 CREATE
TABLE t1 ( a INT NOT NULL AUTO_INCREMENT PRIMARY
KEY, b INT);
437 INSERT INTO t1 (b) VALUES (1);
438 UPDATE t1 SET b = 2 WHERE a = 1;
441 CREATE
TABLE t2 ( a INT NOT NULL AUTO_INCREMENT PRIMARY
KEY, b VARCHAR(1) );
442 INSERT INTO t2 (b) VALUES ('a');
443 UPDATE t2 SET b = 'b' WHERE a = 1;
449 --echo # BUG#13970015: ASSERT `MIN_ENDP || MAX_ENDP
' FAILED IN
450 --echo # HANDLER::MULTI_RANGE_READ_INFO_CONST
455 col_int_key INT NOT NULL,
456 col_varchar_key VARCHAR(1) NOT NULL,
458 KEY col_int_key (col_int_key),
459 KEY col_varchar_key (col_varchar_key,col_int_key)
462 INSERT INTO t1 VALUES (1,1,'a
'), (2,2,'b
');
465 -- disable_result_log
473 WHERE col_varchar_key >= 'l
' OR
474 (((pk BETWEEN 141 AND 141) OR col_varchar_key <> 'l
')
475 AND ((pk BETWEEN 141 AND 141) OR (col_int_key > 141)));
479 WHERE col_varchar_key >= 'l
' OR
480 (((pk BETWEEN 141 AND 141) OR col_varchar_key <> 'l
')
481 AND ((pk BETWEEN 141 AND 141) OR (col_int_key > 141)));