2
# Test of MEMORY tables.
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";
10
insert into t1 values(1,1),(2,2),(3,3),(4,4);
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";
16
select * from t1 where a=4;
17
update t1 set b=5 where a=4;
18
update t1 set b=b+1 where a>=3;
19
replace t1 values (3,3);
21
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";
25
insert into t1 values(1,1),(2,2),(3,3),(4,4);
26
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";
31
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";
38
create temporary table t1 (a int not null) engine=MEMORY;
39
insert into t1 values (869751),(736494),(226312),(802616),(728912);
40
select * from t1 where a > 736494;
41
alter table t1 add unique uniq_id(a);
42
select * from t1 where a > 736494;
43
select * from t1 where a = 736494;
44
select * from t1 where a=869751 or a=736494;
45
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);
50
create temporary table t1 (x int not null, y int not null, key x (x), unique y (y))
52
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
53
select * from t1 where x=1;
54
select * from t1,t1 as t2 where t1.x=t2.y;
55
explain select * from t1,t1 as t2 where t1.x=t2.y;
58
create temporary table t1 (a int) engine=MEMORY;
59
insert into t1 values(1);
60
select max(a) from t1;
63
CREATE TEMPORARY TABLE t1 ( a int not null default 0, b int not null default 0, key(a), key(b) ) ENGINE=MEMORY;
64
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
65
select * from t1 where a=1;
66
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
67
select * from t1 where a=1;
70
create temporary table t1 (id int not null, primary key (id)) engine=MEMORY;
71
insert into t1 values(1);
72
select max(id) from t1;
73
insert into t1 values(2);
74
select max(id) from t1;
75
replace into t1 values(1);
78
create temporary table t1 (n int) engine=MEMORY;
81
create temporary table t1 (n int) engine=MEMORY;
82
drop table if exists t1;
84
# Test of non unique index
86
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not
87
null,index(f2)) engine=MEMORY;
88
INSERT into t1 set f1=12,f2="bill";
89
INSERT into t1 set f1=13,f2="bill";
90
INSERT into t1 set f1=14,f2="bill";
91
INSERT into t1 set f1=15,f2="bill";
92
INSERT into t1 set f1=16,f2="ted";
93
INSERT into t1 set f1=12,f2="ted";
94
INSERT into t1 set f1=12,f2="ted";
95
INSERT into t1 set f1=12,f2="ted";
96
INSERT into t1 set f1=12,f2="ted";
97
delete from t1 where f2="bill";
102
# Test when using part key searches
105
create temporary table t1 (btn char(10) not null, key(btn)) engine=MEMORY;
106
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
107
explain select * from t1 where btn like "q%";
108
select * from t1 where btn like "q%";
109
alter table t1 add column new_col char(1) not null, add key (btn,new_col), drop key btn;
110
update t1 set new_col=left(btn,1);
111
explain select * from t1 where btn="a";
112
explain select * from t1 where btn="a" and new_col="a";
119
CREATE TEMPORARY TABLE t1 (
125
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
126
SELECT * FROM t1 WHERE a=NULL;
127
explain SELECT * FROM t1 WHERE a IS NULL;
128
SELECT * FROM t1 WHERE a<=>NULL;
129
SELECT * FROM t1 WHERE b=NULL;
130
explain SELECT * FROM t1 WHERE b IS NULL;
131
SELECT * FROM t1 WHERE b<=>NULL;
134
INSERT INTO t1 VALUES (1,3);
137
CREATE TEMPORARY TABLE t1 (
141
INSERT INTO t1 VALUES (10), (10), (10);
142
EXPLAIN SELECT * FROM t1 WHERE a=10;
143
SELECT * FROM t1 WHERE a=10;
147
# Test when deleting all rows
150
CREATE TEMPORARY TABLE t1 (a int not null, primary key(a)) engine=MEMORY;
151
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
152
DELETE from t1 where a < 100;
157
# Bug#4411 Server hangs when trying to SELECT MAX(id) from an empty MEMORY table
159
CREATE TEMPORARY TABLE `job_titles` (
160
`job_title_id` int NOT NULL default '0',
161
`job_title` char(18) NOT NULL default '',
162
PRIMARY KEY (`job_title_id`),
163
UNIQUE KEY `job_title_id` (`job_title_id`,`job_title`)
166
SELECT MAX(job_title_id) FROM job_titles;
168
DROP TABLE job_titles;
171
# Test of delete with NOT NULL
175
CREATE TEMPORARY TABLE t1 (a INT NOT NULL, B INT, KEY(B)) ENGINE=MEMORY;
176
INSERT INTO t1 VALUES(1,1), (1,NULL);
177
SELECT * FROM t1 WHERE B is not null;
182
# heap_rfirst() doesn't work (and never did!)
184
CREATE TEMPORARY TABLE t1 (pseudo char(35) PRIMARY KEY, date int NOT NULL) ENGINE=MEMORY;
185
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);
186
DELETE FROM t1 WHERE date<1101106546;
191
# Bug #6878: a problem with small length records
194
create temporary table t1(a char(2)) engine=memory;
195
insert into t1 values (NULL), (NULL);
196
delete from t1 where a is null;
197
insert into t1 values ('2'), ('3');
203
# We can't use varchar.inc becasue MEMORY doesn't support blob's
206
let $default=`select @@storage_engine`;
207
set storage_engine=MEMORY;
210
# Simple basic test that endspace is saved
213
create temporary table t1 (v varchar(10), c char(10), t varchar(50));
214
insert into t1 values('+ ', '+ ', '+ ');
215
set @a=repeat(' ',20);
216
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
217
select concat('*',v,'*',c,'*',t,'*') from t1;
219
# Check how columns are copied
220
show create table t1;
221
create temporary table t2 like t1;
222
show create table t2;
223
create temporary table t3 select * from t1;
224
show create table t3;
225
alter table t1 modify c varchar(10);
226
show create table t1;
227
alter table t1 modify v char(10);
228
show create table t1;
229
alter table t1 modify t varchar(50);
230
show create table t1;
231
select concat('*',v,'*',c,'*',t,'*') from t1;
237
create temporary table t1 (v varchar(10), c char(10), t varchar(50), key(v), key(c), key(t(10)));
238
show create table t1;
245
eval set @space=repeat(' ',10-$1);
248
eval set @char=char(ascii('a')+$2-1);
249
insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space));
256
select count(*) from t1;
257
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
258
select count(*) from t1 where v='a';
259
select count(*) from t1 where c='a';
260
select count(*) from t1 where t='a';
261
select count(*) from t1 where v='a ';
262
select count(*) from t1 where c='a ';
263
select count(*) from t1 where t='a ';
264
select count(*) from t1 where v between 'a' and 'a ';
265
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
266
select count(*) from t1 where v like 'a%';
267
select count(*) from t1 where c like 'a%';
268
select count(*) from t1 where t like 'a%';
269
select count(*) from t1 where v like 'a %';
270
explain select count(*) from t1 where v='a ';
271
explain select count(*) from t1 where c='a ';
272
explain select count(*) from t1 where t='a ';
273
explain select count(*) from t1 where v like 'a%';
274
explain select count(*) from t1 where v between 'a' and 'a ';
275
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
278
alter table t1 add unique(v);
279
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*'));
280
explain select * from t1 where v='a';
284
select v,count(*) from t1 group by v limit 10;
285
select v,count(t) from t1 group by v limit 10;
286
select v,count(c) from t1 group by v limit 10;
287
select sql_big_result trim(v),count(t) from t1 group by v limit 10;
288
select sql_big_result trim(v),count(c) from t1 group by v limit 10;
289
select c,count(*) from t1 group by c limit 10;
290
select c,count(t) from t1 group by c limit 10;
291
select t,count(*) from t1 group by t limit 10;
292
select t,count(t) from t1 group by t limit 10;
293
select sql_big_result trim(t),count(t) from t1 group by t limit 10;
300
create temporary table t1 (a char(10), unique (a));
301
insert into t1 values ('a');
303
insert into t1 values ('a ');
305
alter table t1 modify a varchar(10);
307
insert into t1 values ('a '),('a '),('a '),('a ');
309
insert into t1 values ('a ');
311
insert into t1 values ('a ');
313
insert into t1 values ('a ');
314
update t1 set a='a ' where a like 'a ';
315
update t1 set a='a ' where a like 'a ';
319
# Testing of btree keys
322
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)));
323
show create table t1;
330
eval set @space=repeat(' ',10-$1);
333
eval set @char=char(ascii('a')+$2-1);
334
insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space));
341
select count(*) from t1;
342
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
343
select count(*) from t1 where v='a';
344
select count(*) from t1 where c='a';
345
select count(*) from t1 where t='a';
346
select count(*) from t1 where v='a ';
347
select count(*) from t1 where c='a ';
348
select count(*) from t1 where t='a ';
349
select count(*) from t1 where v between 'a' and 'a ';
351
select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
353
explain select count(*) from t1 where v='a ';
355
explain select count(*) from t1 where c='a ';
357
explain select count(*) from t1 where t='a ';
359
explain select count(*) from t1 where v like 'a%';
361
explain select count(*) from t1 where v between 'a' and 'a ';
363
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
366
alter table t1 add unique(v);
367
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*'));
368
# Number of rows is not constant for b-trees keys
370
explain select * from t1 where v='a';
375
# Test unique btree keys
378
create temporary table t1 (a char(10), unique using btree (a)) engine=MEMORY;
379
insert into t1 values ('a');
381
insert into t1 values ('a ');
383
alter table t1 modify a varchar(10);
385
insert into t1 values ('a '),('a '),('a '),('a ');
387
insert into t1 values ('a ');
389
insert into t1 values ('a ');
391
insert into t1 values ('a ');
392
update t1 set a='a ' where a like 'a ';
393
update t1 set a='a ' where a like 'a ';
397
# test show create table
400
create temporary table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5)));
401
show create table t1;
404
create temporary table t1 (v varchar(16383), key(v(10)));
405
show create table t1;
406
insert into t1 values(repeat('a',16383));
407
select length(v) from t1 where v=repeat('a',16383);
413
eval set storage_engine=$default;
416
# Bug #8489: Strange auto_increment behaviour
419
create temporary table t1 (a bigint auto_increment primary key, b int,
420
key (b, a)) engine=MEMORY;
421
insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1);
425
create temporary table t1 (a int not null, b int not null auto_increment,
426
primary key(a, b), key(b)) engine=MEMORY;
427
insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1);
432
create temporary table t1 (a int not null, b int not null auto_increment,
433
primary key(a, b)) engine=MEMORY;
436
# Bug #10566: Verify that we can create temporary a prefixed key with length > 255
438
create temporary table t1 (c char(255), primary key(c(90)));
439
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
441
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
445
# Bug 12796: Record doesn't show when selecting through index
447
CREATE TEMPORARY TABLE t1 (a int, key(a)) engine=MEMORY;
448
insert into t1 values (0);
451
insert into t1 values (0), (1);
452
select * from t1 where a = 0;
458
# Bug #3094: Row format of memory tables should always be reported as Fixed
460
create temporary table t1 (c char(10)) engine=memory;
461
create temporary table t2 (c varchar(10)) engine=memory;
462
--replace_column 1 # 6 # 7 # 8 # 9 # 10 #
463
show table status like 't_';
467
# BUG#18233 - Memory tables INDEX USING HASH (a,b) returns 1 row on
468
# SELECT WHERE a= AND b=
470
CREATE TEMPORARY TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
471
KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY;
472
INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256));
473
SELECT COUNT(*) FROM t1 WHERE a='a';
474
SELECT COUNT(*) FROM t1 WHERE b='aa';
475
SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256);
481
# BUG#26080 - Memory Storage engine not working properly
483
CREATE TEMPORARY TABLE t1(c1 VARCHAR(100), c2 INT) ENGINE=MEMORY;
484
INSERT INTO t1 VALUES('', 0);
485
ALTER TABLE t1 MODIFY c1 VARCHAR(101);