1
1
drop table if exists t1;
2
create temporary table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=MEMORY comment="testing heaps";
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
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 A NULL NULL NULL BTREE
27
alter table t1 add c int DEFAULT 42 not null, add key using BTREE (c,a);
24
alter table t1 add c int not null, add key using BTREE (c,a);
29
create temporary table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=MEMORY comment="testing heaps";
26
create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps";
30
27
insert into t1 values(-2,-2),(-1,-1),(0,0),(1,1),(2,2),(3,3),(4,4);
31
28
delete from t1 where a > -3;
35
create temporary table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=MEMORY comment="testing heaps";
32
create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps";
36
33
insert into t1 values(1,1),(2,2),(3,3),(4,4);
37
34
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 # # # # #
74
68
id select_type table type possible_keys key key_len ref rows Extra
75
69
1 SIMPLE t1 index uniq_id uniq_id 4 NULL 5 Using where; Using index
77
create temporary table t1 (x int not null, y int not null, key x using BTREE (x,y), unique y using BTREE (y))
71
create table t1 (x int not null, y int not null, key x using BTREE (x,y), unique y using BTREE (y))
79
73
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
80
74
explain select * from t1 where x=1;
81
75
id select_type table type possible_keys key key_len ref rows Extra
82
1 SIMPLE t1 ALL x NULL NULL NULL 6 Using where
76
1 SIMPLE t1 ref x x 4 const 1
83
77
select * from t1 where x=1;
87
81
select * from t1,t1 as t2 where t1.x=t2.y;
88
ERROR HY000: Can't reopen table: 't1'
89
89
explain select * from t1,t1 as t2 where t1.x=t2.y;
90
ERROR HY000: Can't reopen table: 't1'
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
92
create temporary table t1 (a int) engine=MEMORY;
94
create table t1 (a int) engine=heap;
93
95
insert into t1 values(1);
94
96
select max(a) from t1;
98
CREATE TEMPORARY TABLE t1 ( a int not null default 0, b int not null default 0, key using BTREE (a,b), key using BTREE (b) ) ENGINE=MEMORY;
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;
108
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
109
select * from t1 where a=1;
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;
123
125
explain select * from tx where a=x order by a,b;
124
126
id select_type table type possible_keys key key_len ref rows Extra
125
x SIMPLE tx ALL a NULL NULL NULL x Using where; Using filesort
127
x SIMPLE tx ref a a x const x Using where
126
128
explain select * from tx where a=x order by b;
127
129
id select_type table type possible_keys key key_len ref rows Extra
128
x SIMPLE tx ALL a NULL NULL NULL x Using where; Using filesort
130
x SIMPLE tx ref a a x const x Using where
129
131
select * from t1 where b=1;
146
148
replace into t1 values(1);
148
create temporary table t1 (n int) engine=MEMORY;
150
create table t1 (n int) engine=heap;
150
create temporary table t1 (n int) engine=MEMORY;
152
create table t1 (n int) engine=heap;
151
153
drop table if exists t1;
152
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not
153
null,index(f2)) engine=MEMORY;
154
CREATE table t1(f1 int not null,f2 char(20) not
155
null,index(f2)) engine=heap;
154
156
INSERT into t1 set f1=12,f2="bill";
155
157
INSERT into t1 set f1=13,f2="bill";
156
158
INSERT into t1 set f1=14,f2="bill";
172
create temporary table t1 (btn char(10) not null, key using BTREE (btn)) engine=MEMORY;
174
create table t1 (btn char(10) not null, key using BTREE (btn)) engine=heap;
173
175
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
174
176
explain select * from t1 where btn like "i%";
175
177
id select_type table type possible_keys key key_len ref rows Extra
176
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
178
1 SIMPLE t1 range btn btn 42 NULL 1 Using where
177
179
explain select * from t1 where btn like "h%";
178
180
id select_type table type possible_keys key key_len ref rows Extra
179
1 SIMPLE t1 ALL btn NULL NULL NULL # Using where
181
1 SIMPLE t1 range btn btn 42 NULL # Using where
180
182
explain select * from t1 where btn like "a%";
181
183
id select_type table type possible_keys key key_len ref rows Extra
182
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
184
1 SIMPLE t1 range btn btn 42 NULL 1 Using where
183
185
explain select * from t1 where btn like "b%";
184
186
id select_type table type possible_keys key key_len ref rows Extra
185
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
187
1 SIMPLE t1 range btn btn 42 NULL 1 Using where
186
188
select * from t1 where btn like "ff%";
188
190
select * from t1 where btn like " %";
190
192
select * from t1 where btn like "q%";
192
alter table t1 add column new_col char(1) DEFAULT "Y" not null, add key using BTREE (btn,new_col), drop key btn;
194
alter table t1 add column new_col char(1) not null, add key using BTREE (btn,new_col), drop key btn;
193
195
update t1 set new_col=left(btn,1);
194
196
explain select * from t1 where btn="a";
195
197
id select_type table type possible_keys key key_len ref rows Extra
196
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
198
1 SIMPLE t1 ref btn btn 42 const 1 Using where
197
199
explain select * from t1 where btn="a" and new_col="a";
198
200
id select_type table type possible_keys key key_len ref rows Extra
199
1 SIMPLE t1 ref btn btn 48 const,const 2 Using where
201
1 SIMPLE t1 ref btn btn 48 const,const 1 Using where
201
CREATE TEMPORARY TABLE t1 (
202
204
a int default NULL,
203
205
b int default NULL,
204
206
KEY a using BTREE (a),
205
207
UNIQUE b using BTREE (b)
207
209
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
208
210
SELECT * FROM t1 WHERE a=NULL;
210
212
explain SELECT * FROM t1 WHERE a IS NULL;
211
213
id select_type table type possible_keys key key_len ref rows Extra
212
1 SIMPLE t1 ref a a 5 const 2 Using where
214
1 SIMPLE t1 ref a a 5 const 1 Using where
213
215
SELECT * FROM t1 WHERE a<=>NULL;
224
226
INSERT INTO t1 VALUES (1,3);
225
227
ERROR 23000: Duplicate entry '3' for key 'b'
227
CREATE TEMPORARY TABLE t1 (a int, b int, c int, key using BTREE (a, b, c)) engine=MEMORY;
229
CREATE TABLE t1 (a int, b int, c int, key using BTREE (a, b, c)) engine=heap;
228
230
INSERT INTO t1 VALUES (1, NULL, NULL), (1, 1, NULL), (1, NULL, 1);
229
231
SELECT * FROM t1 WHERE a=1 and b IS NULL;
241
CREATE TEMPORARY TABLE t1 (a int not null, primary key using BTREE (a)) engine=MEMORY;
243
CREATE TABLE t1 (a int not null, primary key using BTREE (a)) engine=heap;
242
244
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
243
245
DELETE from t1 where a < 100;
244
246
SELECT * from t1;
247
create temporary table t1(a int not null, key using btree(a)) engine=MEMORY;
249
create table t1(a int not null, key using btree(a)) engine=heap;
248
250
insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3);
249
251
select a from t1 where a > 2 order by a;
310
CREATE TEMPORARY TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY;
312
CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
313
INSERT INTO t1 VALUES(0);
314
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
318
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
322
CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY;
311
323
INSERT INTO t1 VALUES(NULL),(NULL);
313
create temporary table t1(a varchar(255), b varchar(255),
325
create table t1(a varchar(255), b varchar(255),
314
326
key using btree (a,b)) engine=memory;
315
327
insert into t1 values (1, 1), (3, 3), (2, 2), (NULL, 1), (NULL, NULL), (0, 0);
316
328
select * from t1 where a is null;