1
1
drop table if exists t1,t2;
2
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
2
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;
3
3
insert into t1 values(1,1),(2,2),(3,3),(4,4);
4
4
delete from t1 where a=1 or a=0;
5
show table status like "t1";
6
Session Schema Name Type Engine Version Rows Avg_row_length Table_size Auto_increment
7
# test t1 TEMPORARY MEMORY # # # # #
9
Table Unique Key_name Seq_in_index Column_name
6
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
7
t1 0 PRIMARY 1 a NULL 3 NULL NULL HASH
27
24
alter table t1 add c int not null, add key using HASH (c,a);
29
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
26
create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps";
30
27
insert into t1 values(1,1),(2,2),(3,3),(4,4);
31
28
delete from t1 where a > 0;
35
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=MEMORY comment="testing heaps";
32
create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps";
36
33
insert into t1 values(1,1),(2,2),(3,3),(4,4);
37
alter table t1 modify a int not null auto_increment, engine=innodb, comment="new innodb table";
38
show table status like "t1";
39
Session Schema Name Type Engine Version Rows Avg_row_length Table_size Auto_increment
40
# test t1 TEMPORARY InnoDB # # # # #
34
alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table";
72
alter table t1 engine=innodb;
66
alter table t1 engine=myisam;
73
67
explain select * from t1 where a in (869751,736494,226312,802616);
74
68
id select_type table type possible_keys key key_len ref rows Extra
75
1 SIMPLE t1 index uniq_id uniq_id 4 NULL 5 Using where; Using index
69
1 SIMPLE t1 range uniq_id uniq_id 4 NULL 4 Using where; Using index
77
create temporary table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y))
71
create table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y))
79
73
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
80
74
select * from t1 where x=1;
84
78
select * from t1,t1 as t2 where t1.x=t2.y;
85
ERROR HY000: Can't reopen table: 't1'
86
86
explain select * from t1,t1 as t2 where t1.x=t2.y;
87
ERROR HY000: Can't reopen table: 't1'
87
id select_type table type possible_keys key key_len ref rows Extra
88
1 SIMPLE t1 ALL x NULL NULL NULL 6
89
1 SIMPLE t2 eq_ref y y 4 test.t1.x 1
89
create temporary table t1 (a int) engine=MEMORY;
91
create table t1 (a int) engine=heap;
90
92
insert into t1 values(1);
91
93
select max(a) from t1;
95
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;
97
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;
96
98
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
97
99
select * from t1 where a=1;
130
132
replace into t1 values(1);
132
create temporary table t1 (n int) engine=MEMORY;
134
create table t1 (n int) engine=heap;
134
create temporary table t1 (n int) engine=MEMORY;
136
create table t1 (n int) engine=heap;
135
137
drop table if exists t1;
136
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not
137
null,index(f2)) engine=MEMORY;
138
CREATE table t1(f1 int not null,f2 char(20) not
139
null,index(f2)) engine=heap;
138
140
INSERT into t1 set f1=12,f2="bill";
139
141
INSERT into t1 set f1=13,f2="bill";
140
142
INSERT into t1 set f1=14,f2="bill";
156
create temporary table t1 (btn char(10) not null, key using HASH (btn)) engine=MEMORY;
158
create table t1 (btn char(10) not null, key using HASH (btn)) engine=heap;
157
159
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
158
160
explain select * from t1 where btn like "q%";
159
161
id select_type table type possible_keys key key_len ref rows Extra
195
197
INSERT INTO t1 VALUES (1,3);
196
198
ERROR 23000: Duplicate entry '3' for key 'b'
198
CREATE TEMPORARY TABLE t1 (a int not null, primary key using HASH (a)) engine=MEMORY;
200
CREATE TABLE t1 (a int not null, primary key using HASH (a)) engine=heap;
199
201
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
200
202
DELETE from t1 where a < 100;
201
203
SELECT * from t1;
204
create temporary table t1
206
208
a char(8) not null,
207
209
b char(20) not null,
211
213
insert into t1 values ('aaaa', 'prefill-hash=5',0);
212
214
insert into t1 values ('aaab', 'prefill-hash=0',0);
213
215
insert into t1 values ('aaac', 'prefill-hash=7',0);
229
231
id select_type table type possible_keys key key_len ref rows Extra
230
232
1 SIMPLE t1 ref a a 34 const 2 Using where
231
233
insert into t1 select * from t1;
232
ERROR HY000: Can't reopen table: 't1'
234
explain select * from t1 where a='aaaa';
235
id select_type table type possible_keys key key_len ref rows Extra
236
1 SIMPLE t1 ref a a 34 const 2 Using where
237
explain select * from t1 where a='aaab';
238
id select_type table type possible_keys key key_len ref rows Extra
239
1 SIMPLE t1 ref a a 34 const 2 Using where
240
explain select * from t1 where a='aaac';
241
id select_type table type possible_keys key key_len ref rows Extra
242
1 SIMPLE t1 ref a a 34 const 2 Using where
243
explain select * from t1 where a='aaad';
244
id select_type table type possible_keys key key_len ref rows Extra
245
1 SIMPLE t1 ref a a 34 const 2 Using where
247
explain select * from t1 where a='aaaa';
248
id select_type table type possible_keys key key_len ref rows Extra
249
1 SIMPLE t1 ref a a 34 const 2 Using where
250
explain select * from t1 where a='aaab';
251
id select_type table type possible_keys key key_len ref rows Extra
252
1 SIMPLE t1 ref a a 34 const 2 Using where
253
explain select * from t1 where a='aaac';
254
id select_type table type possible_keys key key_len ref rows Extra
255
1 SIMPLE t1 ref a a 34 const 2 Using where
256
explain select * from t1 where a='aaad';
257
id select_type table type possible_keys key key_len ref rows Extra
258
1 SIMPLE t1 ref a a 34 const 2 Using where
259
create temporary table t2 as select * from t1;
235
explain select * from t1 where a='aaaa';
236
id select_type table type possible_keys key key_len ref rows Extra
237
1 SIMPLE t1 ref a a 34 const 2 Using where
238
explain select * from t1 where a='aaab';
239
id select_type table type possible_keys key key_len ref rows Extra
240
1 SIMPLE t1 ref a a 34 const 2 Using where
241
explain select * from t1 where a='aaac';
242
id select_type table type possible_keys key key_len ref rows Extra
243
1 SIMPLE t1 ref a a 34 const 2 Using where
244
explain select * from t1 where a='aaad';
245
id select_type table type possible_keys key key_len ref rows Extra
246
1 SIMPLE t1 ref a a 34 const 2 Using where
248
explain select * from t1 where a='aaaa';
249
id select_type table type possible_keys key key_len ref rows Extra
250
1 SIMPLE t1 ref a a 34 const 2 Using where
251
explain select * from t1 where a='aaab';
252
id select_type table type possible_keys key key_len ref rows Extra
253
1 SIMPLE t1 ref a a 34 const 2 Using where
254
explain select * from t1 where a='aaac';
255
id select_type table type possible_keys key key_len ref rows Extra
256
1 SIMPLE t1 ref a a 34 const 2 Using where
257
explain select * from t1 where a='aaad';
258
id select_type table type possible_keys key key_len ref rows Extra
259
1 SIMPLE t1 ref a a 34 const 2 Using where
260
create table t2 as select * from t1;
261
262
insert into t1 select * from t2;
262
263
explain select * from t1 where a='aaaa';
272
273
id select_type table type possible_keys key key_len ref rows Extra
273
274
1 SIMPLE t1 ref a a 34 const 2 Using where
274
275
drop table t1, t2;
275
create temporary table t1 (
276
277
id int not null primary key auto_increment,
277
278
name varchar(20) not null,
278
279
index heap_idx(name),
279
280
index btree_idx using btree(name)
281
create temporary table t2 (
282
283
id int not null primary key auto_increment,
283
284
name varchar(20) not null,
284
285
index btree_idx using btree(name),
285
286
index heap_idx(name)
287
288
insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'),
288
289
('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'),
289
290
('Emily'), ('Mike');
290
291
insert into t2 select * from t1;
291
292
explain select * from t1 where name='matt';
292
293
id select_type table type possible_keys key key_len ref rows Extra
293
1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 82 const 2 Using where
294
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 82 const 1 Using where
294
295
explain select * from t2 where name='matt';
295
296
id select_type table type possible_keys key key_len ref rows Extra
296
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 2 Using where
297
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 1 Using where
297
298
explain select * from t1 where name='Lilu';
298
299
id select_type table type possible_keys key key_len ref rows Extra
299
1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 82 const 2 Using where
300
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 82 const 1 Using where
300
301
explain select * from t2 where name='Lilu';
301
302
id select_type table type possible_keys key key_len ref rows Extra
302
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 2 Using where
303
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 1 Using where
303
304
explain select * from t1 where name='Phil';
304
305
id select_type table type possible_keys key key_len ref rows Extra
305
1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 82 const 2 Using where
306
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 82 const 1 Using where
306
307
explain select * from t2 where name='Phil';
307
308
id select_type table type possible_keys key key_len ref rows Extra
308
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 2 Using where
309
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 1 Using where
309
310
explain select * from t1 where name='Lilu';
310
311
id select_type table type possible_keys key key_len ref rows Extra
311
1 SIMPLE t1 ref heap_idx,btree_idx heap_idx 82 const 2 Using where
312
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 82 const 1 Using where
312
313
explain select * from t2 where name='Lilu';
313
314
id select_type table type possible_keys key key_len ref rows Extra
314
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 2 Using where
315
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 1 Using where
315
316
insert into t1 (name) select name from t2;
316
317
insert into t1 (name) select name from t2;
317
318
insert into t1 (name) select name from t2;
326
327
id select_type table type possible_keys key key_len ref rows Extra
327
328
1 SIMPLE t1 ref heap_idx heap_idx 82 const 9 Using where
328
329
show index from t1;
329
Table Unique Key_name Seq_in_index Column_name
331
t1 NO heap_idx 1 name
332
t1 NO btree_idx 1 name
330
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
331
t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH
332
t1 1 heap_idx 1 name NULL 10 NULL NULL HASH
333
t1 1 btree_idx 1 name A NULL NULL NULL BTREE
333
334
show index from t1;
334
Table Unique Key_name Seq_in_index Column_name
336
t1 NO heap_idx 1 name
337
t1 NO btree_idx 1 name
338
create temporary table t3
335
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
336
t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH
337
t1 1 heap_idx 1 name NULL 10 NULL NULL HASH
338
t1 1 btree_idx 1 name A NULL NULL NULL BTREE
340
341
a varchar(20) not null,
341
342
b varchar(20) not null,
344
345
insert into t3 select name, name from t1;
345
346
show index from t3;
346
Table Unique Key_name Seq_in_index Column_name
347
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
348
t3 1 a 1 a NULL NULL NULL NULL HASH
349
t3 1 a 2 b NULL 13 NULL NULL HASH
349
350
show index from t3;
350
Table Unique Key_name Seq_in_index Column_name
351
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
352
t3 1 a 1 a NULL NULL NULL NULL HASH
353
t3 1 a 2 b NULL 13 NULL NULL HASH
353
354
explain select * from t1 ignore key(btree_idx), t3 where t1.name='matt' and t3.a = concat('',t1.name) and t3.b=t1.name;
354
355
id select_type table type possible_keys key key_len ref rows Extra
355
356
1 SIMPLE t1 ref heap_idx heap_idx 82 const 9 Using where
366
367
1 SIMPLE t1 range a a 5 NULL 4 Using where
369
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL,
370
CREATE TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL,
370
371
col2 VARCHAR(32) COLLATE utf8_bin NOT NULL,
371
372
UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
372
373
INSERT INTO t1 VALUES('A', 'A');
373
374
INSERT INTO t1 VALUES('A ', 'A ');
374
375
ERROR 23000: Duplicate entry 'A -A ' for key 'key1'
376
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL,
377
CREATE TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL,
377
378
col2 VARCHAR(32) COLLATE utf8_bin NOT NULL,
378
379
UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
379
380
INSERT INTO t1 VALUES('A', 'A');