~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/include/index_merge2.inc

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

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
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
# Test for BUG#12720
 
151
--disable_warnings
 
152
drop view if exists v1;
 
153
--enable_warnings
 
154
CREATE TABLE t1 (
 
155
  `oid` int(11) unsigned NOT NULL auto_increment,
 
156
  `fk_bbk_niederlassung` int(11) unsigned NOT NULL,
 
157
  `fk_wochentag` int(11) unsigned NOT NULL,
 
158
  `uhrzeit_von` time NOT NULL COMMENT 'HH:MM',
 
159
  `uhrzeit_bis` time NOT NULL COMMENT 'HH:MM',
 
160
  `geloescht` tinyint(4) NOT NULL,
 
161
  `version` int(5) NOT NULL,
 
162
  PRIMARY KEY  (`oid`),
 
163
  KEY `fk_bbk_niederlassung` (`fk_bbk_niederlassung`),
 
164
  KEY `fk_wochentag` (`fk_wochentag`),
 
165
  KEY `ix_version` (`version`)
 
166
) DEFAULT CHARSET=latin1;
 
167
 
 
168
insert  into t1 values
 
169
(1, 38, 1, '08:00:00', '13:00:00', 0, 1),
 
170
(2, 38, 2, '08:00:00', '13:00:00', 0, 1),
 
171
(3, 38, 3, '08:00:00', '13:00:00', 0, 1),
 
172
(4, 38, 4, '08:00:00', '13:00:00', 0, 1),
 
173
(5, 38, 5, '08:00:00', '13:00:00', 0, 1),
 
174
(6, 38, 5, '08:00:00', '13:00:00', 1, 2),
 
175
(7, 38, 3, '08:00:00', '13:00:00', 1, 2),
 
176
(8, 38, 1, '08:00:00', '13:00:00', 1, 2),
 
177
(9, 38, 2, '08:00:00', '13:00:00', 1, 2),
 
178
(10, 38, 4, '08:00:00', '13:00:00', 1, 2),
 
179
(11, 38, 1, '08:00:00', '13:00:00', 0, 3),
 
180
(12, 38, 2, '08:00:00', '13:00:00', 0, 3),
 
181
(13, 38, 3, '08:00:00', '13:00:00', 0, 3),
 
182
(14, 38, 4, '08:00:00', '13:00:00', 0, 3),
 
183
(15, 38, 5, '08:00:00', '13:00:00', 0, 3),
 
184
(16, 38, 4, '08:00:00', '13:00:00', 0, 4),
 
185
(17, 38, 5, '08:00:00', '13:00:00', 0, 4),
 
186
(18, 38, 1, '08:00:00', '13:00:00', 0, 4),
 
187
(19, 38, 2, '08:00:00', '13:00:00', 0, 4),
 
188
(20, 38, 3, '08:00:00', '13:00:00', 0, 4),
 
189
(21, 7, 1, '08:00:00', '13:00:00', 0, 1),
 
190
(22, 7, 2, '08:00:00', '13:00:00', 0, 1),
 
191
(23, 7, 3, '08:00:00', '13:00:00', 0, 1),
 
192
(24, 7, 4, '08:00:00', '13:00:00', 0, 1),
 
193
(25, 7, 5, '08:00:00', '13:00:00', 0, 1);
 
194
 
 
195
create view v1 as
 
196
select
 
197
  zeit1.oid AS oid,
 
198
  zeit1.fk_bbk_niederlassung AS fk_bbk_niederlassung,
 
199
  zeit1.fk_wochentag AS fk_wochentag,
 
200
  zeit1.uhrzeit_von AS uhrzeit_von,
 
201
  zeit1.uhrzeit_bis AS uhrzeit_bis,
 
202
  zeit1.geloescht AS geloescht,
 
203
  zeit1.version AS version
 
204
from
 
205
  t1 zeit1
 
206
where
 
207
(zeit1.version =
 
208
  (select max(zeit2.version) AS `max(version)`
 
209
   from t1 zeit2
 
210
   where
 
211
     ((zeit1.fk_bbk_niederlassung = zeit2.fk_bbk_niederlassung) and
 
212
      (zeit1.fk_wochentag = zeit2.fk_wochentag) and
 
213
      (zeit1.uhrzeit_von = zeit2.uhrzeit_von) and
 
214
      (zeit1.uhrzeit_bis = zeit2.uhrzeit_bis)
 
215
     )
 
216
  )
 
217
)
 
