~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/include/index_merge2.inc

  • Committer: Moriyoshi Koizumi
  • Date: 2008-11-15 18:36:31 UTC
  • mto: (584.1.5 devel)
  • mto: This revision was merged to the branch mainline in revision 588.
  • Revision ID: mozo@mozo.jp-20081115183631-81d0clowyot42mk7
Incorporating changes proposed by mtaylor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
begin;
38
 
while ($1)
39
 
{
40
 
  eval insert into t1 values (200-$1, $1);
41
 
  dec $1;
42
 
}
43
 
commit;
44
 
--enable_query_log
45
 
 
46
 
# No primary key
47
 
explain select * from t1 where key1 < 5 or key2 > 197;
48
 
 
49
 
select * from t1 where key1 < 5 or key2 > 197;
50
 
 
51
 
explain select * from t1 where key1 < 3 or key2 > 195;
52
 
select * from t1 where key1 < 3 or key2 > 195;
53
 
 
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;
60
 
 
61
 
UPDATE t1 SET str1='aaa', str2='bbb', str3=concat(key2, '-', key1 div 2, '_' ,if(key1 mod 2 = 0, 'a', 'A'));
62
 
 
63
 
ALTER TABLE t1 ADD PRIMARY KEY (str1, zeroval, str2, str3);
64
 
 
65
 
EXPLAIN SELECT * FROM t1 WHERE key1 < 5 OR key2 > 197;
66
 
 
67
 
select * from t1 where key1 < 5 or key2 > 197;
68
 
 
69
 
explain select * from t1 where key1 < 3 or key2 > 195;
70
 
select * from t1 where key1 < 3 or key2 > 195;
71
 
 
72
 
# Test for BUG#5401
73
 
drop table t1;
74
 
create table t1 (
75
 
  pk    integer not null auto_increment primary key,
76
 
  key1  integer,
77
 
  key2  integer not null,
78
 
  filler char  (200),
79
 
  index (key1),
80
 
  index (key2)
81
 
);
82
 
show warnings;
83
 
--disable_query_log
84
 
let $1=30;
85
 
begin;
86
 
while ($1)
87
 
{
88
 
  eval insert into t1 (key1, key2, filler) values ($1/4, $1/8, 'filler-data');
89
 
  dec $1;
90
 
}
91
 
commit;
92
 
--enable_query_log
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;
96
 
 
97
 
# More tests for BUG#5401.
98
 
drop table t1;
99
 
create table t1 (
100
 
  pk int primary key auto_increment,
101
 
  key1a  int,
102
 
  key2a  int,
103
 
  key1b  int,
104
 
  key2b  int,
105
 
  dummy1 int,
106
 
  dummy2 int,
107
 
  dummy3 int,
108
 
  dummy4 int,
109
 
  key3a  int,
110
 
  key3b  int,
111
 
  filler1 char (200),
112
 
  index i1(key1a, key1b),
113
 
  index i2(key2a, key2b),
114
 
  index i3(key3a, key3b)
115
 
);
116
 
 
117
 
create table t2 (a int);
118
 
insert into t2 values (0),(1),(2),(3),(4),(NULL);
119
 
 
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;
126
 
analyze table t1;
127
 
select count(*) from t1;
128
 
 
129
 
--replace_column 9 #
130
 
explain select count(*) from t1 where
131
 
  key1a = 2 and key1b is null and  key2a = 2 and key2b is null;
132
 
 
133
 
select count(*) from t1 where
134
 
  key1a = 2 and key1b is null and key2a = 2 and key2b is null;
135
 
 
136
 
--replace_column 9 #
137
 
explain select count(*) from t1 where
138
 
  key1a = 2 and key1b is null and key3a = 2 and key3b is null;
139
 
 
140
 
select count(*) from t1 where
141
 
  key1a = 2 and key1b is null and key3a = 2 and key3b is null;
142
 
 
143
 
drop table t1,t2;
144
 
 
145
 
# Test for BUG#8441
146
 
create table t1 (
147
 
  id1 int,
148
 
  id2 date ,
149
 
  index idx2 (id1,id2),
150
 
  index idx1 (id2)
151
 
);
152
 
insert into t1 values(1,'20040101'), (2,'20040102');
153
 
select * from t1  where id1 = 1  and id2= '20040101';
154
 
drop table t1;
155
 
 
156
 
# BUG#21277: Index Merge/sort_union: wrong query results
157
 
create table t1
158
 
(
159
 
  key1 int not null, 
160
 
  key2 int not null default 0,
161
 
  key3 int not null default 0
162
 
);
163
 
 
164
 
insert into t1(key1) values (1),(2),(3),(4),(5),(6),(7),(8);
165
 
 
166
 
let $1=7;
167
 
set @d=8;
168
 
begin;
169
 
while ($1)
170
 
{
171
 
  eval insert into t1 (key1) select key1+@d from t1;
172
 
  eval set @d=@d*2;
173
 
  dec $1;
174
 
}
175
 
commit;
176
 
 
177
 
alter table t1 add index i2(key2);
178
 
alter table t1 add index i3(key3);
179
 
update t1 set key2=key1,key3=key1;
180
 
 
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);
184
 
drop table t1;
185
 
 
186
 
--echo #
187
 
--echo # Bug#56423: Different count with SELECT and CREATE SELECT queries
188
 
--echo #
189
 
 
190
 
CREATE TABLE t1 (
191
 
  a INT,
192
 
  b INT,
193
 
  c INT,
194
 
  d INT,
195
 
  PRIMARY KEY (a),
196
 
  KEY (c),
197
 
  KEY bd (b,d)
198
 
);
199
 
 
200
 
INSERT INTO t1 VALUES
201
 
(1, 0, 1, 0),
202
 
(2, 1, 1, 1),
203
 
(3, 1, 1, 1),
204
 
(4, 0, 1, 1);
205
 
 
206
 
EXPLAIN
207
 
SELECT a
208
 
FROM t1
209
 
WHERE c = 1 AND b = 1 AND d = 1;
210
 
 
211
 
CREATE TABLE t2 ( a INT )
212
 
SELECT a
213
 
FROM t1
214
 
WHERE c = 1 AND b = 1 AND d = 1;
215
 
 
216
 
SELECT * FROM t2;
217
 
 
218
 
DROP TABLE t1, t2;
219
 
 
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;
223
 
 
224
 
DROP TABLE t1;
225
 
 
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;
230
 
SELECT * FROM t1;
231
 
 
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;
235
 
SELECT * FROM t2;
236
 
 
237
 
DROP TABLE t1, t2;