1
drop table if exists t1;
2
create table t1 (a int not null,b int not null, primary key using BTREE (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 A NULL NULL NULL BTREE
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 BTREE (c,a);
26
create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps";
27
insert into t1 values(-2,-2),(-1,-1),(0,0),(1,1),(2,2),(3,3),(4,4);
28
delete from t1 where a > -3;
32
create table t1 (a int not null,b int not null, primary key using BTREE (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 BTREE (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 BTREE (x,y), unique y using BTREE (y))
73
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
74
explain select * from t1 where x=1;
75
id select_type table type possible_keys key key_len ref rows Extra
76
1 SIMPLE t1 ref x x 4 const 1
77
select * from t1 where x=1;
81
select * from t1,t1 as t2 where t1.x=t2.y;
89
explain select * from t1,t1 as t2 where t1.x=t2.y;
90
id select_type table type possible_keys key key_len ref rows Extra
91
1 SIMPLE t1 ALL x NULL NULL NULL 6
92
1 SIMPLE t2 eq_ref y y 4 test.t1.x 1
94
create table t1 (a int) engine=heap;
95
insert into t1 values(1);
96
select max(a) from t1;
100
CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key using BTREE (a,b), key using BTREE (b) ) ENGINE=HEAP;
101
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
102
select * from t1 where a=1;
110
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
111
select * from t1 where a=1;
125
explain select * from tx where a=x order by a,b;
126
id select_type table type possible_keys key key_len ref rows Extra
127
x SIMPLE tx ref a a x const x Using where
128
explain select * from tx where a=x order by b;
129
id select_type table type possible_keys key key_len ref rows Extra
130
x SIMPLE tx ref a a x const x Using where
131
select * from t1 where b=1;
135
explain select * from tx where b=x;
136
id select_type table type possible_keys key key_len ref rows Extra
137
x SIMPLE tx ref b b x const x
139
create table t1 (id int unsigned not null, primary key using BTREE (id)) engine=HEAP;
140
insert into t1 values(1);
141
select max(id) from t1;
144
insert into t1 values(2);
145
select max(id) from t1;
148
replace into t1 values(1);
150
create table t1 (n int) engine=heap;
152
create table t1 (n int) engine=heap;
153
drop table if exists t1;
154
CREATE table t1(f1 int not null,f2 char(20) not
155
null,index(f2)) engine=heap;
156
INSERT into t1 set f1=12,f2="bill";
157
INSERT into t1 set f1=13,f2="bill";
158
INSERT into t1 set f1=14,f2="bill";
159
INSERT into t1 set f1=15,f2="bill";
160
INSERT into t1 set f1=16,f2="ted";
161
INSERT into t1 set f1=12,f2="ted";
162
INSERT into t1 set f1=12,f2="ted";
163
INSERT into t1 set f1=12,f2="ted";
164
INSERT into t1 set f1=12,f2="ted";
165
delete from t1 where f2="bill";
174
create table t1 (btn char(10) not null, key using BTREE (btn)) engine=heap;
175
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
176
explain select * from t1 where btn like "i%";
177
id select_type table type possible_keys key key_len ref rows Extra
178
1 SIMPLE t1 range btn btn 10 NULL 1 Using where
179
explain select * from t1 where btn like "h%";
180
id select_type table type possible_keys key key_len ref rows Extra
181
1 SIMPLE t1 range btn btn 10 NULL # Using where
182
explain select * from t1 where btn like "a%";
183
id select_type table type possible_keys key key_len ref rows Extra
184
1 SIMPLE t1 range btn btn 10 NULL 1 Using where
185
explain select * from t1 where btn like "b%";
186
id select_type table type possible_keys key key_len ref rows Extra
187
1 SIMPLE t1 range btn btn 10 NULL 1 Using where
188
select * from t1 where btn like "ff%";
190
select * from t1 where btn like " %";
192
select * from t1 where btn like "q%";
194
alter table t1 add column new_col char(1) not null, add key using BTREE (btn,new_col), drop key btn;
195
update t1 set new_col=left(btn,1);
196
explain select * from t1 where btn="a";
197
id select_type table type possible_keys key key_len ref rows Extra
198
1 SIMPLE t1 ref btn btn 10 const 1 Using where
199
explain select * from t1 where btn="a" and new_col="a";
200
id select_type table type possible_keys key key_len ref rows Extra
201
1 SIMPLE t1 ref btn btn 11 const,const 1 Using where
206
KEY a using BTREE (a),
207
UNIQUE b using BTREE (b)
209
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
210
SELECT * FROM t1 WHERE a=NULL;
212
explain SELECT * FROM t1 WHERE a IS NULL;
213
id select_type table type possible_keys key key_len ref rows Extra
214
1 SIMPLE t1 ref a a 5 const 1 Using where
215
SELECT * FROM t1 WHERE a<=>NULL;
218
SELECT * FROM t1 WHERE b=NULL;
220
explain SELECT * FROM t1 WHERE b IS NULL;
221
id select_type table type possible_keys key key_len ref rows Extra
222
1 SIMPLE t1 ref b b 5 const 1 Using where
223
SELECT * FROM t1 WHERE b<=>NULL;
226
INSERT INTO t1 VALUES (1,3);
227
ERROR 23000: Duplicate entry '3' for key 'b'
229
CREATE TABLE t1 (a int, b int, c int, key using BTREE (a, b, c)) engine=heap;
230
INSERT INTO t1 VALUES (1, NULL, NULL), (1, 1, NULL), (1, NULL, 1);
231
SELECT * FROM t1 WHERE a=1 and b IS NULL;
235
SELECT * FROM t1 WHERE a=1 and c IS NULL;
239
SELECT * FROM t1 WHERE a=1 and b IS NULL and c IS NULL;
243
CREATE TABLE t1 (a int not null, primary key using BTREE (a)) engine=heap;
244
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
245
DELETE from t1 where a < 100;
249
create table t1(a int not null, key using btree(a)) engine=heap;
250
insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3);
251
select a from t1 where a > 2 order by a;
257
delete from t1 where a < 4;
258
select a from t1 order by a;
260
insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3);
261
select a from t1 where a > 4 order by a;
263
delete from t1 where a > 4;
264
select a from t1 order by a;
275
select a from t1 where a > 3 order by a;
277
delete from t1 where a >= 2;
278
select a from t1 order by a;
289
INSERT INTO t1 VALUES ('ABC',0), ('A',0), ('B',0), ('C',0);
290
UPDATE t1 SET c2= c2 + 1 WHERE c1 = 'A';
300
UNIQUE USING BTREE(c1)
301
) ENGINE= MEMORY DEFAULT CHARSET= utf8;
302
INSERT INTO t1 VALUES('1'), ('2');
306
UNIQUE USING BTREE(c1)
307
) ENGINE= MEMORY DEFAULT CHARSET= utf8;
308
INSERT INTO t1 VALUES('1'), ('2');
310
CREATE TABLE t1 (a INT, KEY USING BTREE(a)) ENGINE=MEMORY;
311
INSERT INTO t1 VALUES(1),(2),(2);
312
DELETE FROM t1 WHERE a=2;
318
CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
319
INSERT INTO t1 VALUES(0);
320
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
324
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
328
CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY;
329
INSERT INTO t1 VALUES(NULL),(NULL);
331
create table t1(a varchar(255), b varchar(255),
332
key using btree (a,b)) engine=memory;
333
insert into t1 values (1, 1), (3, 3), (2, 2), (NULL, 1), (NULL, NULL), (0, 0);
334
select * from t1 where a is null;