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 Using where
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));
255
ERROR 22001: Data too long for column 'v' at row 1
256
set @a=repeat(' ',10);
257
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
258
ERROR 22001: Data too long for column 'v' at row 1
259
set @a=repeat(' ',9);
260
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
261
select concat('*',v,'*',c,'*',t,'*') from t1;
262
concat('*',v,'*',c,'*',t,'*')
265
show create table t1;
267
t1 CREATE TEMPORARY TABLE `t1` (
268
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
269
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
270
`t` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL
271
) ENGINE=MEMORY COLLATE = utf8_general_ci
272
create temporary table t2 like t1;
273
show create table t2;
275
t2 CREATE TEMPORARY TABLE `t2` (
276
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
277
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
278
`t` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL
279
) ENGINE=MEMORY COLLATE = utf8_general_ci
280
create temporary table t3 select * from t1;
281
show create table t3;
283
t3 CREATE TEMPORARY TABLE `t3` (
284
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
285
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
286
`t` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL
287
) ENGINE=MEMORY COLLATE = utf8_general_ci
288
alter table t1 modify c varchar(10);
289
show create table t1;
291
t1 CREATE TEMPORARY TABLE `t1` (
292
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
293
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
294
`t` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL
295
) ENGINE=MEMORY COLLATE = utf8_general_ci
296
alter table t1 modify v char(10);
297
show create table t1;
299
t1 CREATE TEMPORARY TABLE `t1` (
300
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
301
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
302
`t` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL
303
) ENGINE=MEMORY COLLATE = utf8_general_ci
304
alter table t1 modify t varchar(50);
305
show create table t1;
307
t1 CREATE TEMPORARY TABLE `t1` (
308
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
309
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
310
`t` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL
311
) ENGINE=MEMORY COLLATE = utf8_general_ci
312
select concat('*',v,'*',c,'*',t,'*') from t1;
313
concat('*',v,'*',c,'*',t,'*')
317
create temporary table t1 (v varchar(10), c char(10), t varchar(50), key(v), key(c), key(t(10)));
318
show create table t1;
320
t1 CREATE TEMPORARY TABLE `t1` (
321
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
322
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
323
`t` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL,
327
) ENGINE=MEMORY COLLATE = utf8_general_ci
328
select count(*) from t1;
331
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
332
select count(*) from t1 where v='a';
335
select count(*) from t1 where c='a';
338
select count(*) from t1 where t='a';
341
select count(*) from t1 where v='a ';
344
select count(*) from t1 where c='a ';
347
select count(*) from t1 where t='a ';
350
select count(*) from t1 where v between 'a' and 'a ';
353
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
356
select count(*) from t1 where v like 'a%';
359
select count(*) from t1 where c like 'a%';
362
select count(*) from t1 where t like 'a%';
365
select count(*) from t1 where v like 'a %';
368
explain select count(*) from t1 where v='a ';
369
id select_type table type possible_keys key key_len ref rows Extra
370
1 SIMPLE t1 ref v v 43 const 10 Using where
371
explain select count(*) from t1 where c='a ';
372
id select_type table type possible_keys key key_len ref rows Extra
373
1 SIMPLE t1 ref c c 43 const 10 Using where
374
explain select count(*) from t1 where t='a ';
375
id select_type table type possible_keys key key_len ref rows Extra
376
1 SIMPLE t1 ref t t 43 const 10 Using where
377
explain select count(*) from t1 where v like 'a%';
378
id select_type table type possible_keys key key_len ref rows Extra
379
1 SIMPLE t1 ALL v NULL NULL NULL 271 Using where
380
explain select count(*) from t1 where v between 'a' and 'a ';
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
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
384
id select_type table type possible_keys key key_len ref rows Extra
385
1 SIMPLE t1 ref v v 43 const 10 Using where
386
alter table t1 add unique(v);
387
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
388
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*'));
400
explain select * from t1 where v='a';
401
id select_type table type possible_keys key key_len ref rows Extra
402
1 SIMPLE t1 ref v v 43 const 10 Using where
403
select v,count(*) from t1 group by v limit 10;
415
select v,count(t) from t1 group by v limit 10;
427
select v,count(c) from t1 group by v limit 10;
439
select sql_big_result trim(v),count(t) from t1 group by v limit 10;
451
select sql_big_result trim(v),count(c) from t1 group by v limit 10;
463
select c,count(*) from t1 group by c limit 10;
475
select c,count(t) from t1 group by c limit 10;
487
select t,count(*) from t1 group by t limit 10;
499
select t,count(t) from t1 group by t limit 10;
511
select sql_big_result trim(t),count(t) from t1 group by t limit 10;
524
create temporary table t1 (a char(10), unique (a));
525
insert into t1 values ('a');
526
insert into t1 values ('a ');
527
ERROR 23000: Duplicate entry 'a ' for key 'a'
528
alter table t1 modify a varchar(10);
529
insert into t1 values ('a '),('a '),('a '),('a ');
530
ERROR 23000: Duplicate entry 'a ' for key 'a'
531
insert into t1 values ('a ');
532
ERROR 23000: Duplicate entry 'a ' for key 'a'
533
insert into t1 values ('a ');
534
ERROR 22001: Data too long for column 'a' at row 1
535
insert into t1 values ('a ');
536
ERROR 23000: Duplicate entry 'a ' for key 'a'
537
update t1 set a='a ' where a like 'a ';
538
update t1 set a='a ' where a like 'a ';
540
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)));
541
show create table t1;
543
t1 CREATE TEMPORARY TABLE `t1` (
544
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
545
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
546
`t` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL,
547
KEY `v` (`v`) USING BTREE,
548
KEY `c` (`c`) USING BTREE,
549
KEY `t` (`t`(10)) USING BTREE
550
) ENGINE=MEMORY COLLATE = utf8_general_ci
551
select count(*) from t1;
554
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
555
select count(*) from t1 where v='a';
558
select count(*) from t1 where c='a';
561
select count(*) from t1 where t='a';
564
select count(*) from t1 where v='a ';
567
select count(*) from t1 where c='a ';
570
select count(*) from t1 where t='a ';
573
select count(*) from t1 where v between 'a' and 'a ';
576
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
579
explain select count(*) from t1 where v='a ';
580
id select_type table type possible_keys key key_len ref rows Extra
581
1 SIMPLE t1 ref v v 43 const # Using where
582
explain select count(*) from t1 where c='a ';
583
id select_type table type possible_keys key key_len ref rows Extra
584
1 SIMPLE t1 ref c c 43 const # Using where
585
explain select count(*) from t1 where t='a ';
586
id select_type table type possible_keys key key_len ref rows Extra
587
1 SIMPLE t1 ref t t 43 const # Using where
588
explain select count(*) from t1 where v like 'a%';
589
id select_type table type possible_keys key key_len ref rows Extra
590
1 SIMPLE t1 ALL v NULL NULL NULL # Using where
591
explain select count(*) from t1 where v between 'a' and 'a ';
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
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
595
id select_type table type possible_keys key key_len ref rows Extra
596
1 SIMPLE t1 ref v v 43 const # Using where
597
alter table t1 add unique(v);
598
ERROR 23000: Duplicate entry '{ ' for key 'v_2'
599
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*'));
611
explain select * from t1 where v='a';
612
id select_type table type possible_keys key key_len ref rows Extra
613
1 SIMPLE t1 ref v v 43 const # Using where
615
create temporary table t1 (a char(10), unique using btree (a)) engine=MEMORY;
616
insert into t1 values ('a');
617
insert into t1 values ('a ');
618
ERROR 23000: Duplicate entry 'a ' for key 'a'
619
alter table t1 modify a varchar(10);
620
insert into t1 values ('a '),('a '),('a '),('a ');
621
ERROR 23000: Duplicate entry 'a ' for key 'a'
622
insert into t1 values ('a ');
623
ERROR 23000: Duplicate entry 'a ' for key 'a'
624
insert into t1 values ('a ');
625
ERROR 22001: Data too long for column 'a' at row 1
626
insert into t1 values ('a ');
627
ERROR 23000: Duplicate entry 'a ' for key 'a'
628
update t1 set a='a ' where a like 'a ';
629
update t1 set a='a ' where a like 'a ';
631
create temporary table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5)));
632
show create table t1;
634
t1 CREATE TEMPORARY TABLE `t1` (
635
`v` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
636
`c` VARCHAR(10) COLLATE utf8_general_ci DEFAULT NULL,
637
`t` VARCHAR(50) COLLATE utf8_general_ci DEFAULT NULL,
641
) ENGINE=MEMORY COLLATE = utf8_general_ci
643
create temporary table t1 (v varchar(16383), key(v(10)));
644
show create table t1;
646
t1 CREATE TEMPORARY TABLE `t1` (
647
`v` VARCHAR(16383) COLLATE utf8_general_ci DEFAULT NULL,
649
) ENGINE=MEMORY COLLATE = utf8_general_ci
650
insert into t1 values(repeat('a',16383));
651
select length(v) from t1 where v=repeat('a',16383);
655
set storage_engine=PBXT;
656
create temporary table t1 (a bigint auto_increment primary key, b int,
657
key (b, a)) engine=MEMORY;
658
insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1);
670
create temporary table t1 (a int not null, b int not null auto_increment,
671
primary key(a, b), key(b)) engine=MEMORY;
672
insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1);
684
create temporary table t1 (a int not null, b int not null auto_increment,
685
primary key(a, b)) engine=MEMORY;
686
ERROR 42000: Incorrect table definition; there can be only one auto column and it must be defined as a key
687
create temporary table t1 (c char(255), primary key(c(90)));
688
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
689
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
690
ERROR 23000: Duplicate entry 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl' for key 'PRIMARY'
692
CREATE TEMPORARY TABLE t1 (a int, key(a)) engine=MEMORY;
693
insert into t1 values (0);
697
insert into t1 values (0), (1);
698
select * from t1 where a = 0;
702
create temporary table t1 (c char(10)) engine=memory;
703
create temporary table t2 (c varchar(10)) engine=memory;
704
show table status like 't_';
705
Session Schema Name Type Engine Version Rows Avg_row_length Table_size Auto_increment
706
# test t1 TEMPORARY MEMORY # # # # #
707
# test t2 TEMPORARY MEMORY # # # # #
709
CREATE TEMPORARY TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
710
KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY;
711
INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256));
712
SELECT COUNT(*) FROM t1 WHERE a='a';
715
SELECT COUNT(*) FROM t1 WHERE b='aa';
718
SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256);
722
CREATE TEMPORARY TABLE t1(c1 VARCHAR(100), c2 INT) ENGINE=MEMORY;
723
INSERT INTO t1 VALUES('', 0);
724
ALTER TABLE t1 MODIFY c1 VARCHAR(101);