1
1
drop table if exists t1,t2,t3;
2
create temporary table t1 (a int not null,b int not null, primary key (a)) engine=MEMORY comment="testing heaps";
2
create table t1 (a int not null,b int not null, primary key (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 NULL 3 NULL NULL HASH
27
24
alter table t1 add c int not null, add key (c,a);
29
create temporary table t1 (a int not null,b int not null, primary key (a)) engine=memory comment="testing heaps";
26
create table t1 (a int not null,b int not null, primary key (a)) engine=memory comment="testing heaps";
30
27
insert into t1 values(1,1),(2,2),(3,3),(4,4);
31
28
delete from t1 where a > 0;
35
create temporary table t1 (a int not null,b int not null, primary key (a)) engine=MEMORY comment="testing heaps";
32
create table t1 (a int not null,b int not null, primary key (a)) engine=heap comment="testing heaps";
36
33
insert into t1 values(1,1),(2,2),(3,3),(4,4);
37
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 # # # # #
34
alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table";
72
create temporary table t2 SELECT * FROM t1;
73
explain select * from t2 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);
74
68
id select_type table type possible_keys key key_len ref rows Extra
75
1 SIMPLE t2 ALL NULL NULL NULL NULL 5 Using where
77
create temporary table t1 (x int not null, y int not null, key x (x), unique y (y))
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 (x), unique y (y))
79
73
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
80
74
select * from t1 where x=1;
84
78
select * from t1,t1 as t2 where t1.x=t2.y;
85
ERROR HY000: Can't reopen table: 't1'
86
86
explain select * from t1,t1 as t2 where t1.x=t2.y;
87
ERROR HY000: Can't reopen table: 't1'
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
89
create temporary table t1 (a int) engine=MEMORY;
91
create table t1 (a int) engine=heap;
90
92
insert into t1 values(1);
91
93
select max(a) from t1;
95
CREATE TEMPORARY TABLE t1 ( a int not null default 0, b int not null default 0, key(a), key(b) ) ENGINE=MEMORY;
97
CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key(a), key(b) ) ENGINE=HEAP;
96
98
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
97
99
select * from t1 where a=1;
130
132
replace into t1 values(1);
132
create temporary table t1 (n int) engine=MEMORY;
134
create table t1 (n int) engine=heap;
134
create temporary table t1 (n int) engine=MEMORY;
136
create table t1 (n int) engine=heap;
135
137
drop table if exists t1;
136
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not
137
null,index(f2)) engine=MEMORY;
138
CREATE table t1(f1 int not null,f2 char(20) not
139
null,index(f2)) engine=heap;
138
140
INSERT into t1 set f1=12,f2="bill";
139
141
INSERT into t1 set f1=13,f2="bill";
140
142
INSERT into t1 set f1=14,f2="bill";
156
create temporary table t1 (btn char(10) not null, key(btn)) engine=MEMORY;
158
create table t1 (btn char(10) not null, key(btn)) engine=heap;
157
159
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
158
160
explain select * from t1 where btn like "q%";
159
161
id select_type table type possible_keys key key_len ref rows Extra
169
171
id select_type table type possible_keys key key_len ref rows Extra
170
172
1 SIMPLE t1 ref btn btn 48 const,const 2 Using where
172
CREATE TEMPORARY TABLE t1 (
173
175
a int default NULL,
174
176
b int default NULL,
178
180
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
179
181
SELECT * FROM t1 WHERE a=NULL;
195
197
INSERT INTO t1 VALUES (1,3);
196
198
ERROR 23000: Duplicate entry '3' for key 'b'
198
CREATE TEMPORARY TABLE t1 (
199
201
a int default NULL,
202
204
INSERT INTO t1 VALUES (10), (10), (10);
203
205
EXPLAIN SELECT * FROM t1 WHERE a=10;
204
206
id select_type table type possible_keys key key_len ref rows Extra
212
CREATE TEMPORARY TABLE t1 (a int not null, primary key(a)) engine=MEMORY;
214
CREATE TABLE t1 (a int not null, primary key(a)) engine=heap;
213
215
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
214
216
DELETE from t1 where a < 100;
215
217
SELECT * from t1;
218
CREATE TEMPORARY TABLE `job_titles` (
220
CREATE TABLE `job_titles` (
219
221
`job_title_id` int NOT NULL default '0',
220
222
`job_title` char(18) NOT NULL default '',
221
223
PRIMARY KEY (`job_title_id`),
222
224
UNIQUE KEY `job_title_id` (`job_title_id`,`job_title`)
224
226
SELECT MAX(job_title_id) FROM job_titles;
225
227
MAX(job_title_id)
227
229
DROP TABLE job_titles;
228
CREATE TEMPORARY TABLE t1 (a INT NOT NULL, B INT, KEY(B)) ENGINE=MEMORY;
230
CREATE TABLE t1 (a INT NOT NULL, B INT, KEY(B)) ENGINE=HEAP;
229
231
INSERT INTO t1 VALUES(1,1), (1,NULL);
230
232
SELECT * FROM t1 WHERE B is not null;
234
CREATE TEMPORARY TABLE t1 (pseudo char(35) PRIMARY KEY, date int NOT NULL) ENGINE=MEMORY;
236
CREATE TABLE t1 (pseudo char(35) PRIMARY KEY, date int NOT NULL) ENGINE=HEAP;
235
237
INSERT INTO t1 VALUES ('massecot',1101106491),('altec',1101106492),('stitch+',1101106304),('Seb Corgan',1101106305),('beerfilou',1101106263),('flaker',1101106529),('joce8',5),('M4vrick',1101106418),('gabay008',1101106525),('Vamp irX',1101106291),('ZoomZip',1101106546),('rip666',1101106502),('CBP ',1101106397),('guezpard',1101106496);
236
238
DELETE FROM t1 WHERE date<1101106546;
237
239
SELECT * FROM t1;
239
241
ZoomZip 1101106546
241
create temporary table t1(a char(2)) engine=memory;
243
create table t1(a char(2)) engine=memory;
242
244
insert into t1 values (NULL), (NULL);
243
245
delete from t1 where a is null;
244
246
insert into t1 values ('2'), ('3');
250
set storage_engine=MEMORY;
251
create temporary table t1 (v varchar(10), c char(10), t varchar(50));
252
set storage_engine=HEAP;
253
create table t1 (v varchar(10), c char(10), t varchar(50));
252
254
insert into t1 values('+ ', '+ ', '+ ');
253
255
set @a=repeat(' ',20);
254
256
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
262
264
show create table t1;
263
265
Table Create Table
264
t1 CREATE TEMPORARY TABLE `t1` (
266
t1 CREATE TABLE `t1` (
265
267
`v` varchar(10) DEFAULT NULL,
266
268
`c` varchar(10) DEFAULT NULL,
267
269
`t` varchar(50) DEFAULT NULL
269
create temporary table t2 like t1;
271
create table t2 like t1;
270
272
show create table t2;
271
273
Table Create Table
272
t2 CREATE TEMPORARY TABLE `t2` (
274
t2 CREATE TABLE `t2` (
273
275
`v` varchar(10) DEFAULT NULL,
274
276
`c` varchar(10) DEFAULT NULL,
275
277
`t` varchar(50) DEFAULT NULL
277
create temporary table t3 select * from t1;
279
create table t3 select * from t1;
278
280
show create table t3;
279
281
Table Create Table
280
t3 CREATE TEMPORARY TABLE `t3` (
282
t3 CREATE TABLE `t3` (
281
283
`v` varchar(10) DEFAULT NULL,
282
284
`c` varchar(10) DEFAULT NULL,
283
285
`t` varchar(50) DEFAULT NULL
313
315
drop table t1,t2,t3;
314
create temporary table t1 (v varchar(10), c char(10), t varchar(50), key(v), key(c), key(t(10)));
316
create table t1 (v varchar(10), c char(10), t varchar(50), key(v), key(c), key(t(10)));
315
317
show create table t1;
316
318
Table Create Table
317
t1 CREATE TEMPORARY TABLE `t1` (
319
t1 CREATE TABLE `t1` (
318
320
`v` varchar(10) DEFAULT NULL,
319
321
`c` varchar(10) DEFAULT NULL,
320
322
`t` varchar(50) DEFAULT NULL,
325
327
select count(*) from t1;
534
536
update t1 set a='a ' where a like 'a ';
535
537
update t1 set a='a ' where a like 'a ';
537
create temporary table t1 (v varchar(10), c char(10), t varchar(50), key using btree (v), key using btree (c), key using btree (t(10)));
539
create table t1 (v varchar(10), c char(10), t varchar(50), key using btree (v), key using btree (c), key using btree (t(10)));
538
540
show create table t1;
539
541
Table Create Table
540
t1 CREATE TEMPORARY TABLE `t1` (
542
t1 CREATE TABLE `t1` (
541
543
`v` varchar(10) DEFAULT NULL,
542
544
`c` varchar(10) DEFAULT NULL,
543
545
`t` varchar(50) DEFAULT NULL,
544
546
KEY `v` (`v`) USING BTREE,
545
547
KEY `c` (`c`) USING BTREE,
546
KEY `t` (`t`(10)) USING BTREE
548
KEY `t` (`t`()) USING BTREE
548
550
select count(*) from t1;
609
611
id select_type table type possible_keys key key_len ref rows Extra
610
612
1 SIMPLE t1 ref v v 43 const # Using where
612
create temporary table t1 (a char(10), unique using btree (a)) engine=MEMORY;
614
create table t1 (a char(10), unique using btree (a)) engine=heap;
613
615
insert into t1 values ('a');
614
616
insert into t1 values ('a ');
615
617
ERROR 23000: Duplicate entry 'a ' for key 'a'
625
627
update t1 set a='a ' where a like 'a ';
626
628
update t1 set a='a ' where a like 'a ';
628
create temporary table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5)));
630
create table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5)));
629
631
show create table t1;
630
632
Table Create Table
631
t1 CREATE TEMPORARY TABLE `t1` (
633
t1 CREATE TABLE `t1` (
632
634
`v` varchar(10) DEFAULT NULL,
633
635
`c` varchar(10) DEFAULT NULL,
634
636
`t` varchar(50) DEFAULT NULL,
640
create temporary table t1 (v varchar(16383), key(v(10)));
642
create table t1 (v varchar(16383), key(v(10)));
641
643
show create table t1;
642
644
Table Create Table
643
t1 CREATE TEMPORARY TABLE `t1` (
645
t1 CREATE TABLE `t1` (
644
646
`v` varchar(16383) DEFAULT NULL,
647
649
insert into t1 values(repeat('a',16383));
648
650
select length(v) from t1 where v=repeat('a',16383);
652
654
set storage_engine=InnoDB;
653
create temporary table t1 (a bigint auto_increment primary key, b int,
654
key (b, a)) engine=MEMORY;
655
create table t1 (a bigint auto_increment primary key, b int,
656
key (b, a)) engine=heap;
655
657
insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1);
656
658
select * from t1;
667
create temporary table t1 (a int not null, b int not null auto_increment,
668
primary key(a, b), key(b)) engine=MEMORY;
669
create table t1 (a int not null, b int not null auto_increment,
670
primary key(a, b), key(b)) engine=heap;
669
671
insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1);
670
672
select * from t1;
681
create temporary table t1 (a int not null, b int not null auto_increment,
682
primary key(a, b)) engine=MEMORY;
683
create table t1 (a int not null, b int not null auto_increment,
684
primary key(a, b)) engine=heap;
683
685
ERROR 42000: Incorrect table definition; there can be only one auto column and it must be defined as a key
684
create temporary table t1 (c char(255), primary key(c(90)));
686
create table t1 (c char(255), primary key(c(90)));
685
687
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
686
688
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
687
689
ERROR 23000: Duplicate entry 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl' for key 'PRIMARY'
689
CREATE TEMPORARY TABLE t1 (a int, key(a)) engine=MEMORY;
691
CREATE TABLE t1 (a int, key(a)) engine=heap;
690
692
insert into t1 values (0);
692
694
select * from t1;
699
create temporary table t1 (c char(10)) engine=memory;
700
create temporary table t2 (c varchar(10)) engine=memory;
701
create table t1 (c char(10)) engine=memory;
702
create table t2 (c varchar(10)) engine=memory;
701
703
show table status like 't_';
702
Session Schema Name Type Engine Version Rows Avg_row_length Table_size Auto_increment
703
# test t1 TEMPORARY MEMORY # # # # #
704
# test t2 TEMPORARY MEMORY # # # # #
704
Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
705
t1 MEMORY # Fixed 0 42 0 # 0 0 NULL NULL NULL NULL utf8_general_ci NULL
706
t2 MEMORY # Fixed 0 42 0 # 0 0 NULL NULL NULL NULL utf8_general_ci NULL
705
707
drop table t1, t2;
706
CREATE TEMPORARY TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
708
CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
707
709
KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY;
708
710
INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256));
709
711
SELECT COUNT(*) FROM t1 WHERE a='a';