218
and (zeit1.geloescht = 0);
 
219
 
 
220
select * from v1 where oid = 21;
 
221
drop view v1;
 
222
drop table t1;
 
223
##
 
224
CREATE TABLE t1(
 
225
  t_cpac varchar(2) NOT NULL,
 
226
  t_vers varchar(4) NOT NULL,
 
227
  t_rele varchar(2) NOT NULL,
 
228
  t_cust varchar(4) NOT NULL,
 
229
  filler1 char(250) default NULL,
 
230
  filler2 char(250) default NULL,
 
231
  PRIMARY KEY (t_cpac,t_vers,t_rele,t_cust),
 
232
  UNIQUE KEY IX_4 (t_cust,t_cpac,t_vers,t_rele),
 
233
  KEY IX_5 (t_vers,t_rele,t_cust)
 
234
);
 
235
 
 
236
insert into t1 values
 
237
('tm','2.5 ','a ','    ','',''), ('tm','2.5U','a ','stnd','',''),
 
238
('da','3.3 ','b ','    ','',''), ('da','3.3U','b ','stnd','',''),
 
239
('tl','7.6 ','a ','    ','',''), ('tt','7.6 ','a ','    ','',''),
 
240
('bc','B61 ','a ','    ','',''), ('bp','B61 ','a ','    ','',''),
 
241
('ca','B61 ','a ','    ','',''), ('ci','B61 ','a ','    ','',''),
 
242
('cp','B61 ','a ','    ','',''), ('dm','B61 ','a ','    ','',''),
 
243
('ec','B61 ','a ','    ','',''), ('ed','B61 ','a ','    ','',''),
 
244
('fm','B61 ','a ','    ','',''), ('nt','B61 ','a ','    ','',''),
 
245
('qm','B61 ','a ','    ','',''), ('tc','B61 ','a ','    ','',''),
 
246
('td','B61 ','a ','    ','',''), ('tf','B61 ','a ','    ','',''),
 
247
('tg','B61 ','a ','    ','',''), ('ti','B61 ','a ','    ','',''),
 
248
('tp','B61 ','a ','    ','',''), ('ts','B61 ','a ','    ','',''),
 
249
('wh','B61 ','a ','    ','',''), ('bc','B61U','a ','stnd','',''),
 
250
('bp','B61U','a ','stnd','',''), ('ca','B61U','a ','stnd','',''),
 
251
('ci','B61U','a ','stnd','',''), ('cp','B61U','a ','stnd','',''),
 
252
('dm','B61U','a ','stnd','',''), ('ec','B61U','a ','stnd','',''),
 
253
('fm','B61U','a ','stnd','',''), ('nt','B61U','a ','stnd','',''),
 
254
('qm','B61U','a ','stnd','',''), ('tc','B61U','a ','stnd','',''),
 
255
('td','B61U','a ','stnd','',''), ('tf','B61U','a ','stnd','',''),
 
256
('tg','B61U','a ','stnd','',''), ('ti','B61U','a ','stnd','',''),
 
257
('tp','B61U','a ','stnd','',''), ('ts','B61U','a ','stnd','',''),
 
258
('wh','B61U','a ','stnd','','');
 
259
show create table t1;
 
260
 
 
261
select t_vers,t_rele,t_cust,filler1 from t1 where t_vers = '7.6';
 
262
select t_vers,t_rele,t_cust,filler1 from t1 where t_vers = '7.6'
 
263
  and t_rele='a' and t_cust = ' ';
 
264
 
 
265
drop table t1;
 
266
 
 
267
# BUG#19021: Crash in index_merge/ROR-intersection optimizer under
 
268
# specific circumstances.
 
269
create table t1 (
 
270
  pk int(11) not null auto_increment,
 
271
  a int(11) not null default '0',
 
272
  b int(11) not null default '0',
 
273
  c int(11) not null default '0',
 
274
 
 
275
  filler1 datetime, filler2 varchar(15),
 
276
  filler3 longtext,
 
277
 
 
278
  kp1 varchar(4), kp2 varchar(7),
 
279
  kp3 varchar(2), kp4 varchar(4),
 
280
  kp5 varchar(7),
 
281
  filler4 char(1),
 
282
 
 
283
  primary key (pk),
 
284
  key idx1(a,b,c),
 
285
  key idx2(c),
 
286
  key idx3(kp1,kp2,kp3,kp4,kp5)
 
287
) default charset=latin1;
 
