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=heap comment="testing heaps";
3
insert into t1 values(1,1),(2,2),(3,3),(4,4);
4
delete from t1 where a=1 or a=0;
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
13
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);
24
alter table t1 add c int not null, add key using HASH (c,a);
26
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps";
27
insert into t1 values(1,1),(2,2),(3,3),(4,4);
28
delete from t1 where a > 0;
32
create temporary table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps";
33
insert into t1 values(1,1),(2,2),(3,3),(4,4);
34
alter table t1 modify a int not null auto_increment, engine=innodb, comment="new innodb table";
42
create temporary table t1 (a int not null) engine=heap;
43
insert into t1 values (869751),(736494),(226312),(802616),(728912);
44
select * from t1 where a > 736494;
48
alter table t1 add unique uniq_id using HASH (a);
49
select * from t1 where a > 736494;
53
select * from t1 where a = 736494;
56
select * from t1 where a=869751 or a=736494;
60
select * from t1 where a in (869751,736494,226312,802616);
66
alter table t1 engine=innodb;
67
explain select * from t1 where a in (869751,736494,226312,802616);
68
id select_type table type possible_keys key key_len ref rows Extra
69
1 SIMPLE t1 index uniq_id uniq_id 4 NULL 5 Using where; Using index
71
create temporary table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y))
73
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
74
select * from t1 where x=1;
78
select * from t1,t1 as t2 where t1.x=t2.y;
79
ERROR HY000: Can't reopen table: 't1'
80
explain select * from t1,t1 as t2 where t1.x=t2.y;
81
ERROR HY000: Can't reopen table: 't1'
83
create temporary table t1 (a int) engine=heap;
84
insert into t1 values(1);
85
select max(a) from t1;
89
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;
90
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
91
select * from t1 where a=1;
99
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
100
select * from t1 where a=1;
115
create temporary table t1 (id int not null, primary key using HASH (id)) engine=HEAP;
116
insert into t1 values(1);
117
select max(id) from t1;
120
insert into t1 values(2);
121
select max(id) from t1;
124
replace into t1 values(1);
126
create temporary table t1 (n int) engine=heap;
128
create temporary table t1 (n int) engine=heap;
129
drop table if exists t1;
130
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not
131
null,index(f2)) engine=heap;
132
INSERT into t1 set f1=12,f2="bill";
133
INSERT into t1 set f1=13,f2="bill";
134
INSERT into t1 set f1=14,f2="bill";
135
INSERT into t1 set f1=15,f2="bill";
136
INSERT into t1 set f1=16,f2="ted";
137
INSERT into t1 set f1=12,f2="ted";
138
INSERT into t1 set f1=12,f2="ted";
139
INSERT into t1 set f1=12,f2="ted";
140
INSERT into t1 set f1=12,f2="ted";
141
delete from t1 where f2="bill";
150
create temporary table t1 (btn char(10) not null, key using HASH (btn)) engine=heap;
151
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
152
explain select * from t1 where btn like "q%";
153
id select_type table type possible_keys key key_len ref rows Extra
154
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
155
select * from t1 where btn like "q%";
157
alter table t1 add column new_col char(1) not null, add key using HASH (btn,new_col), drop key btn;
158
update t1 set new_col=left(btn,1);
159
explain select * from t1 where btn="a";
160
id select_type table type possible_keys key key_len ref rows Extra
161
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
162
explain select * from t1 where btn="a" and new_col="a";
163
id select_type table type possible_keys key key_len ref rows Extra
164
1 SIMPLE t1 ref btn btn 48 const,const 2 Using where
166
CREATE TEMPORARY TABLE t1 (
169
KEY a using HASH (a),
170
UNIQUE b using HASH (b)
172
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
173
SELECT * FROM t1 WHERE a=NULL;
175
explain SELECT * FROM t1 WHERE a IS NULL;
176
id select_type table type possible_keys key key_len ref rows Extra
177
1 SIMPLE t1 ref a a 5 const 2 Using where
178
SELECT * FROM t1 WHERE a<=>NULL;
181
SELECT * FROM t1 WHERE b=NULL;
183
explain SELECT * FROM t1 WHERE b IS NULL;
184
id select_type table type possible_keys key key_len ref rows Extra
185
1 SIMPLE t1 ref b b 5 const 1 Using where
186
SELECT * FROM t1 WHERE b<=>NULL;
189
INSERT INTO t1 VALUES (1,3);
190
ERROR 23000: Duplicate entry '3' for key 'b'
192
CREATE TEMPORARY TABLE t1 (a int not null, primary key using HASH (a)) engine=heap;
193
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
194
DELETE from t1 where a < 100;
198
create temporary table t1
205
insert into t1 values ('aaaa', 'prefill-hash=5',0);
206
insert into t1 values ('aaab', 'prefill-hash=0',0);
207
insert into t1 values ('aaac', 'prefill-hash=7',0);
208
insert into t1 values ('aaad', 'prefill-hash=2',0);
209
insert into t1 values ('aaae', 'prefill-hash=1',0);
210
insert into t1 values ('aaaf', 'prefill-hash=4',0);
211
insert into t1 values ('aaag', 'prefill-hash=3',0);
212
insert into t1 values ('aaah', 'prefill-hash=6',0);
213
explain select * from t1 where a='aaaa';
214
id select_type table type possible_keys key key_len ref rows Extra
215
1 SIMPLE t1 ref a a 34 const 2 Using where
216
explain select * from t1 where a='aaab';
217
id select_type table type possible_keys key key_len ref rows Extra
218
1 SIMPLE t1 ref a a 34 const 2 Using where
219
explain select * from t1 where a='aaac';
220
id select_type table type possible_keys key key_len ref rows Extra
221
1 SIMPLE t1 ref a a 34 const 2 Using where
222
explain select * from t1 where a='aaad';
223
id select_type table type possible_keys key key_len ref rows Extra
224
1 SIMPLE t1 ref a a 34 const 2 Using where
225
insert into t1 select * from t1;
226
ERROR HY000: Can't reopen table: 't1'
228
explain select * from t1 where a='aaaa';
229
id select_type table type possible_keys key key_len ref rows Extra
230
1 SIMPLE t1 ref a a 34 const 2 Using where
231
explain select * from t1 where a='aaab';
232
id select_type table type possible_keys key key_len ref rows Extra
233
1 SIMPLE t1 ref a a 34 const 2 Using where
234
explain select * from t1 where a='aaac';
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='aaad';
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
241
explain select * from t1 where a='aaaa';
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='aaab';
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
247
explain select * from t1 where a='aaac';
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='aaad';
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
create temporary table t2 as select * from t1;
255
insert into t1 select * from t2;
256
explain select * from t1 where a='aaaa';
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
explain select * from t1 where a='aaab';
260
id select_type table type possible_keys key key_len ref rows Extra
261
1 SIMPLE t1 ref a a 34 const 2 Using where
262
explain select * from t1 where a='aaac';
263
id select_type table type possible_keys key key_len ref rows Extra
264
1 SIMPLE t1 ref a a 34 const 2 Using where
265
explain select * from t1 where a='aaad';
266
id select_type table type possible_keys key key_len ref rows Extra
267
1 SIMPLE t1 ref a a 34 const 2 Using where
269
create temporary table t1 (
270
id int not null primary key auto_increment,
271
name varchar(20) not null,
272
index heap_idx(name),
273
index btree_idx using btree(name)
275
create temporary table t2 (
276
id int not null primary key auto_increment,
277
name varchar(20) not null,
278
index btree_idx using btree(name),
281
insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'),
282
('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'),
284
insert into t2 select * from t1;
285
explain select * from t1 where name='matt';
286
id select_type table type possible_keys key key_len ref rows Extra
287
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 82 const 1 Using where
288
explain select * from t2 where name='matt';
289
id select_type table type possible_keys key key_len ref rows Extra
290
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 82 const 1 Using where
291
explain select * from t1 where name='Lilu';
292
id select_type table type possible_keys key key_len ref rows Extra
293
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 82 const 1 Using where
294
explain select * from t2 where name='Lilu';
295
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 1 Using where
297
explain select * from t1 where name='Phil';
298
id select_type table type possible_keys key key_len ref rows Extra
299
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 82 const 1 Using where
300
explain select * from t2 where name='Phil';
301
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 1 Using where
303
explain select * from t1 where name='Lilu';
304
id select_type table type possible_keys key key_len ref rows Extra
305
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 82 const 1 Using where
306
explain select * from t2 where name='Lilu';
307
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 1 Using where
309
insert into t1 (name) select name from t2;
310
insert into t1 (name) select name from t2;
311
insert into t1 (name) select name from t2;
312
insert into t1 (name) select name from t2;
313
insert into t1 (name) select name from t2;
314
insert into t1 (name) select name from t2;
316
select count(*) from t1 where name='Matt';
319
explain select * from t1 ignore index (btree_idx) where name='matt';
320
id select_type table type possible_keys key key_len ref rows Extra
321
1 SIMPLE t1 ref heap_idx heap_idx 82 const 9 Using where
323
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
324
t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH
325
t1 1 heap_idx 1 name NULL 10 NULL NULL HASH
326
t1 1 btree_idx 1 name A NULL NULL NULL BTREE
328
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
329
t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH
330
t1 1 heap_idx 1 name NULL 10 NULL NULL HASH
331
t1 1 btree_idx 1 name A NULL NULL NULL BTREE
332
create temporary table t3
334
a varchar(20) not null,
335
b varchar(20) not null,
338
insert into t3 select name, name from t1;
340
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
341
t3 1 a 1 a NULL NULL NULL NULL HASH
342
t3 1 a 2 b NULL 13 NULL NULL HASH
344
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_Comment
345
t3 1 a 1 a NULL NULL NULL NULL HASH
346
t3 1 a 2 b NULL 13 NULL NULL HASH
347
explain select * from t1 ignore key(btree_idx), t3 where t1.name='matt' and t3.a = concat('',t1.name) and t3.b=t1.name;
348
id select_type table type possible_keys key key_len ref rows Extra
349
1 SIMPLE t1 ref heap_idx heap_idx 82 const 9 Using where
350
1 SIMPLE t3 ref a a 164 func,const 7 Using where
351
drop table t1, t2, t3;
352
create temporary table t1 ( a int, index (a) ) engine=memory;
353
insert into t1 values (1),(2),(3),(4),(5);
354
select a from t1 where a in (1,3);
358
explain select a from t1 where a in (1,3);
359
id select_type table type possible_keys key key_len ref rows Extra
360
1 SIMPLE t1 range a a 5 NULL 4 Using where
363
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL,
364
col2 VARCHAR(32) COLLATE utf8_bin NOT NULL,
365
UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
366
INSERT INTO t1 VALUES('A', 'A');
367
INSERT INTO t1 VALUES('A ', 'A ');
368
ERROR 23000: Duplicate entry 'A -A ' for key 'key1'
370
CREATE TEMPORARY TABLE t1(col1 VARCHAR(32) COLLATE utf8_bin NOT NULL,
371
col2 VARCHAR(32) COLLATE utf8_bin NOT NULL,
372
UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
373
INSERT INTO t1 VALUES('A', 'A');
374
INSERT INTO t1 VALUES('A ', 'A ');
375
ERROR 23000: Duplicate entry 'A -A ' for key 'key1'