~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Test of heap tables.
3
#
4
5
--disable_warnings
6
drop table if exists t1,t2;
7
--enable_warnings
8
1116.1.2 by Brian Aker
Remove options which are just for internal optimizations.
9
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps";
1 by brian
clean slate
10
insert into t1 values(1,1),(2,2),(3,3),(4,4);
11
delete from t1 where a=1 or a=0;
12
#show table status like "t1";
13
show keys from t1;
14
select * from t1;
15
select * from t1 where a=4;
16
update t1 set b=5 where a=4;
17
update t1 set b=b+1 where a>=3;
18
replace t1 values (3,3);
19
select * from t1;
20
alter table t1 add c int not null, add key using HASH (c,a);
21
drop table t1;
22
1106.3.1 by Brian Aker
Heap is now tmp only table
23
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps";
1 by brian
clean slate
24
insert into t1 values(1,1),(2,2),(3,3),(4,4);
25
delete from t1 where a > 0;
26
select * from t1;
27
drop table t1;
28
1106.3.1 by Brian Aker
Heap is now tmp only table
29
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps";
1 by brian
clean slate
30
insert into t1 values(1,1),(2,2),(3,3),(4,4);
1063.9.3 by Brian Aker
Partial fix for tests for tmp
31
alter table t1 modify a int not null auto_increment, engine=innodb, comment="new innodb table";
1 by brian
clean slate
32
#show table status like "t1";
33
select * from t1;
34
drop table t1;
35
1106.3.1 by Brian Aker
Heap is now tmp only table
36
create temporary table t1 (a int not null) engine=heap;
1 by brian
clean slate
37
insert into t1 values (869751),(736494),(226312),(802616),(728912);
38
select * from t1 where a > 736494;
39
alter table t1 add unique uniq_id using HASH (a);
40
select * from t1 where a > 736494;
41
select * from t1 where a = 736494;
42
select * from t1 where a=869751 or a=736494;
43
select * from t1 where a in (869751,736494,226312,802616);
1063.9.3 by Brian Aker
Partial fix for tests for tmp
44
alter table t1 engine=innodb;
1 by brian
clean slate
45
explain select * from t1 where a in (869751,736494,226312,802616);
46
drop table t1;
47
1106.3.1 by Brian Aker
Heap is now tmp only table
48
create temporary table t1 (x int not null, y int not null, key x  using HASH (x), unique y  using HASH (y))
1 by brian
clean slate
49
engine=heap;
50
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
51
select * from t1 where x=1;
1106.3.1 by Brian Aker
Heap is now tmp only table
52
-- error 1137
1 by brian
clean slate
53
select * from t1,t1 as t2 where t1.x=t2.y;
1106.3.1 by Brian Aker
Heap is now tmp only table
54
-- error 1137
1 by brian
clean slate
55
explain select * from t1,t1 as t2 where t1.x=t2.y;
56
drop table t1;
57
1106.3.1 by Brian Aker
Heap is now tmp only table
58
create temporary table t1 (a int) engine=heap;
1 by brian
clean slate
59
insert into t1 values(1);
60
select max(a) from t1;
61
drop table t1;
62
1106.3.1 by Brian Aker
Heap is now tmp only table
63
CREATE TEMPORARY TABLE t1 ( a int not null default 0, b int not null default 0,  key  using HASH (a),  key  using HASH (b)  ) ENGINE=HEAP;
1 by brian
clean slate
64
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
65
select * from t1 where a=1; 
66
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
67
select * from t1 where a=1;
68
drop table t1;
69
1106.3.1 by Brian Aker
Heap is now tmp only table
70
create temporary table t1 (id int not null, primary key  using HASH (id)) engine=HEAP;
1 by brian
clean slate
71
insert into t1 values(1);
72
select max(id) from t1; 
73
insert into t1 values(2);
74
select max(id) from t1; 
75
replace into t1 values(1);
76
drop table t1;
77
1106.3.1 by Brian Aker
Heap is now tmp only table
78
create temporary table t1 (n int) engine=heap;
1 by brian
clean slate
79
drop table t1;
80
1106.3.1 by Brian Aker
Heap is now tmp only table
81
create temporary table t1 (n int) engine=heap;
1 by brian
clean slate
82
drop table if exists t1;
83
84
# Test of non unique index
85
1106.3.1 by Brian Aker
Heap is now tmp only table
86
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not 
1 by brian
clean slate
87
null,index(f2)) engine=heap;
88
INSERT into t1 set f1=12,f2="bill";
89
INSERT into t1 set f1=13,f2="bill";
90
INSERT into t1 set f1=14,f2="bill";
91
INSERT into t1 set f1=15,f2="bill";
92
INSERT into t1 set f1=16,f2="ted";
93
INSERT into t1 set f1=12,f2="ted";
94
INSERT into t1 set f1=12,f2="ted";
95
INSERT into t1 set f1=12,f2="ted";
96
INSERT into t1 set f1=12,f2="ted";
97
delete from t1 where f2="bill";
98
select * from t1;
99
drop table t1;
100
101
#
102
# Test when using part key searches
103
#
104
1106.3.1 by Brian Aker
Heap is now tmp only table
105
create temporary table t1 (btn char(10) not null, key using HASH (btn)) engine=heap;
1 by brian
clean slate
106
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
107
explain select * from t1 where btn like "q%";
108
select * from t1 where btn like "q%";
109
alter table t1 add column new_col char(1) not null, add key using HASH (btn,new_col), drop key btn;
110
update t1 set new_col=left(btn,1);
111
explain select * from t1 where btn="a";
112
explain select * from t1 where btn="a" and new_col="a";
113
drop table t1;
114
115
#
116
# Test of NULL keys
117
#
118
1106.3.1 by Brian Aker
Heap is now tmp only table
119
CREATE TEMPORARY TABLE t1 (
1 by brian
clean slate
120
  a int default NULL,
121
  b int default NULL,
122
  KEY a using HASH (a),
123
  UNIQUE b using HASH (b)
124
) engine=heap;
125
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
126
SELECT * FROM t1 WHERE a=NULL;
127
explain SELECT * FROM t1 WHERE a IS NULL;
128
SELECT * FROM t1 WHERE a<=>NULL;
129
SELECT * FROM t1 WHERE b=NULL;
130
explain SELECT * FROM t1 WHERE b IS NULL;
131
SELECT * FROM t1 WHERE b<=>NULL;
132
133
--error ER_DUP_ENTRY
134
INSERT INTO t1 VALUES (1,3);
135
DROP TABLE t1;
136
137
#
138
# Test when deleting all rows
139
#
140
1106.3.1 by Brian Aker
Heap is now tmp only table
141
CREATE TEMPORARY TABLE t1 (a int not null, primary key using HASH (a)) engine=heap;
1 by brian
clean slate
142
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
143
DELETE from t1 where a < 100;
144
SELECT * from t1;
145
DROP TABLE t1;
146
147
148
#
149
# Hash index # records estimate test
150
#
1106.3.1 by Brian Aker
Heap is now tmp only table
151
create temporary table t1
1 by brian
clean slate
152
(
153
  a char(8) not null,
154
  b char(20) not null,
155
  c int not null,
156
  key (a)
157
) engine=heap;
158
159
insert into t1 values ('aaaa', 'prefill-hash=5',0);
160
insert into t1 values ('aaab', 'prefill-hash=0',0);
161
insert into t1 values ('aaac', 'prefill-hash=7',0);
162
insert into t1 values ('aaad', 'prefill-hash=2',0);
163
insert into t1 values ('aaae', 'prefill-hash=1',0);
164
insert into t1 values ('aaaf', 'prefill-hash=4',0);
165
insert into t1 values ('aaag', 'prefill-hash=3',0);
166
insert into t1 values ('aaah', 'prefill-hash=6',0);
167
168
explain select * from t1 where a='aaaa';
169
explain select * from t1 where a='aaab';
170
explain select * from t1 where a='aaac';
171
explain select * from t1 where a='aaad';
1106.3.1 by Brian Aker
Heap is now tmp only table
172
-- error 1137
1 by brian
clean slate
173
insert into t1 select * from t1;
174
175
# avoid statistics differences between normal and ps-protocol tests
176
flush tables;
177
explain select * from t1 where a='aaaa';
178
explain select * from t1 where a='aaab';
179
explain select * from t1 where a='aaac';
180
explain select * from t1 where a='aaad';
181
182
# a known effect: table reload causes statistics to be updated:
183
flush tables;
184
explain select * from t1 where a='aaaa';
185
explain select * from t1 where a='aaab';
186
explain select * from t1 where a='aaac';
187
explain select * from t1 where a='aaad';
188
189
# Check if delete_all_rows() updates #hash_buckets
1106.3.1 by Brian Aker
Heap is now tmp only table
190
create temporary table t2 as select * from t1;
1 by brian
clean slate
191
delete from t1;
192
insert into t1 select * from t2;
193
explain select * from t1 where a='aaaa';
194
explain select * from t1 where a='aaab';
195
explain select * from t1 where a='aaac';
196
explain select * from t1 where a='aaad';
197
drop table t1, t2;
198
199
200
# Btree and hash index use costs. 
1106.3.1 by Brian Aker
Heap is now tmp only table
201
create temporary table t1 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
202
  id int not null primary key auto_increment, 
