1
by brian
clean slate |
1 |
# include/index_merge2.inc |
2 |
#
|
|
3 |
# 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 InnoDB. |
|
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_innodb.test |
|
15 |
# main code went into include/index_merge2.inc |
|
16 |
#
|
|
17 |
||
18 |
--echo #---------------- Index merge test 2 ------------------------------------------- |
|
19 |
||
20 |
eval SET SESSION STORAGE_ENGINE = $engine_type; |
|
21 |
||
22 |
--disable_warnings |
|
23 |
drop table if exists t1,t2; |
|
24 |
--enable_warnings |
|
25 |
||
26 |
create table t1 |
|
27 |
(
|
|
28 |
key1 int not null, |
|
29 |
key2 int not null, |
|
30 |
||
31 |
INDEX i1(key1), |
|
32 |
INDEX i2(key2) |
|
33 |
);
|
|
34 |
||
35 |
--disable_query_log |
|
36 |
let $1=200; |
|
37 |
while ($1) |
|
38 |
{
|
|
39 |
eval insert into t1 values (200-$1, $1); |
|
40 |
dec $1; |
|
41 |
}
|
|
42 |
--enable_query_log |
|
43 |
||
44 |
# No primary key |
|
45 |
explain select * from t1 where key1 < 5 or key2 > 197; |
|
46 |
||
47 |
select * from t1 where key1 < 5 or key2 > 197; |
|
48 |
||
49 |
explain select * from t1 where key1 < 3 or key2 > 195; |
|
50 |
select * from t1 where key1 < 3 or key2 > 195; |
|
51 |
||
52 |
# Primary key as case-sensitive string with \0s. |
|
53 |
# also make primary key be longer then max. index length of MyISAM. |
|
54 |
alter table t1 add str1 char (255) not null, |
|
55 |
add zeroval int not null default 0, |
|
56 |
add str2 char (255) not null, |
|
57 |
add str3 char (255) not null; |
|
58 |
||
59 |
update t1 set str1='aaa', str2='bbb', str3=concat(key2, '-', key1 div 2, '_' ,if(key1 mod 2 = 0, 'a', 'A')); |
|
60 |
||
61 |
alter table t1 add primary key (str1, zeroval, str2, str3); |
|
62 |
||
63 |
explain select * from t1 where key1 < 5 or key2 > 197; |
|
64 |
||
65 |
select * from t1 where key1 < 5 or key2 > 197; |
|
66 |
||
67 |
explain select * from t1 where key1 < 3 or key2 > 195; |
|
68 |
select * from t1 where key1 < 3 or key2 > 195; |
|
69 |
||
70 |
# Test for BUG#5401 |
|
71 |
drop table t1; |
|
72 |
create table t1 ( |
|
73 |
pk integer not null auto_increment primary key, |
|
74 |
key1 integer, |
|
75 |
key2 integer not null, |
|
76 |
filler char (200), |
|
77 |
index (key1), |
|
78 |
index (key2) |
|
79 |
);
|
|
80 |
show warnings; |
|
81 |
--disable_query_log |
|
82 |
let $1=30; |
|
83 |
while ($1) |
|
84 |
{
|
|
85 |
eval insert into t1 (key1, key2, filler) values ($1/4, $1/8, 'filler-data'); |
|
86 |
dec $1; |
|
87 |
}
|
|
88 |
--enable_query_log |
|
89 |
explain select pk from t1 where key1 = 1 and key2 = 1; |
|
90 |
select pk from t1 where key2 = 1 and key1 = 1; |
|
91 |
select pk from t1 ignore index(key1,key2) where key2 = 1 and key1 = 1; |
|
92 |
||
93 |
# More tests for BUG#5401. |
|
94 |
drop table t1; |
|
95 |
create table t1 ( |
|
96 |
pk int primary key auto_increment, |
|
97 |
key1a int, |
|
98 |
key2a int, |
|
99 |
key1b int, |
|
100 |
key2b int, |
|
101 |
dummy1 int, |
|
102 |
dummy2 int, |
|
103 |
dummy3 int, |
|
104 |
dummy4 int, |
|
105 |
key3a int, |
|
106 |
key3b int, |
|
107 |
filler1 char (200), |
|
108 |
index i1(key1a, key1b), |
|
109 |
index i2(key2a, key2b), |
|
110 |
index i3(key3a, key3b) |
|
111 |
);
|
|
112 |
||
113 |
create table t2 (a int); |
|
114 |
insert into t2 values (0),(1),(2),(3),(4),(NULL); |
|
115 |
||
116 |
insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b) |
|
117 |
select A.a, B.a, C.a, D.a, C.a, D.a from t2 A,t2 B,t2 C, t2 D; |
|
118 |
insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b) |
|
119 |
select key1a, key1b, key2a, key2b, key3a, key3b from t1; |
|
120 |
insert into t1 (key1a, key1b, key2a, key2b, key3a, key3b) |
|
121 |
select key1a, key1b, key2a, key2b, key3a, key3b from t1; |
|
122 |
analyze table t1; |
|
123 |
select count(*) from t1; |
|
124 |
||
125 |
explain select count(*) from t1 where |
|
126 |
key1a = 2 and key1b is null and key2a = 2 and key2b is null; |
|
127 |
||
128 |
select count(*) from t1 where |
|
129 |
key1a = 2 and key1b is null and key2a = 2 and key2b is null; |
|
130 |
||
131 |
explain select count(*) from t1 where |
|
132 |
key1a = 2 and key1b is null and key3a = 2 and key3b is null; |
|
133 |
||
134 |
select count(*) from t1 where |
|
135 |
key1a = 2 and key1b is null and key3a = 2 and key3b is null; |
|
136 |
||
137 |
drop table t1,t2; |
|
138 |
||
139 |
# Test for BUG#8441 |
|
140 |
create table t1 ( |
|
141 |
id1 int, |
|
142 |
id2 date , |
|
143 |
index idx2 (id1,id2), |
|
144 |
index idx1 (id2) |
|
145 |
);
|
|
146 |
insert into t1 values(1,'20040101'), (2,'20040102'); |
|
147 |
select * from t1 where id1 = 1 and id2= '20040101'; |
|
148 |
drop table t1; |
|
149 |
||
150 |
# BUG#21277: Index Merge/sort_union: wrong query results |
|
151 |
create table t1 |
|
152 |
(
|
|
153 |
key1 int not null, |
|
154 |
key2 int not null default 0, |
|
155 |
key3 int not null default 0 |
|
156 |
);
|
|
157 |
||
158 |
insert into t1(key1) values (1),(2),(3),(4),(5),(6),(7),(8); |
|
159 |
||
160 |
let $1=7; |
|
161 |
set @d=8; |
|
162 |
while ($1) |
|
163 |
{
|
|
164 |
eval insert into t1 (key1) select key1+@d from t1; |
|
165 |
eval set @d=@d*2; |
|
166 |
dec $1; |
|
167 |
}
|
|
168 |
||
169 |
alter table t1 add index i2(key2); |
|
170 |
alter table t1 add index i3(key3); |
|
171 |
update t1 set key2=key1,key3=key1; |
|
172 |
||
173 |
# to test the bug, the following must use "sort_union": |
|
174 |
explain select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40); |
|
175 |
select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40); |
|
176 |
drop table t1; |