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";
3
insert into t1 values(1,1),(2,2),(3,3),(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
16
select * from t1 where a=4;
19
update t1 set b=5 where a=4;
20
update t1 set b=b+1 where a>=3;
21
replace t1 values (3,3);
27
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";
30
insert into t1 values(1,1),(2,2),(3,3),(4,4);
31
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";
36
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 # # # # #
48
create temporary table t1 (a int not null) engine=MEMORY;
49
insert into t1 values (869751),(736494),(226312),(802616),(728912);
50
select * from t1 where a > 736494;
54
alter table t1 add unique uniq_id(a);
55
select * from t1 where a > 736494;
59
select * from t1 where a = 736494;
62
select * from t1 where a=869751 or a=736494;
66
select * from t1 where a in (869751,736494,226312,802616);
72
create temporary table t2 SELECT * FROM t1;
73
explain select * from t2 where a in (869751,736494,226312,802616);
74
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))
79
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
80
select * from t1 where x=1;
84
select * from t1,t1 as t2 where t1.x=t2.y;
85
ERROR HY000: Can't reopen table: 't1'
86
explain select * from t1,t1 as t2 where t1.x=t2.y;
87
ERROR HY000: Can't reopen table: 't1'
89
create temporary table t1 (a int) engine=MEMORY;
90
insert into t1 values(1);
91
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;
96
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
97
select * from t1 where a=1;
105
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
106
select * from t1 where a=1;
121
create temporary table t1 (id int not null, primary key (id)) engine=MEMORY;
122
insert into t1 values(1);
123
select max(id) from t1;
126
insert into t1 values(2);
127
select max(id) from t1;
130
replace into t1 values(1);
132
create temporary table t1 (n int) engine=MEMORY;
134
create temporary table t1 (n int) engine=MEMORY;
135
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
INSERT into t1 set f1=12,f2="bill";
139
INSERT into t1 set f1=13,f2="bill";
140
INSERT into t1 set f1=14,f2="bill";
141
INSERT into t1 set f1=15,f2="bill";
142
INSERT into t1 set f1=16,f2="ted";
143
INSERT into t1 set f1=12,f2="ted";
144
INSERT into t1 set f1=12,f2="ted";
145
INSERT into t1 set f1=12,f2="ted";
146
INSERT into t1 set f1=12,f2="ted";
147
delete from t1 where f2="bill";
156
create temporary table t1 (btn char(10) not null, key(btn)) engine=MEMORY;
157
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
158
explain select * from t1 where btn like "q%";
159
id select_type table type possible_keys key key_len ref rows Extra
160
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
161
select * from t1 where btn like "q%";
163
alter table t1 add column new_col char(1) not null, add key (btn,new_col), drop key btn;
164
update t1 set new_col=left(btn,1);
165
explain select * from t1 where btn="a";
166
id select_type table type possible_keys key key_len ref rows Extra
167
1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where
168
explain select * from t1 where btn="a" and new_col="a";
169
id select_type table type possible_keys key key_len ref rows Extra
170
1 SIMPLE t1 ref btn btn 48 const,const 2 Using where
172
CREATE TEMPORARY TABLE t1 (
178
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
179
SELECT * FROM t1 WHERE a=NULL;
181
explain SELECT * FROM t1 WHERE a IS NULL;
182
id select_type table type possible_keys key key_len ref rows Extra
183
1 SIMPLE t1 ref a a 5 const 2 Using where
184
SELECT * FROM t1 WHERE a<=>NULL;
187
SELECT * FROM t1 WHERE b=NULL;
189
explain SELECT * FROM t1 WHERE b IS NULL;
190
id select_type table type possible_keys key key_len ref rows Extra
191
1 SIMPLE t1 ref b b 5 const 1 Using where
192
SELECT * FROM t1 WHERE b<=>NULL;
195
INSERT INTO t1 VALUES (1,3);
196
ERROR 23000: Duplicate entry '3' for key 'b'
198
CREATE TEMPORARY TABLE t1 (
202
INSERT INTO t1 VALUES (10), (10), (10);
203
EXPLAIN SELECT * FROM t1 WHERE a=10;
204
id select_type table type possible_keys key key_len ref rows Extra
205
1 SIMPLE t1 ref a a 5 const 3
206
SELECT * FROM t1 WHERE a=10;
212
CREATE TEMPORARY TABLE t1 (a int not null, primary key(a)) engine=MEMORY;
213
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
214
DELETE from t1 where a < 100;
218
CREATE TEMPORARY TABLE `job_titles` (
219
`job_title_id` int NOT NULL default '0',
220
`job_title` char(18) NOT NULL default '',
221
PRIMARY KEY (`job_title_id`),
222
UNIQUE KEY `job_title_id` (`job_title_id`,`job_title`)
224
SELECT MAX(job_title_id) FROM job_titles;
227
DROP TABLE job_titles;
228
CREATE TEMPORARY TABLE t1 (a INT NOT NULL, B INT, KEY(B)) ENGINE=MEMORY;
229
INSERT INTO t1 VALUES(1,1), (1,NULL);
230
SELECT * FROM t1 WHERE B is not null;
234
CREATE TEMPORARY TABLE t1 (pseudo char(35) PRIMARY KEY, date int NOT NULL) ENGINE=MEMORY;
235
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
DELETE FROM t1 WHERE date<1101106546;
241
create temporary table t1(a char(2)) engine=memory;
242
insert into t1 values (NULL), (NULL);
243
delete from t1 where a is null;
244
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
insert into t1 values('+ ', '+ ', '+ ');
253
set @a=repeat(' ',20);
254
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
256
Note 1265 Data truncated for column 'v' at row 1
257
Note 1265 Data truncated for column 'c' at row 1
258
select concat('*',v,'*',c,'*',t,'*') from t1;
259
concat('*',v,'*',c,'*',t,'*')
262
show create table t1;
264
t1 CREATE TEMPORARY TABLE `t1` (
265
`v` varchar(10) DEFAULT NULL,
266
`c` varchar(10) DEFAULT NULL,
267
`t` varchar(50) DEFAULT NULL
269
create temporary table t2 like t1;
270
show create table t2;
272
t2 CREATE TEMPORARY TABLE `t2` (
273
`v` varchar(10) DEFAULT NULL,
274
`c` varchar(10) DEFAULT NULL,
275
`t` varchar(50) DEFAULT NULL
277
create temporary table t3 select * from t1;
278
show create table t3;
280
t3 CREATE TEMPORARY TABLE `t3` (
281
`v` varchar(10) DEFAULT NULL,
282
`c` varchar(10) DEFAULT NULL,
283
`t` varchar(50) DEFAULT NULL
285
alter table t1 modify c varchar(10);
286
show create table t1;
288
t1 CREATE TEMPORARY TABLE `t1` (
289
`v` varchar(10) DEFAULT NULL,
290
`c` varchar(10) DEFAULT NULL,
291
`t` varchar(50) DEFAULT NULL
293
alter table t1 modify v char(10);
294
show create table t1;
296
t1 CREATE TEMPORARY TABLE `t1` (
297
`v` varchar(10) DEFAULT NULL,
298
`c` varchar(10) DEFAULT NULL,
299
`t` varchar(50) DEFAULT NULL
301
alter table t1 modify t varchar(50);
302
show create table t1;
304
t1 CREATE TEMPORARY TABLE `t1` (
305
`v` varchar(10) DEFAULT NULL,
306
`c` varchar(10) DEFAULT NULL,
307
`t` varchar(50) DEFAULT NULL
309
select concat('*',v,'*',c,'*',t,'*') from t1;
310
concat('*',v,'*',c,'*',t,'*')
314
create temporary table t1 (v varchar(10), c char(10), t varchar(50), key(v), key(c), key(t(10)));
315
show create table t1;
317
t1 CREATE TEMPORARY TABLE `t1` (
318
`v` varchar(10) DEFAULT NULL,
319
`c` varchar(10) DEFAULT NULL,
320
`t` varchar(50) DEFAULT NULL,
325
select count(*) from t1;
328
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
329
select count(*) from t1 where v='a';
332
select count(*) from t1 where c='a';
335
select count(*) from t1 where t='a';
338
select count(*) from t1 where v='a ';
341
select count(*) from t1 where c='a ';
344
select count(*) from t1 where t='a ';
347
select count(*) from t1 where v between 'a' and 'a ';
350
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
353
select count(*) from t1 where v like 'a%';
356
select count(*) from t1 where c like 'a%';
359
select count(*) from t1 where t like 'a%';
362
select count(*) from t1 where v like 'a %';
365
explain select count(*) from t1 where v='a ';
366
id select_type table type possible_keys key key_len ref rows Extra
367
1 SIMPLE t1 ref v v 43 const 10 Using where
368
explain select count(*) from t1 where c='a ';
369
id select_type table type possible_keys key key_len ref rows Extra
370
1 SIMPLE t1 ref c c 43 const 10 Using where
371
explain select count(*) from t1 where t='a ';
372
id select_type table type possible_keys key key_len ref rows Extra
373
1 SIMPLE t1 ref t t 43 const 10 Using where
374
explain select count(*) from t1 where v like 'a%';
375
id select_type table type possible_keys key key_len ref rows Extra
376
1 SIMPLE t1 ALL v NULL NULL NULL 271 Using where
377
explain select count(*) from t1 where v between 'a' and 'a ';
378
id select_type table type possible_keys key key_len ref rows Extra
379
1 SIMPLE t1 ref v v 43 const 10 Using where
380
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
381
id select_type table type possible_keys key key_len ref rows Extra
382
1 SIMPLE t1 ref v v 43 const 10 Using where
383
alter table t1 add unique(v);
384
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
385
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*'));
397
explain select * from t1 where v='a';
398
id select_type table type possible_keys key key_len ref rows Extra
399
1 SIMPLE t1 ref v v 43 const 10 Using where
400
select v,count(*) from t1 group by v limit 10;
412
select v,count(t) from t1 group by v limit 10;
424
select v,count(c) from t1 group by v limit 10;
436
select sql_big_result trim(v),count(t) from t1 group by v limit 10;
448
select sql_big_result trim(v),count(c) from t1 group by v limit 10;
460
select c,count(*) from t1 group by c limit 10;
472
select c,count(t) from t1 group by c limit 10;
484
select t,count(*) from t1 group by t limit 10;
496
select t,count(t) from t1 group by t limit 10;
508
select sql_big_result trim(t),count(t) from t1 group by t limit 10;
521
create temporary table t1 (a char(10), unique (a));
522
insert into t1 values ('a');
523
insert into t1 values ('a ');
524
ERROR 23000: Duplicate entry 'a ' for key 'a'
525
alter table t1 modify a varchar(10);
526
insert into t1 values ('a '),('a '),('a '),('a ');
527
ERROR 23000: Duplicate entry 'a ' for key 'a'
528
insert into t1 values ('a ');
529
ERROR 23000: Duplicate entry 'a ' for key 'a'
530
insert into t1 values ('a ');
531
ERROR 23000: Duplicate entry 'a ' for key 'a'
532
insert into t1 values ('a ');
533
ERROR 23000: Duplicate entry 'a ' for key 'a'
534
update t1 set a='a ' where a like 'a ';
535
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)));
538
show create table t1;
540
t1 CREATE TEMPORARY TABLE `t1` (
541
`v` varchar(10) DEFAULT NULL,
542
`c` varchar(10) DEFAULT NULL,
543
`t` varchar(50) DEFAULT NULL,
544
KEY `v` (`v`) USING BTREE,
545
KEY `c` (`c`) USING BTREE,
546
KEY `t` (`t`(10)) USING BTREE
548
select count(*) from t1;
551
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
552
select count(*) from t1 where v='a';
555
select count(*) from t1 where c='a';
558
select count(*) from t1 where t='a';
561
select count(*) from t1 where v='a ';
564
select count(*) from t1 where c='a ';
567
select count(*) from t1 where t='a ';
570
select count(*) from t1 where v between 'a' and 'a ';
573
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
576
explain select count(*) from t1 where v='a ';
577
id select_type table type possible_keys key key_len ref rows Extra
578
1 SIMPLE t1 ref v v 43 const # Using where
579
explain select count(*) from t1 where c='a ';
580
id select_type table type possible_keys key key_len ref rows Extra
581
1 SIMPLE t1 ref c c 43 const # Using where
582
explain select count(*) from t1 where t='a ';
583
id select_type table type possible_keys key key_len ref rows Extra
584
1 SIMPLE t1 ref t t 43 const # Using where
585
explain select count(*) from t1 where v like 'a%';
586
id select_type table type possible_keys key key_len ref rows Extra
587
1 SIMPLE t1 range v v 43 NULL # Using where
588
explain select count(*) from t1 where v between 'a' and 'a ';
589
id select_type table type possible_keys key key_len ref rows Extra
590
1 SIMPLE t1 ref v v 43 const # Using where
591
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
592
id select_type table type possible_keys key key_len ref rows Extra
593
1 SIMPLE t1 ref v v 43 const # Using where
594
alter table t1 add unique(v);
595
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
596
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*'));
608
explain select * from t1 where v='a';
609
id select_type table type possible_keys key key_len ref rows Extra
610
1 SIMPLE t1 ref v v 43 const # Using where
612
create temporary table t1 (a char(10), unique using btree (a)) engine=MEMORY;
613
insert into t1 values ('a');
614
insert into t1 values ('a ');
615
ERROR 23000: Duplicate entry 'a ' for key 'a'
616
alter table t1 modify a varchar(10);
617
insert into t1 values ('a '),('a '),('a '),('a ');
618
ERROR 23000: Duplicate entry 'a ' for key 'a'
619
insert into t1 values ('a ');
620
ERROR 23000: Duplicate entry 'a ' for key 'a'
621
insert into t1 values ('a ');
622
ERROR 23000: Duplicate entry 'a ' for key 'a'
623
insert into t1 values ('a ');
624
ERROR 23000: Duplicate entry 'a ' for key 'a'
625
update t1 set a='a ' where a like 'a ';
626
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)));
629
show create table t1;
631
t1 CREATE TEMPORARY TABLE `t1` (
632
`v` varchar(10) DEFAULT NULL,
633
`c` varchar(10) DEFAULT NULL,
634
`t` varchar(50) DEFAULT NULL,
640
create temporary table t1 (v varchar(16383), key(v(10)));
641
show create table t1;
643
t1 CREATE TEMPORARY TABLE `t1` (
644
`v` varchar(16383) DEFAULT NULL,
647
insert into t1 values(repeat('a',16383));
648
select length(v) from t1 where v=repeat('a',16383);
652
set storage_engine=PBXT;
653
create temporary table t1 (a bigint auto_increment primary key, b int,
654
key (b, a)) engine=MEMORY;
655
insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1);
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
insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1);
681
create temporary table t1 (a int not null, b int not null auto_increment,
682
primary key(a, b)) engine=MEMORY;
683
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)));
685
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
686
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
687
ERROR 23000: Duplicate entry 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl' for key 'PRIMARY'
689
CREATE TEMPORARY TABLE t1 (a int, key(a)) engine=MEMORY;
690
insert into t1 values (0);
694
insert into t1 values (0), (1);
695
select * from t1 where a = 0;
699
create temporary table t1 (c char(10)) engine=memory;
700
create temporary table t2 (c varchar(10)) engine=memory;
701
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 # # # # #
706
CREATE TEMPORARY TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
707
KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY;
708
INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256));
709
SELECT COUNT(*) FROM t1 WHERE a='a';
712
SELECT COUNT(*) FROM t1 WHERE b='aa';
715
SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256);
719
CREATE TEMPORARY TABLE t1(c1 VARCHAR(100), c2 INT) ENGINE=MEMORY;
720
INSERT INTO t1 VALUES('', 0);
721
ALTER TABLE t1 MODIFY c1 VARCHAR(101);