1 by brian
clean slate
203
  name varchar(20) not null,
204
  index heap_idx(name),
205
  index btree_idx using btree(name)
206
) engine=heap;
207
1106.3.1 by Brian Aker
Heap is now tmp only table
208
create temporary table t2 (
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
209
  id int not null primary key auto_increment, 
1 by brian
clean slate
210
  name varchar(20) not null,
211
  index btree_idx using btree(name),
212
  index heap_idx(name)
213
) engine=heap;
214
215
insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'), 
216
  ('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'), 
217
  ('Emily'), ('Mike');
218
insert into t2 select * from t1;
219
explain select * from t1 where name='matt';
220
explain select * from t2 where name='matt';
221
222
explain select * from t1 where name='Lilu';
223
explain select * from t2 where name='Lilu';
224
225
explain select * from t1 where name='Phil';
226
explain select * from t2 where name='Phil';
227
228
explain select * from t1 where name='Lilu';
229
explain select * from t2 where name='Lilu';
230
231
insert into t1 (name) select name from t2;
232
insert into t1 (name) select name from t2;
233
insert into t1 (name) select name from t2;
234
insert into t1 (name) select name from t2;
235
insert into t1 (name) select name from t2;
236
insert into t1 (name) select name from t2;
237
flush tables;
238
select count(*) from t1 where name='Matt';
239
explain select * from t1 ignore index (btree_idx) where name='matt';
240
show index from t1;
241
242
show index from t1;
243
1106.3.1 by Brian Aker
Heap is now tmp only table
244
create temporary table t3
1 by brian
clean slate
245
(
246
  a varchar(20) not null,
247
  b varchar(20) not null,
248
  key (a,b)
249
) engine=heap;
250
insert into t3 select name, name from t1;
251
show index from t3;
252
show index from t3;
253
254
# test rec_per_key use for joins.
255
explain select * from t1 ignore key(btree_idx), t3 where t1.name='matt' and t3.a = concat('',t1.name) and t3.b=t1.name;
256
257
drop table t1, t2, t3;
258
259
# Fix for BUG#8371: wrong rec_per_key value for hash index on temporary table
1106.3.1 by Brian Aker
Heap is now tmp only table
260
create temporary temporary table t1 ( a int, index (a) ) engine=memory;
1 by brian
clean slate
261
insert into t1 values (1),(2),(3),(4),(5);
262
select a from t1 where a in (1,3);
263
explain select a from t1 where a in (1,3);
264
drop table t1;
265
266
--echo End of 4.1 tests
267
268
#
269
# Bug #27643: query failed : 1114 (The table '' is full)
270
#
271
# Check that HASH indexes disregard trailing spaces when comparing 
272
# strings with binary collations
273
1106.3.1 by Brian Aker
Heap is now tmp only table
274
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
520.1.8 by Brian Aker
Updating tests.
275
                col2 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
1 by brian
clean slate
276
                UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
277
INSERT INTO t1 VALUES('A', 'A');
278
--error ER_DUP_ENTRY
279
INSERT INTO t1 VALUES('A ', 'A ');
280
DROP TABLE t1;
1106.3.1 by Brian Aker
Heap is now tmp only table
281
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
520.1.8 by Brian Aker
Updating tests.
282
                col2 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
1 by brian
clean slate
283
                UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
284
INSERT INTO t1 VALUES('A', 'A');
285
--error ER_DUP_ENTRY
286
INSERT INTO t1 VALUES('A ', 'A ');
287
DROP TABLE t1;
288
289
--echo End of 5.0 tests