2
# Test of MEMORY tables.
6
drop table if exists t1,t2;
9
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
10
insert into t1 values(1,1),(2,2),(3,3),(4,4);
11
delete from t1 where a=1 or a=0;
12
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
13
show table status like "t1";
16
select * from t1 where a=4;
17
update t1 set b=5 where a=4;
18
update t1 set b=b+1 where a>=3;
19
replace t1 values (3,3);
21
alter table t1 add c int not null, add key using HASH (c,a);
24
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
25
insert into t1 values(1,1),(2,2),(3,3),(4,4);
26
delete from t1 where a > 0;
30
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
31
insert into t1 values(1,1),(2,2),(3,3),(4,4);
32
alter table t1 modify a int not null auto_increment, engine=innodb, comment="new innodb table";
33
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
34
show table status like "t1";
38
create temporary table t1 (a int not null) engine=MEMORY;
39
insert into t1 values (869751),(736494),(226312),(802616),(728912);
40
select * from t1 where a > 736494;
41
alter table t1 add unique uniq_id using HASH (a);
42
select * from t1 where a > 736494;
43
select * from t1 where a = 736494;
44
select * from t1 where a=869751 or a=736494;
45
select * from t1 where a in (869751,736494,226312,802616);
46
alter table t1 engine=innodb;
47
explain select * from t1 where a in (869751,736494,226312,802616);
50
create temporary table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y))
52
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
53
select * from t1 where x=1;
54
select * from t1,t1 as t2 where t1.x=t2.y;
55
explain select * from t1,t1 as t2 where t1.x=t2.y;
58
create temporary table t1 (a int) engine=MEMORY;
59
insert into t1 values(1);
60
select max(a) from t1;
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;
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;
70
create temporary table t1 (id int not null, primary key using HASH (id)) engine=MEMORY;
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);
78
create temporary table t1 (n int) engine=MEMORY;
81
create temporary table t1 (n int) engine=MEMORY;
82
drop table if exists t1;
84
# Test of non unique index
86
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not
87
null,index(f2)) engine=MEMORY;
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";
102
# Test when using part key searches
105
create temporary table t1 (btn char(10) not null, key using HASH (btn)) engine=MEMORY;
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";
119
CREATE TEMPORARY TABLE t1 (
122
KEY a using HASH (a),
123
UNIQUE b using HASH (b)
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;
134
INSERT INTO t1 VALUES (1,3);
138
# Test when deleting all rows
141
CREATE TEMPORARY TABLE t1 (a int not null, primary key using HASH (a)) engine=MEMORY;
142
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
143
DELETE from t1 where a < 100;
149
# Hash index # records estimate test
151
create temporary table t1
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);
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';
172
insert into t1 select * from t1;
174
# avoid statistics differences between normal and ps-protocol tests
176
explain select * from t1 where a='aaaa';
177
explain select * from t1 where a='aaab';
178
explain select * from t1 where a='aaac';
179
explain select * from t1 where a='aaad';
181
# a known effect: table reload causes statistics to be updated:
183
explain select * from t1 where a='aaaa';
184
explain select * from t1 where a='aaab';
185
explain select * from t1 where a='aaac';
186
explain select * from t1 where a='aaad';
188
# Check if delete_all_rows() updates #hash_buckets
189
create temporary table t2 as select * from t1;
191
insert into t1 select * from t2;
192
explain select * from t1 where a='aaaa';
193
explain select * from t1 where a='aaab';
194
explain select * from t1 where a='aaac';
195
explain select * from t1 where a='aaad';
199
# Btree and hash index use costs.
200
create temporary table t1 (
201
id int not null primary key auto_increment,
202
name varchar(20) not null,
203
index heap_idx(name),
204
index btree_idx using btree(name)
207
create temporary table t2 (
208
id int not null primary key auto_increment,
209
name varchar(20) not null,
210
index btree_idx using btree(name),
214
insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'),
215
('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'),
217
insert into t2 select * from t1;
218
explain select * from t1 where name='matt';
219
explain select * from t2 where name='matt';
221
explain select * from t1 where name='Lilu';
222
explain select * from t2 where name='Lilu';
224
explain select * from t1 where name='Phil';
225
explain select * from t2 where name='Phil';
227
explain select * from t1 where name='Lilu';
228
explain select * from t2 where name='Lilu';
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
insert into t1 (name) select name from t2;
235
insert into t1 (name) select name from t2;
237
select count(*) from t1 where name='Matt';
238
explain select * from t1 ignore index (btree_idx) where name='matt';
243
create temporary table t3
245
a varchar(20) not null,
246
b varchar(20) not null,
249
insert into t3 select name, name from t1;
253
# test rec_per_key use for joins.
254
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
drop table t1, t2, t3;
258
# Fix for BUG#8371: wrong rec_per_key value for hash index on temporary table
259
create temporary table t1 ( a int, index (a) ) engine=memory;
260
insert into t1 values (1),(2),(3),(4),(5);
261
select a from t1 where a in (1,3);
262
explain select a from t1 where a in (1,3);
265
--echo End of 4.1 tests
268
# Bug #27643: query failed : 1114 (The table '' is full)
270
# Check that HASH indexes disregard trailing spaces when comparing
271
# strings with binary collations
273
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL,
274
col2 VARCHAR(32) COLLATE utf8_bin NOT NULL,
275
UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
276
INSERT INTO t1 VALUES('A', 'A');
278
INSERT INTO t1 VALUES('A ', 'A ');
280
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL,
281
col2 VARCHAR(32) COLLATE utf8_bin NOT NULL,
282
UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
283
INSERT INTO t1 VALUES('A', 'A');
285
INSERT INTO t1 VALUES('A ', 'A ');
288
--echo End of 5.0 tests