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