~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/include/index_merge2.inc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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) not null,
 
57
                add zeroval int not null default 0,
 
58
                add str2 char (100) not null,
 
59
                add str3 char (100) 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,t2 B,t2 C, 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;