~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/heap_hash.test

  • Committer: Brian Aker
  • Date: 2008-07-13 21:20:24 UTC
  • Revision ID: brian@tangent.org-20080713212024-o6263c1vha7yxdeu
More bool removal. More cow bell!

Show diffs side-by-side

added added

removed removed

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