2
# Test of MEMORY tables.
6
6
drop table if exists t1,t2,t3;
9
create temporary table t1 (a int not null,b int not null, primary key (a)) engine=MEMORY comment="testing heaps";
9
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;
10
10
insert into t1 values(1,1),(2,2),(3,3),(4,4);
11
11
delete from t1 where a=1 or a=0;
12
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
13
show table status like "t1";
12
#show table status like "t1";
16
15
select * from t1 where a=4;
18
17
update t1 set b=b+1 where a>=3;
19
18
replace t1 values (3,3);
21
alter table t1 add c int DEFAULT 42 not null, add key (c,a);
20
alter table t1 add c int not null, add key (c,a);
24
create temporary table t1 (a int not null,b int not null, primary key (a)) engine=memory comment="testing heaps";
23
create table t1 (a int not null,b int not null, primary key (a)) engine=memory comment="testing heaps";
25
24
insert into t1 values(1,1),(2,2),(3,3),(4,4);
26
25
delete from t1 where a > 0;
30
create temporary table t1 (a int not null,b int not null, primary key (a)) engine=MEMORY comment="testing heaps";
29
create table t1 (a int not null,b int not null, primary key (a)) engine=heap comment="testing heaps";
31
30
insert into t1 values(1,1),(2,2),(3,3),(4,4);
32
alter table t1 modify a int not null auto_increment, engine=innodb, comment="new innodb table";
33
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
34
show table status like "t1";
31
alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table";
32
#show table status like "t1";
38
create temporary table t1 (a int not null) engine=MEMORY;
36
create table t1 (a int not null) engine=heap;
39
37
insert into t1 values (869751),(736494),(226312),(802616),(728912);
40
38
select * from t1 where a > 736494;
41
39
alter table t1 add unique uniq_id(a);
43
41
select * from t1 where a = 736494;
44
42
select * from t1 where a=869751 or a=736494;
45
43
select * from t1 where a in (869751,736494,226312,802616);
46
create temporary table t2 SELECT * FROM t1;
47
explain select * from t2 where a in (869751,736494,226312,802616);
44
alter table t1 engine=myisam;
45
explain select * from t1 where a in (869751,736494,226312,802616);
50
create temporary table t1 (x int not null, y int not null, key x (x), unique y (y))
48
create table t1 (x int not null, y int not null, key x (x), unique y (y))
52
50
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
53
51
select * from t1 where x=1;
54
--error ER_CANT_REOPEN_TABLE
55
52
select * from t1,t1 as t2 where t1.x=t2.y;
56
--error ER_CANT_REOPEN_TABLE
57
53
explain select * from t1,t1 as t2 where t1.x=t2.y;
60
create temporary table t1 (a int) engine=MEMORY;
56
create table t1 (a int) engine=heap;
61
57
insert into t1 values(1);
62
58
select max(a) from t1;
65
CREATE TEMPORARY TABLE t1 ( a int not null default 0, b int not null default 0, key(a), key(b) ) ENGINE=MEMORY;
61
CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key(a), key(b) ) ENGINE=HEAP;
66
62
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
67
63
select * from t1 where a=1;
68
64
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
69
65
select * from t1 where a=1;
72
create temporary table t1 (id int not null, primary key (id)) engine=MEMORY;
68
create table t1 (id int not null, primary key (id)) engine=HEAP;
73
69
insert into t1 values(1);
74
70
select max(id) from t1;
75
71
insert into t1 values(2);
77
73
replace into t1 values(1);
80
create temporary table t1 (n int) engine=MEMORY;
76
create table t1 (n int) engine=heap;
83
create temporary table t1 (n int) engine=MEMORY;
79
create table t1 (n int) engine=heap;
84
80
drop table if exists t1;
86
82
# Test of non unique index
88
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not
89
null,index(f2)) engine=MEMORY;
84
CREATE table t1(f1 int not null,f2 char(20) not
85
null,index(f2)) engine=heap;
90
86
INSERT into t1 set f1=12,f2="bill";
91
87
INSERT into t1 set f1=13,f2="bill";
92
88
INSERT into t1 set f1=14,f2="bill";
104
100
# Test when using part key searches
107
create temporary table t1 (btn char(10) not null, key(btn)) engine=MEMORY;
103
create table t1 (btn char(10) not null, key(btn)) engine=heap;
108
104
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
109
105
explain select * from t1 where btn like "q%";
110
106
select * from t1 where btn like "q%";
111
alter table t1 add column new_col char(1) DEFAULT "Y" not null, add key (btn,new_col), drop key btn;
107
alter table t1 add column new_col char(1) not null, add key (btn,new_col), drop key btn;
112
108
update t1 set new_col=left(btn,1);
113
109
explain select * from t1 where btn="a";
114
110
explain select * from t1 where btn="a" and new_col="a";
118
114
# Test of NULL keys
121
CREATE TEMPORARY TABLE t1 (
122
118
a int default NULL,
123
119
b int default NULL,
127
123
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
128
124
SELECT * FROM t1 WHERE a=NULL;
129
125
explain SELECT * FROM t1 WHERE a IS NULL;
149
145
# Test when deleting all rows
152
CREATE TEMPORARY TABLE t1 (a int not null, primary key(a)) engine=MEMORY;
148
CREATE TABLE t1 (a int not null, primary key(a)) engine=heap;
153
149
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
154
150
DELETE from t1 where a < 100;
155
151
SELECT * from t1;
159
# Bug#4411 Server hangs when trying to SELECT MAX(id) from an empty MEMORY table
155
# Bug#4411 Server hangs when trying to SELECT MAX(id) from an empty HEAP table
161
CREATE TEMPORARY TABLE `job_titles` (
157
CREATE TABLE `job_titles` (
162
158
`job_title_id` int NOT NULL default '0',
163
159
`job_title` char(18) NOT NULL default '',
164
160
PRIMARY KEY (`job_title_id`),
165
161
UNIQUE KEY `job_title_id` (`job_title_id`,`job_title`)
168
164
SELECT MAX(job_title_id) FROM job_titles;
184
180
# heap_rfirst() doesn't work (and never did!)
186
CREATE TEMPORARY TABLE t1 (pseudo char(35) PRIMARY KEY, date int NOT NULL) ENGINE=MEMORY;
182
CREATE TABLE t1 (pseudo char(35) PRIMARY KEY, date int NOT NULL) ENGINE=HEAP;
187
183
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);
188
184
DELETE FROM t1 WHERE date<1101106546;
189
185
SELECT * FROM t1;
205
# We can't use varchar.inc becasue MEMORY doesn't support blob's
201
# We can't use varchar.inc becasue heap doesn't support blob's
208
204
let $default=`select @@storage_engine`;
209
set storage_engine=MEMORY;
205
set storage_engine=HEAP;
212
208
# Simple basic test that endspace is saved
215
create temporary table t1 (v varchar(10), c char(10), t varchar(50));
211
create table t1 (v varchar(10), c char(10), t varchar(50));
216
212
insert into t1 values('+ ', '+ ', '+ ');
217
213
set @a=repeat(' ',20);
218
--error ER_DATA_TOO_LONG
219
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
220
set @a=repeat(' ',10);
221
--error ER_DATA_TOO_LONG
222
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
223
set @a=repeat(' ',9);
224
214
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
225
215
select concat('*',v,'*',c,'*',t,'*') from t1;
227
217
# Check how columns are copied
228
218
show create table t1;
229
create temporary table t2 like t1;
219
create table t2 like t1;
230
220
show create table t2;
231
create temporary table t3 select * from t1;
221
create table t3 select * from t1;
232
222
show create table t3;
233
223
alter table t1 modify c varchar(10);
234
224
show create table t1;
405
391
# test show create table
408
create temporary table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5)));
394
create table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5)));
409
395
show create table t1;
412
create temporary table t1 (v varchar(16383), key(v(10)));
398
create table t1 (v varchar(16383), key(v(10)));
413
399
show create table t1;
414
400
insert into t1 values(repeat('a',16383));
415
401
select length(v) from t1 where v=repeat('a',16383);
424
410
# Bug #8489: Strange auto_increment behaviour
427
create temporary table t1 (a bigint auto_increment primary key, b int,
428
key (b, a)) engine=MEMORY;
413
create table t1 (a bigint auto_increment primary key, b int,
414
key (b, a)) engine=heap;
429
415
insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1);
430
416
select * from t1;
433
create temporary table t1 (a int not null, b int not null auto_increment,
434
primary key(a, b), key(b)) engine=MEMORY;
419
create table t1 (a int not null, b int not null auto_increment,
420
primary key(a, b), key(b)) engine=heap;
435
421
insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1);
436
422
select * from t1;
439
--error ER_WRONG_AUTO_KEY
440
create temporary table t1 (a int not null, b int not null auto_increment,
441
primary key(a, b)) engine=MEMORY;
426
create table t1 (a int not null, b int not null auto_increment,
427
primary key(a, b)) engine=heap;
444
# Bug #10566: Verify that we can create temporary a prefixed key with length > 255
430
# Bug #10566: Verify that we can create a prefixed key with length > 255
446
create temporary table t1 (c char(255), primary key(c(90)));
432
create table t1 (c char(255), primary key(c(90)));
447
433
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
448
434
--error ER_DUP_ENTRY
449
435
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
475
461
# BUG#18233 - Memory tables INDEX USING HASH (a,b) returns 1 row on
476
462
# SELECT WHERE a= AND b=
478
CREATE TEMPORARY TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
464
CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
479
465
KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY;
480
466
INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256));
481
467
SELECT COUNT(*) FROM t1 WHERE a='a';