~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#
2
# Test of heap tables.
3
#
4
5
--disable_warnings
6
drop table if exists t1;
7
--enable_warnings
8
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";
13
show keys from t1;
14
select * from 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);
19
select * from t1;
20
alter table t1 add c int not null, add key using BTREE (c,a);
21
drop table t1;
22
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;
26
select * from t1;
27
drop table t1;
28
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";
33
select * from t1;
34
drop table t1;
35
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);
46
drop table t1;
47
48
create table t1 (x int not null, y int not null, key x  using BTREE (x,y), unique y  using BTREE (y))
49
engine=heap;
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;
55
drop table t1;
56
57
create table t1 (a int) engine=heap;
58
insert into t1 values(1);
59
select max(a) from t1;
60
drop table t1;
61
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;
74
drop table t1;
75
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);
82
drop table t1;
83
84
create table t1 (n int) engine=heap;
85
drop table t1;
86
87
create table t1 (n int) engine=heap;
88
drop table if exists t1;
89
90
# Test of non unique index
91
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";
104
select * from t1;
105
drop table t1;
106
107
#
108
# Test when using part key searches
109
#
110
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%";
114
--replace_column 9 #
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";
126
drop table t1;
127
128
#
129
# Test of NULL keys
130
#
131
132
CREATE TABLE t1 (
133
  a int default NULL,
134
  b int default NULL,
135
  KEY a using BTREE (a),
136
  UNIQUE b using BTREE (b)
137
) engine=heap;
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;
145
146
--error ER_DUP_ENTRY
147
INSERT INTO t1 VALUES (1,3);
148
DROP TABLE t1;
149
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;
155
DROP TABLE t1;
156
157
#
158
# Test when deleting all rows
159
#
160
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;
164
SELECT * from t1;
165
DROP TABLE t1;
166
167
#
168
# Bug #9719: problem with delete
169
#
170
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;
183
drop table t1;
184
185
#
186
# Bug#26996 - Update of a Field in a Memory Table ends with wrong result
187
#
188
CREATE TABLE t1 (
189
  c1 CHAR(3),
190
  c2 INTEGER,
191
  KEY USING BTREE(c1),
192
  KEY USING BTREE(c2)
193
) ENGINE= MEMORY;
194
INSERT INTO t1 VALUES ('ABC',0), ('A',0), ('B',0), ('C',0);
195
UPDATE t1 SET c2= c2 + 1 WHERE c1 = 'A';
196
SELECT * FROM t1;
197
DROP TABLE t1;
198
199
#
200
# Bug#24985 - UTF8 ENUM primary key on MEMORY using BTREE
201
#             causes incorrect duplicate entries
202
#
203
CREATE TABLE t1 (
204
  c1 ENUM('1', '2'),
205
  UNIQUE USING BTREE(c1)
206
) ENGINE= MEMORY DEFAULT CHARSET= utf8;
207
INSERT INTO t1 VALUES('1'), ('2');
208
DROP TABLE t1;
209
CREATE TABLE t1 (
210
  c1 SET('1', '2'),
211
  UNIQUE USING BTREE(c1)
212
) ENGINE= MEMORY DEFAULT CHARSET= utf8;
213
INSERT INTO t1 VALUES('1'), ('2');
214
DROP TABLE t1;
215
216
#
217
# BUG#30590 - delete from memory table with composite btree primary key
218
#
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;
222
SELECT * FROM t1;
223
DROP TABLE t1;
224
225
--echo End of 4.1 tests
226
227
#
228
# BUG#18160 - Memory-/HEAP Table endless growing indexes
229
#
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';
234
UPDATE t1 SET val=1;
235
--replace_result 37 21
236
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
237
DROP TABLE t1;
238
239
#
240
# BUG#12873 - BTREE index on MEMORY table with multiple NULL values doesn't
241
# work properly
242
#
243
CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY;
244
INSERT INTO t1 VALUES(NULL),(NULL);
245
DROP TABLE t1;
246
247
#
248
# Bug #30885: MEMORY returns incorrect data if BTREE index is used for NULL lookup
249
#
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;
254
drop table t1;
255
256
--echo End of 5.0 tests
257