~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/heap_hash.test

  • Committer: Brian Aker
  • Date: 2010-02-07 01:33:54 UTC
  • Revision ID: brian@gaz-20100207013354-d2pg1n68u5c09pgo
Remove giant include header to its own file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
 
# Test of heap tables.
 
2
# Test of MEMORY tables.
3
3
#
4
4
 
5
5
--disable_warnings
6
6
drop table if exists t1,t2;
7
7
--enable_warnings
8
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;
 
9
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
10
10
insert into t1 values(1,1),(2,2),(3,3),(4,4);
11
11
delete from t1 where a=1 or a=0;
12
12
#show table status like "t1";
20
20
alter table t1 add c int not null, add key using HASH (c,a);
21
21
drop table t1;
22
22
 
23
 
create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps";
 
23
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
24
24
insert into t1 values(1,1),(2,2),(3,3),(4,4);
25
25
delete from t1 where a > 0;
26
26
select * from t1;
27
27
drop table t1;
28
28
 
29
 
create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps";
 
29
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
30
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";
 
31
alter table t1 modify a int not null auto_increment, engine=innodb, comment="new innodb table";
32
32
#show table status like "t1";
33
33
select * from t1;
34
34
drop table t1;
35
35
 
36
 
create table t1 (a int not null) engine=heap;
 
36
create temporary table t1 (a int not null) engine=MEMORY;
37
37
insert into t1 values (869751),(736494),(226312),(802616),(728912);
38
38
select * from t1 where a > 736494;
39
39
alter table t1 add unique uniq_id using HASH (a);
41
41
select * from t1 where a = 736494;
42
42
select * from t1 where a=869751 or a=736494;
43
43
select * from t1 where a in (869751,736494,226312,802616);
44
 
alter table t1 engine=myisam;
 
44
alter table t1 engine=innodb;
45
45
explain select * from t1 where a in (869751,736494,226312,802616);
46
46
drop table t1;
47
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;
 
48
create temporary table t1 (x int not null, y int not null, key x  using HASH (x), unique y  using HASH (y))
 
49
engine=MEMORY;
50
50
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
51
51
select * from t1 where x=1;
 
52
-- error 1137
52
53
select * from t1,t1 as t2 where t1.x=t2.y;
 
54
-- error 1137
53
55
explain select * from t1,t1 as t2 where t1.x=t2.y;
54
56
drop table t1;
55
57
 
56
 
create table t1 (a int) engine=heap;
 
58
create temporary table t1 (a int) engine=MEMORY;
57
59
insert into t1 values(1);
58
60
select max(a) from t1;
59
61
drop table t1;
60
62
 
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;
 
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=MEMORY;
62
64
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
63
65
select * from t1 where a=1; 
64
66
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
65
67
select * from t1 where a=1;
66
68
drop table t1;
67
69
 
68
 
create table t1 (id int unsigned not null, primary key  using HASH (id)) engine=HEAP;
 
70
create temporary table t1 (id int not null, primary key  using HASH (id)) engine=MEMORY;
69
71
insert into t1 values(1);
70
72
select max(id) from t1; 
71
73
insert into t1 values(2);
73
75
replace into t1 values(1);
74
76
drop table t1;
75
77
 
76
 
create table t1 (n int) engine=heap;
 
78
create temporary table t1 (n int) engine=MEMORY;
77
79
drop table t1;
78
80
 
79
 
create table t1 (n int) engine=heap;
 
81
create temporary table t1 (n int) engine=MEMORY;
80
82
drop table if exists t1;
81
83
 
82
84
# Test of non unique index
83
85
 
84
 
CREATE table t1(f1 int not null,f2 char(20) not 
85
 
null,index(f2)) engine=heap;
 
86
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not 
 
87
null,index(f2)) engine=MEMORY;
86
88
INSERT into t1 set f1=12,f2="bill";
87
89
INSERT into t1 set f1=13,f2="bill";
88
90
INSERT into t1 set f1=14,f2="bill";
100
102
# Test when using part key searches
101
103
#
102
104
 
103
 
create table t1 (btn char(10) not null, key using HASH (btn)) engine=heap;
 
