2
# Test of MEMORY tables.
6
6
drop table if exists t1;
9
create temporary table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=MEMORY comment="testing heaps";
9
create table t1 (a int not null,b int not null, primary key using BTREE (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
12
#show table status like "t1";
20
20
alter table t1 add c int not null, add key using BTREE (c,a);
23
create temporary table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=MEMORY comment="testing heaps";
23
create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps";
24
24
insert into t1 values(-2,-2),(-1,-1),(0,0),(1,1),(2,2),(3,3),(4,4);
25
25
delete from t1 where a > -3;
29
create temporary table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=MEMORY comment="testing heaps";
29
create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps";
30
30
insert into t1 values(1,1),(2,2),(3,3),(4,4);
31
alter table t1 modify a int not null auto_increment, engine=innodb, comment="new innodb table";
31
alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table";
32
32
#show table status like "t1";
36
create temporary table t1 (a int not null) engine=MEMORY;
36
create table t1 (a int not null) engine=heap;
37
37
insert into t1 values (869751),(736494),(226312),(802616),(728912);
38
38
select * from t1 where a > 736494;
39
39
alter table t1 add unique uniq_id using BTREE (a);
41
41
select * from t1 where a = 736494;
42
42
select * from t1 where a=869751 or a=736494;
43
43
select * from t1 where a in (869751,736494,226312,802616);
44
alter table t1 engine=innodb;
44
alter table t1 engine=myisam;
45
45
explain select * from t1 where a in (869751,736494,226312,802616);
48
create temporary table t1 (x int not null, y int not null, key x using BTREE (x,y), unique y using BTREE (y))
48
create table t1 (x int not null, y int not null, key x using BTREE (x,y), unique y using BTREE (y))
50
50
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
51
51
explain select * from t1 where x=1;
52
52
select * from t1 where x=1;
53
53
select * from t1,t1 as t2 where t1.x=t2.y;
54
54
explain select * from t1,t1 as t2 where t1.x=t2.y;
57
create temporary table t1 (a int) engine=MEMORY;
57
create table t1 (a int) engine=heap;
58
58
insert into t1 values(1);
59
59
select max(a) from t1;
62
CREATE TEMPORARY TABLE t1 ( a int not null default 0, b int not null default 0, key using BTREE (a,b), key using BTREE (b) ) ENGINE=MEMORY;
62
CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key using BTREE (a,b), key using BTREE (b) ) ENGINE=HEAP;
63
63
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
64
64
select * from t1 where a=1;
65
65
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
83
81
replace into t1 values(1);
86
create temporary table t1 (n int) engine=MEMORY;
84
create table t1 (n int) engine=heap;
89
create temporary table t1 (n int) engine=MEMORY;
87
create table t1 (n int) engine=heap;
90
88
drop table if exists t1;
92
90
# Test of non unique index
94
CREATE TEMPORARY table t1(f1 int not null,f2 char(20) not
95
null,index(f2)) engine=MEMORY;
92
CREATE table t1(f1 int not null,f2 char(20) not
93
null,index(f2)) engine=heap;
96
94
INSERT into t1 set f1=12,f2="bill";
97
95
INSERT into t1 set f1=13,f2="bill";
98
96
INSERT into t1 set f1=14,f2="bill";
110
108
# Test when using part key searches
113
create temporary table t1 (btn char(10) not null, key using BTREE (btn)) engine=MEMORY;
111
create table t1 (btn char(10) not null, key using BTREE (btn)) engine=heap;
114
112
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
115
113
explain select * from t1 where btn like "i%";
116
114
--replace_column 9 #
131
129
# Test of NULL keys
134
CREATE TEMPORARY TABLE t1 (
135
133
a int default NULL,
136
134
b int default NULL,
137
135
KEY a using BTREE (a),
138
136
UNIQUE b using BTREE (b)
140
138
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
141
139
SELECT * FROM t1 WHERE a=NULL;
142
140
explain SELECT * FROM t1 WHERE a IS NULL;
149
147
INSERT INTO t1 VALUES (1,3);
152
CREATE TEMPORARY TABLE t1 (a int, b int, c int, key using BTREE (a, b, c)) engine=MEMORY;
150
CREATE TABLE t1 (a int, b int, c int, key using BTREE (a, b, c)) engine=heap;
153
151
INSERT INTO t1 VALUES (1, NULL, NULL), (1, 1, NULL), (1, NULL, 1);
154
152
SELECT * FROM t1 WHERE a=1 and b IS NULL;
155
153
SELECT * FROM t1 WHERE a=1 and c IS NULL;
160
158
# Test when deleting all rows
163
CREATE TEMPORARY TABLE t1 (a int not null, primary key using BTREE (a)) engine=MEMORY;
161
CREATE TABLE t1 (a int not null, primary key using BTREE (a)) engine=heap;
164
162
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
165
163
DELETE from t1 where a < 100;
166
164
SELECT * from t1;
170
168
# Bug #9719: problem with delete
173
create temporary table t1(a int not null, key using btree(a)) engine=MEMORY;
171
create table t1(a int not null, key using btree(a)) engine=heap;
174
172
insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3);
175
173
select a from t1 where a > 2 order by a;
176
174
delete from t1 where a < 4;
202
200
# Bug#24985 - UTF8 ENUM primary key on MEMORY using BTREE
203
201
# causes incorrect duplicate entries
205
CREATE TEMPORARY TABLE t1 (
206
204
c1 ENUM('1', '2'),
207
205
UNIQUE USING BTREE(c1)
206
) ENGINE= MEMORY DEFAULT CHARSET= utf8;
209
207
INSERT INTO t1 VALUES('1'), ('2');
213
211
# BUG#30590 - delete from memory table with composite btree primary key
215
CREATE TEMPORARY TABLE t1 (a INT, KEY USING BTREE(a)) ENGINE=MEMORY;
213
CREATE TABLE t1 (a INT, KEY USING BTREE(a)) ENGINE=MEMORY;
216
214
INSERT INTO t1 VALUES(1),(2),(2);
217
215
DELETE FROM t1 WHERE a=2;
218
216
SELECT * FROM t1;
221
219
--echo End of 4.1 tests
224
# BUG#18160 - Memory-/MEMORY Table endless growing indexes
222
# BUG#18160 - Memory-/HEAP Table endless growing indexes
226
CREATE TEMPORARY TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
224
CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
227
225
INSERT INTO t1 VALUES(0);
228
226
--replace_result 37 21
229
227
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
236
234
# BUG#12873 - BTREE index on MEMORY table with multiple NULL values doesn't
239
CREATE TEMPORARY TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY;
237
CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY;
240
238
INSERT INTO t1 VALUES(NULL),(NULL);
244
242
# Bug #30885: MEMORY returns incorrect data if BTREE index is used for NULL lookup
246
create temporary table t1(a varchar(255), b varchar(255),
244
create table t1(a varchar(255), b varchar(255),
247
245
key using btree (a,b)) engine=memory;
248
246
insert into t1 values (1, 1), (3, 3), (2, 2), (NULL, 1), (NULL, NULL), (0, 0);
249
247
select * from t1 where a is null;