288
--disable_query_log
 
289
set @fill= uncompress(unhex(concat(
 
290
'F91D0000789CDD993D6FDB301086F7FE0A6D4E0105B8E3F1335D5BA028DA0EEDE28E1D320408',
 
291
'52A0713BF4D7571FB62C51A475924839080307B603E77DEE787C8FA41F9E9EEF7F1F8A87A7C3',
 
292
'AFE280C5DF9F8F7FEE9F8B1B2CB114D6902E918455245DB91300FA16E42D5201FA4EE29DA05D',
 
293
'B9FB3718A33718A3FA8C30AEFAFDE1F317D016AA67BA7A60FDE45BF5F8BA7B5BDE8812AA9F1A',
 
294
'069DB03C9804346644F3A3A6A1338DB572756A3C4D1BCC804CABF912C654AE9BB855A2B85962',
 
295
'3A479259CAE6A86C0411D01AE5483581EDCBD9A39C45252D532E533979EB9F82E971D979BDB4',
 
296
'8531105670740AFBFD1E34AAB0029E4AD0A1D46A6D0946A21A16038A5CD965CD2D524673F712',
 
297
'20C304477315CE18405EAF9BD0AFFEAC74FDA14F1FBF5BD34C769D73FBBEDF4750ADD4E5A99C',
 
298
'5C8DC04934AFA275D483D536D174C11B12AF27F8F888B41B6FC9DBA569E1FD7BD72D698130B7',
 
299
'91B23A98803512B3D31881E8DCDA2AC1754E3644C4BB3A8466750B911681274A39E35E8624B7',
 
300
'444A42AC1213F354758E3CF1A4CDD5A688C767CF1B11ABC5867CB15D8A18E0B91E9EC275BB94',
 
301
'58F33C2936F64690D55BC29E4A293D95A798D84217736CEAAA538CE1354269EE2162053FBC66',
 
302
'496D90CB53323CB279D3A6AF651B4B22B9E430743D83BE48E995A09D4FC9871C22D8D189B945',
 
303
'706911BCB8C3C774B9C08D2FC6ED853ADACA37A14A4CB2E027630E5B80ECACD939431B1CDF62',
 
304
'7D71487536EA2C678F59685E91F4B6C144BCCB94C1EBA9FA6F5552DDCA4E4539BE326A2720CB',
 
305
'45ED028EB3616AC93C46E775FEA9FA6DA7CFCEC6DEBA5FCD1F915EED4D983BDDB881528AD9AB',
 
306
'43C1576F29AAB35BDFBC21D422F52B307D350589D45225A887AC46C8EDD72D99EC3ED2E1BCEF',
 
307
'7AF26FC4C74097B6768A5EDAFA660CC64278F7E63F99AC954B')));
 
308
prepare x from @fill;
 
309
execute x;
 
310
deallocate prepare x;
 
311
--enable_query_log
 
312
set @fill=NULL;
 
313
SELECT COUNT(*) FROM t1 WHERE b = 0 AND a = 0 AND c = 13286427 AND
 
314
 kp1='279' AND kp2='ELM0678' AND kp3='6' AND kp4='10' AND  kp5 = 'R        ';
 
315
 
 
316
drop table t1;
 
317
 
 
318
# BUG#21277: Index Merge/sort_union: wrong query results
 
319
create table t1
 
320
(
 
321
  key1 int not null, 
 
322
  key2 int not null default 0,
 
323
  key3 int not null default 0
 
324
);
 
325
 
 
326
insert into t1(key1) values (1),(2),(3),(4),(5),(6),(7),(8);
 
327
 
 
328
let $1=7;
 
329
set @d=8;
 
330
while ($1)
 
331
{
 
332
  eval insert into t1 (key1) select key1+@d from t1;
 
333
  eval set @d=@d*2;
 
334
  dec $1;
 
335
}
 
336
 
 
337
alter table t1 add index i2(key2);
 
338
alter table t1 add index i3(key3);
 
339
update t1 set key2=key1,key3=key1;
 
340
 
 
341
# to test the bug, the following must use "sort_union":
 
342
explain select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40);
 
343
select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40);
 
344
drop table t1;
 
345