105
create temporary table t1 (btn char(10) not null, key using HASH (btn)) engine=MEMORY;
104
106
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
105
107
explain select * from t1 where btn like "q%";
106
108
select * from t1 where btn like "q%";
114
116
# Test of NULL keys
115
117
#
116
118
 
117
 
CREATE TABLE t1 (
 
119
CREATE TEMPORARY TABLE t1 (
118
120
  a int default NULL,
119
121
  b int default NULL,
120
122
  KEY a using HASH (a),
121
123
  UNIQUE b using HASH (b)
122
 
) engine=heap;
 
124
) engine=MEMORY;
123
125
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
124
126
SELECT * FROM t1 WHERE a=NULL;
125
127
explain SELECT * FROM t1 WHERE a IS NULL;
136
138
# Test when deleting all rows
137
139
#
138
140
 
139
 
CREATE TABLE t1 (a int not null, primary key using HASH (a)) engine=heap;
 
141
CREATE TEMPORARY TABLE t1 (a int not null, primary key using HASH (a)) engine=MEMORY;
140
142
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
141
143
DELETE from t1 where a < 100;
142
144
SELECT * from t1;
146
148
#
147
149
# Hash index # records estimate test
148
150
#
149
 
create table t1
 
151
create temporary table t1
150
152
(
151
153
  a char(8) not null,
152
154
  b char(20) not null,
153
155
  c int not null,
154
156
  key (a)
155
 
) engine=heap;
 
157
) engine=MEMORY;
156
158
 
157
159
insert into t1 values ('aaaa', 'prefill-hash=5',0);
158
160
insert into t1 values ('aaab', 'prefill-hash=0',0);
167
169
explain select * from t1 where a='aaab';
168
170
explain select * from t1 where a='aaac';
169
171
explain select * from t1 where a='aaad';
 
172
-- error 1137
170
173
insert into t1 select * from t1;
171
174
 
172
175
# avoid statistics differences between normal and ps-protocol tests
184
187
explain select * from t1 where a='aaad';
185
188
 
186
189
# Check if delete_all_rows() updates #hash_buckets
187
 
create table t2 as select * from t1;
 
190
create temporary table t2 as select * from t1;
188
191
delete from t1;
189
192
insert into t1 select * from t2;
190
193
explain select * from t1 where a='aaaa';
195
198
 
196
199
 
197
200
# Btree and hash index use costs. 
198
 
create table t1 (
199
 
  id int unsigned not null primary key auto_increment, 
 
201
create temporary table t1 (
 
202
  id int not null primary key auto_increment, 
200
203
  name varchar(20) not null,
201
204
  index heap_idx(name),
202
205
  index btree_idx using btree(name)
203
 
) engine=heap;
 
206
) engine=MEMORY;
204
207
 
205
 
create table t2 (
206
 
  id int unsigned not null primary key auto_increment, 
 
208
create temporary table t2 (
 
209
  id int not null primary key auto_increment, 
207
210
  name varchar(20) not null,
208
211
  index btree_idx using btree(name),
209
212
  index heap_idx(name)
210
 
) engine=heap;
 
213
) engine=MEMORY;
211
214
 
212
215
insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'), 
213
216
  ('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'), 
238
241
 
239
242
show index from t1;
240
243
 
241
 
create table t3
 
244
create temporary table t3
242
245
(
243
246
  a varchar(20) not null,
244
247
  b varchar(20) not null,
245
248
  key (a,b)
246
 
) engine=heap;
 
249
) engine=MEMORY;
247
250
insert into t3 select name, name from t1;
248
251
show index from t3;
249
252
show index from t3;
268
271
# Check that HASH indexes disregard trailing spaces when comparing 
269
272
# strings with binary collations
270
273
 
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, 
 
274
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
 
275
                col2 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
273
276
                UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
274
277
INSERT INTO t1 VALUES('A', 'A');
275
278
--error ER_DUP_ENTRY
276
279
INSERT INTO t1 VALUES('A ', 'A ');
277
280
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, 
 
281
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
 
282
                col2 VARCHAR(32) COLLATE utf8_bin NOT NULL, 
280
283
                UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
281
284
INSERT INTO t1 VALUES('A', 'A');
282
285
--error ER_DUP_ENTRY