1
drop table if exists t1;
2
create table t1 (a int not null,b int not null, primary key using HASH (a)) type=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
7
t1 0 PRIMARY 1 a NULL NULL 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)) type=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)) type=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, type=myisam, comment="new myisam table";
42
create table t1 (a int not null) type=heap;
43
insert into t1 values (869751),(736494),(226312),(802616);
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 type=myisam;
67
explain select * from t1 where a in (869751,736494,226312,802616);
68
table type possible_keys key key_len ref rows Extra
69
t1 range uniq_id uniq_id 4 NULL 4 where used; 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
table type possible_keys key key_len ref rows Extra
88
t1 ALL x NULL NULL NULL 6
89
t2 eq_ref y y 4 t1.x 1
91
create table t1 (a int) type=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) ) TYPE=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)) type=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) type=heap;
136
create table t1 (n int) type=heap;
137
drop table if exists t1;
138
CREATE table t1(f1 int not null,f2 char(20) not
139
null,index(f2)) type=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)) type=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
table type possible_keys key key_len ref rows Extra
162
t1 ALL btn NULL NULL NULL 14 where used
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=btn;
167
explain select * from t1 where btn="a";
168
table type possible_keys key key_len ref rows Extra
169
t1 ALL btn NULL NULL NULL 14 where used
170
explain select * from t1 where btn="a" and new_col="a";
171
table type possible_keys key key_len ref rows Extra
172
t1 ref btn btn 11 const,const 10 where used
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
table type possible_keys key key_len ref rows Extra
185
t1 ref a a 5 const 10 where used
186
SELECT * FROM t1 WHERE a<=>NULL;
189
SELECT * FROM t1 WHERE b=NULL;
191
explain SELECT * FROM t1 WHERE b IS NULL;
192
table type possible_keys key key_len ref rows Extra
193
t1 ref b b 5 const 1 where used
194
SELECT * FROM t1 WHERE b<=>NULL;
197
INSERT INTO t1 VALUES (1,3);
198
Duplicate entry '3' for key 1
200
CREATE TABLE t1 (a int not null, primary key using HASH (a)) type=heap;
201
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
202
DELETE from t1 where a < 100;