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 STORAGE_ENGINE = $engine_type;
23
drop table if exists t1,t2;
40
eval insert into t1 values (200-$1, $1);
47
explain select * from t1 where key1 < 5 or key2 > 197;
49
select * from t1 where key1 < 5 or key2 > 197;
51
explain select * from t1 where key1 < 3 or key2 > 195;
52
select * from t1 where key1 < 3 or key2 > 195;
54
# Primary key as case-sensitive string with \0s.
55
# also make primary key be longer then max. index length of MyISAM.
56
ALTER TABLE t1 ADD str1 CHAR (100) DEFAULT "catfood" NOT NULL,
57
ADD zeroval INT NOT NULL DEFAULT 0,
58
ADD str2 CHAR (100) DEFAULT "bird" NOT NULL,
59
ADD str3 CHAR (100) DEFAULT "dog" NOT NULL;
61
UPDATE t1 SET str1='aaa', str2='bbb', str3=concat(key2, '-', key1 div 2, '_' ,if(key1 mod 2 = 0, 'a', 'A'));
63
ALTER TABLE t1 ADD PRIMARY KEY (str1, zeroval, str2, str3);
65
EXPLAIN SELECT * FROM t1 WHERE key1 < 5 OR key2 > 197;
67
select * from t1 where key1 < 5 or key2 > 197;
69
explain select * from t1 where key1 < 3 or key2 > 195;
70
select * from t1 where key1 < 3 or key2 > 195;
75
pk integer not null auto_increment primary key,
77
key2 integer not null,
88
eval insert into t1 (key1, key2, filler) values ($1/4, $1/8, 'filler-data');
93
explain select pk from t1 where key1 = 1 and key2 = 1;
94
select pk from t1 where key2 = 1 and key1 = 1;
95
select pk from t1 ignore index(key1,key2) where key2 = 1 and key1 = 1;
97
# More tests for BUG#5401.
100
pk int primary key auto_increment,
112
index i1(key1a, key1b),
113
index i2(key2a, key2b),
114
index i3(key3a, key3b)
117
create table t2 (a int);
118
insert into t2 values (0),(1),(2),(3),(4),(NULL);
120
insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b)
121
select A.a, B.a, C.a, D.a, C.a, D.a from t2 A CROSS JOIN t2 B CROSS JOIN t2 C CROSS JOIN t2 D;
122
insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b)
123
select key1a, key1b, key2a, key2b, key3a, key3b from t1;
124
insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b)
125
select key1a, key1b, key2a, key2b, key3a, key3b from t1;
127
select count(*) from t1;
130
explain select count(*) from t1 where
131
key1a = 2 and key1b is null and key2a = 2 and key2b is null;
133
select count(*) from t1 where
134
key1a = 2 and key1b is null and key2a = 2 and key2b is null;
137
explain select count(*) from t1 where
138
key1a = 2 and key1b is null and key3a = 2 and key3b is null;
140
select count(*) from t1 where
141
key1a = 2 and key1b is null and key3a = 2 and key3b is null;
149
index idx2 (id1,id2),
152
insert into t1 values(1,'20040101'), (2,'20040102');
153
select * from t1 where id1 = 1 and id2= '20040101';
156
# BUG#21277: Index Merge/sort_union: wrong query results
160
key2 int not null default 0,
161
key3 int not null default 0
164
insert into t1(key1) values (1),(2),(3),(4),(5),(6),(7),(8);
171
eval insert into t1 (key1) select key1+@d from t1;
177
alter table t1 add index i2(key2);
178
alter table t1 add index i3(key3);
179
update t1 set key2=key1,key3=key1;
181
# to test the bug, the following must use "sort_union":
182
explain select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40);
183
select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40);
187
--echo # Bug#56423: Different count with SELECT and CREATE SELECT queries
200
INSERT INTO t1 VALUES
209
WHERE c = 1 AND b = 1 AND d = 1;
211
CREATE TABLE t2 ( a INT )
214
WHERE c = 1 AND b = 1 AND d = 1;
220
CREATE TABLE t1( a INT, b INT, KEY(a), KEY(b) );
221
INSERT INTO t1 VALUES (1, 2), (1, 2), (1, 2), (1, 2);
222
SELECT * FROM t1 FORCE INDEX(a, b) WHERE a = 1 AND b = 2;
226
--echo # Code coverage of fix.
227
CREATE TABLE t1 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT);
228
INSERT INTO t1 (b) VALUES (1);
229
UPDATE t1 SET b = 2 WHERE a = 1;
232
CREATE TABLE t2 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(1) );
233
INSERT INTO t2 (b) VALUES ('a');
234
UPDATE t2 SET b = 'b' WHERE a = 1;