6
drop table if exists t1;
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
insert into t1 values(1,1),(2,2),(3,3),(4,4);
11
delete from t1 where a=1 or a=0;
12
#show table status like "t1";
15
select * from t1 where a=4;
16
update t1 set b=5 where a=4;
17
update t1 set b=b+1 where a>=3;
18
replace t1 values (3,3);
20
alter table t1 add c int not null, add key using BTREE (c,a);
23
create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps";
24
insert into t1 values(-2,-2),(-1,-1),(0,0),(1,1),(2,2),(3,3),(4,4);
25
delete from t1 where a > -3;
29
create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps";
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=myisam, comment="new myisam table";
32
#show table status like "t1";
36
create table t1 (a int not null) engine=heap;
37
insert into t1 values (869751),(736494),(226312),(802616),(728912);
38
select * from t1 where a > 736494;
39
alter table t1 add unique uniq_id using BTREE (a);
40
select * from t1 where a > 736494;
41
select * from t1 where a = 736494;
42
select * from t1 where a=869751 or a=736494;
43
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);
48
create table t1 (x int not null, y int not null, key x using BTREE (x,y), unique y using BTREE (y))
50
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
51
explain select * from t1 where x=1;
52
select * from t1 where x=1;
53
select * from t1,t1 as t2 where t1.x=t2.y;
54
explain select * from t1,t1 as t2 where t1.x=t2.y;
57
create table t1 (a int) engine=heap;
58
insert into t1 values(1);
59
select max(a) from t1;
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
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
64
select * from t1 where a=1;
65
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
66
select * from t1 where a=1;
67
--replace_result 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 x 13 x 14 x
68
explain select * from t1 where a=1 order by a,b;
69
--replace_result 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 x 13 x 14 x
70
explain select * from t1 where a=1 order by b;
71
select * from t1 where b=1;
72
--replace_result 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 x 13 x 14 x
73
explain select * from t1 where b=1;
76
create table t1 (id int unsigned not null, primary key using BTREE (id)) engine=HEAP;
77
insert into t1 values(1);
78
select max(id) from t1;
79
insert into t1 values(2);
80
select max(id) from t1;
81
replace into t1 values(1);
84
create table t1 (n int) engine=heap;
87
create table t1 (n int) engine=heap;
88
drop table if exists t1;
90
# Test of non unique index
92
CREATE table t1(f1 int not null,f2 char(20) not
93
null,index(f2)) engine=heap;
94
INSERT into t1 set f1=12,f2="bill";
95
INSERT into t1 set f1=13,f2="bill";
96
INSERT into t1 set f1=14,f2="bill";
97
INSERT into t1 set f1=15,f2="bill";
98
INSERT into t1 set f1=16,f2="ted";
99
INSERT into t1 set f1=12,f2="ted";
100
INSERT into t1 set f1=12,f2="ted";
101
INSERT into t1 set f1=12,f2="ted";
102
INSERT into t1 set f1=12,f2="ted";
103
delete from t1 where f2="bill";
108
# Test when using part key searches
111
create table t1 (btn char(10) not null, key using BTREE (btn)) engine=heap;
112
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
113
explain select * from t1 where btn like "i%";
115
explain select * from t1 where btn like "h%";
116
explain select * from t1 where btn like "a%";
117
explain select * from t1 where btn like "b%";
118
# For the following the BTREE MAY notice that there is no possible matches
119
select * from t1 where btn like "ff%";
120
select * from t1 where btn like " %";
121
select * from t1 where btn like "q%";
122
alter table t1 add column new_col char(1) not null, add key using BTREE (btn,new_col), drop key btn;
123
update t1 set new_col=left(btn,1);
124
explain select * from t1 where btn="a";
125
explain select * from t1 where btn="a" and new_col="a";
135
KEY a using BTREE (a),
136
UNIQUE b using BTREE (b)
138
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
139
SELECT * FROM t1 WHERE a=NULL;
140
explain SELECT * FROM t1 WHERE a IS NULL;
141
SELECT * FROM t1 WHERE a<=>NULL;
142
SELECT * FROM t1 WHERE b=NULL;
143
explain SELECT * FROM t1 WHERE b IS NULL;
144
SELECT * FROM t1 WHERE b<=>NULL;
147
INSERT INTO t1 VALUES (1,3);
150
CREATE TABLE t1 (a int, b int, c int, key using BTREE (a, b, c)) engine=heap;
151
INSERT INTO t1 VALUES (1, NULL, NULL), (1, 1, NULL), (1, NULL, 1);
152
SELECT * FROM t1 WHERE a=1 and b IS NULL;
153
SELECT * FROM t1 WHERE a=1 and c IS NULL;
154
SELECT * FROM t1 WHERE a=1 and b IS NULL and c IS NULL;
158
# Test when deleting all rows
161
CREATE TABLE t1 (a int not null, primary key using BTREE (a)) engine=heap;
162
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
163
DELETE from t1 where a < 100;
168
# Bug #9719: problem with delete
171
create table t1(a int not null, key using btree(a)) engine=heap;
172
insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3);
173
select a from t1 where a > 2 order by a;
174
delete from t1 where a < 4;
175
select a from t1 order by a;
176
insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3);
177
select a from t1 where a > 4 order by a;
178
delete from t1 where a > 4;
179
select a from t1 order by a;
180
select a from t1 where a > 3 order by a;
181
delete from t1 where a >= 2;
182
select a from t1 order by a;
186
# Bug#26996 - Update of a Field in a Memory Table ends with wrong result
194
INSERT INTO t1 VALUES ('ABC',0), ('A',0), ('B',0), ('C',0);
195
UPDATE t1 SET c2= c2 + 1 WHERE c1 = 'A';
200
# Bug#24985 - UTF8 ENUM primary key on MEMORY using BTREE
201
# causes incorrect duplicate entries
205
UNIQUE USING BTREE(c1)
206
) ENGINE= MEMORY DEFAULT CHARSET= utf8;
207
INSERT INTO t1 VALUES('1'), ('2');
211
UNIQUE USING BTREE(c1)
212
) ENGINE= MEMORY DEFAULT CHARSET= utf8;
213
INSERT INTO t1 VALUES('1'), ('2');
217
# BUG#30590 - delete from memory table with composite btree primary key
219
CREATE TABLE t1 (a INT, KEY USING BTREE(a)) ENGINE=MEMORY;
220
INSERT INTO t1 VALUES(1),(2),(2);
221
DELETE FROM t1 WHERE a=2;
225
--echo End of 4.1 tests
228
# BUG#18160 - Memory-/HEAP Table endless growing indexes
230
CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
231
INSERT INTO t1 VALUES(0);
232
--replace_result 37 21
233
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
235
--replace_result 37 21
236
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
240
# BUG#12873 - BTREE index on MEMORY table with multiple NULL values doesn't
243
CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY;
244
INSERT INTO t1 VALUES(NULL),(NULL);
248
# Bug #30885: MEMORY returns incorrect data if BTREE index is used for NULL lookup
250
create table t1(a varchar(255), b varchar(255),
251
key using btree (a,b)) engine=memory;
252
insert into t1 values (1, 1), (3, 3), (2, 2), (NULL, 1), (NULL, NULL), (0, 0);
253
select * from t1 where a is null;
256
--echo End of 5.0 tests