1
drop table if exists t1,t2;
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
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 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 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=myisam, comment="new myisam table";
42
create 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=myisam;
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 range uniq_id uniq_id 4 NULL 4 Using where; Using index
71
create 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;
86
explain select * from t1,t1 as t2 where t1.x=t2.y;
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
91
create table t1 (a int) engine=heap;
92
insert into t1 values(1);
93
select max(a) from t1;
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;
98
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
99
select * from t1 where a=1;
107
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
108
select * from t1 where a=1;
123
create table t1 (id int unsigned not null, primary key using HASH (id)) engine=HEAP;
124
insert into t1 values(1);
125
select max(id) from t1;
128
insert into t1 values(2);
129
select max(id) from t1;
132
replace into t1 values(1);
134
create table t1 (n int) engine=heap;
136
create table t1 (n int) engine=heap;
137
drop table if exists t1;
138
CREATE table t1(f1 int not null,f2 char(20) not
139
null,index(f2)) engine=heap;
140
INSERT into t1 set f1=12,f2="bill";
141
INSERT into t1 set f1=13,f2="bill";
142
INSERT into t1 set f1=14,f2="bill";
143
INSERT into t1 set f1=15,f2="bill";
144
INSERT into t1 set f1=16,f2="ted";
145
INSERT into t1 set f1=12,f2="ted";
146
INSERT into t1 set f1=12,f2="ted";
147
INSERT into t1 set f1=12,f2="ted";
148
INSERT into t1 set f1=12,f2="ted";
149
delete from t1 where f2="bill";
158
create table t1 (btn char(10) not null, key using HASH (btn)) engine=heap;
159
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
160
explain select * from t1 where btn like "q%";
161
id select_type table type possible_keys key key_len ref rows Extra
162
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
163
select * from t1 where btn like "q%";
165
alter table t1 add column new_col char(1) not null, add key using HASH (btn,new_col), drop key btn;
166
update t1 set new_col=left(btn,1);
167
explain select * from t1 where btn="a";
168
id select_type table type possible_keys key key_len ref rows Extra
169
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
170
explain select * from t1 where btn="a" and new_col="a";
171
id select_type table type possible_keys key key_len ref rows Extra
172
1 SIMPLE t1 ref btn btn 11 const,const 2 Using where
177
KEY a using HASH (a),
178
UNIQUE b using HASH (b)
180
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
181
SELECT * FROM t1 WHERE a=NULL;
183
explain SELECT * FROM t1 WHERE a IS NULL;
184
id select_type table type possible_keys key key_len ref rows Extra
185
1 SIMPLE t1 ref a a 5 const 2 Using where
186
SELECT * FROM t1 WHERE a<=>NULL;
189
SELECT * FROM t1 WHERE b=NULL;
191
explain SELECT * FROM t1 WHERE b IS NULL;
192
id select_type table type possible_keys key key_len ref rows Extra
193
1 SIMPLE t1 ref b b 5 const 1 Using where
194
SELECT * FROM t1 WHERE b<=>NULL;
197
INSERT INTO t1 VALUES (1,3);
198
ERROR 23000: Duplicate entry '3' for key 'b'
200
CREATE TABLE t1 (a int not null, primary key using HASH (a)) engine=heap;
201
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
202
DELETE from t1 where a < 100;
213
insert into t1 values ('aaaa', 'prefill-hash=5',0);
214
insert into t1 values ('aaab', 'prefill-hash=0',0);
215
insert into t1 values ('aaac', 'prefill-hash=7',0);
216
insert into t1 values ('aaad', 'prefill-hash=2',0);
217
insert into t1 values ('aaae', 'prefill-hash=1',0);
218
insert into t1 values ('aaaf', 'prefill-hash=4',0);
219
insert into t1 values ('aaag', 'prefill-hash=3',0);
220
insert into t1 values ('aaah', 'prefill-hash=6',0);
221
explain select * from t1 where a='aaaa';
222
id select_type table type possible_keys key key_len ref rows Extra
223
1 SIMPLE t1 ref a a 8 const 2 Using where
224
explain select * from t1 where a='aaab';
225
id select_type table type possible_keys key key_len ref rows Extra
226
1 SIMPLE t1 ref a a 8 const 2 Using where
227
explain select * from t1 where a='aaac';
228
id select_type table type possible_keys key key_len ref rows Extra
229
1 SIMPLE t1 ref a a 8 const 2 Using where
230
explain select * from t1 where a='aaad';
231
id select_type table type possible_keys key key_len ref rows Extra
232
1 SIMPLE t1 ref a a 8 const 2 Using where
233
insert into t1 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 8 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 8 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 8 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 8 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 8 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 8 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 8 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 8 const 2 Using where
260
create table t2 as select * from t1;
262
insert into t1 select * from t2;
263
explain select * from t1 where a='aaaa';
264
id select_type table type possible_keys key key_len ref rows Extra
265
1 SIMPLE t1 ref a a 8 const 2 Using where
266
explain select * from t1 where a='aaab';
267
id select_type table type possible_keys key key_len ref rows Extra
268
1 SIMPLE t1 ref a a 8 const 2 Using where
269
explain select * from t1 where a='aaac';
270
id select_type table type possible_keys key key_len ref rows Extra
271
1 SIMPLE t1 ref a a 8 const 2 Using where
272
explain select * from t1 where a='aaad';
273
id select_type table type possible_keys key key_len ref rows Extra
274
1 SIMPLE t1 ref a a 8 const 2 Using where
277
id int unsigned not null primary key auto_increment,
278
name varchar(20) not null,
279
index heap_idx(name),
280
index btree_idx using btree(name)
283
id int unsigned not null primary key auto_increment,
284
name varchar(20) not null,
285
index btree_idx using btree(name),
288
insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'),
289
('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'),
291
insert into t2 select * from t1;
292
explain select * from t1 where name='matt';
293
id select_type table type possible_keys key key_len ref rows Extra
294
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where
295
explain select * from t2 where name='matt';
296
id select_type table type possible_keys key key_len ref rows Extra
297
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where
298
explain select * from t1 where name='Lilu';
299
id select_type table type possible_keys key key_len ref rows Extra
300
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where
301
explain select * from t2 where name='Lilu';
302
id select_type table type possible_keys key key_len ref rows Extra
303
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where
304
explain select * from t1 where name='Phil';
305
id select_type table type possible_keys key key_len ref rows Extra
306
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where
307
explain select * from t2 where name='Phil';
308
id select_type table type possible_keys key key_len ref rows Extra
309
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where
310
explain select * from t1 where name='Lilu';
311
id select_type table type possible_keys key key_len ref rows Extra
312
1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where
313
explain select * from t2 where name='Lilu';
314
id select_type table type possible_keys key key_len ref rows Extra
315
1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where
316
insert into t1 (name) select name from t2;
317
insert into t1 (name) select name from t2;
318
insert into t1 (name) select name from t2;
319
insert into t1 (name) select name from t2;
320
insert into t1 (name) select name from t2;
321
insert into t1 (name) select name from t2;
323
select count(*) from t1 where name='Matt';
326
explain select * from t1 ignore index (btree_idx) where name='matt';
327
id select_type table type possible_keys key key_len ref rows Extra
328
1 SIMPLE t1 ref heap_idx heap_idx 22 const 7 Using where
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 13 NULL NULL HASH
333
t1 1 btree_idx 1 name A NULL NULL NULL BTREE
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 13 NULL NULL HASH
338
t1 1 btree_idx 1 name A NULL NULL NULL BTREE
341
a varchar(20) not null,
342
b varchar(20) not null,
345
insert into t3 select name, name from t1;
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
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
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;
355
id select_type table type possible_keys key key_len ref rows Extra
356
1 SIMPLE t1 ref heap_idx heap_idx 22 const 7 Using where
357
1 SIMPLE t3 ref a a 44 func,const 7 Using where
358
drop table t1, t2, t3;
359
create temporary table t1 ( a int, index (a) ) engine=memory;
360
insert into t1 values (1),(2),(3),(4),(5);
361
select a from t1 where a in (1,3);
365
explain select a from t1 where a in (1,3);
366
id select_type table type possible_keys key key_len ref rows Extra
367
1 SIMPLE t1 range a a 5 NULL 4 Using where
370
CREATE TABLE t1(col1 VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
371
col2 VARCHAR(32) CHARACTER SET utf8 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'
377
CREATE TABLE t1(col1 VARCHAR(32) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
378
col2 VARCHAR(32) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,
379
UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY;
380
INSERT INTO t1 VALUES('A', 'A');
381
INSERT INTO t1 VALUES('A ', 'A ');
382
ERROR 23000: Duplicate entry 'A -A ' for key 'key1'