~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
drop table if exists t1;
2
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;
3
insert into t1 values(1,1),(2,2),(3,3),(4,4);
4
delete from t1 where a=1 or a=0;
5
show keys from t1;
6
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment	Index_Comment
7
t1	0	PRIMARY	1	a	A	NULL	NULL	NULL		BTREE		
8
select * from t1;
9
a	b
10
2	2
11
3	3
12
4	4
13
select * from t1 where a=4;
14
a	b
15
4	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
a	b
21
2	2
22
3	3
23
4	6
24
alter table t1 add c int not null, add key using BTREE (c,a);
25
drop table t1;
26
create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps";
27
insert into t1 values(-2,-2),(-1,-1),(0,0),(1,1),(2,2),(3,3),(4,4);
28
delete from t1 where a > -3;
29
select * from t1;
30
a	b
31
drop table t1;
32
create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps";
33
insert into t1 values(1,1),(2,2),(3,3),(4,4);
34
alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table";
35
select * from t1;
36
a	b
37
1	1
38
2	2
39
3	3
40
4	4
41
drop table t1;
42
create table t1 (a int not null) engine=heap;
43
insert into t1 values (869751),(736494),(226312),(802616),(728912);
44
select * from t1 where a > 736494;
45
a
46
869751
47
802616
48
alter table t1 add unique uniq_id using BTREE (a);
49
select * from t1 where a > 736494;
50
a
51
802616
52
869751
53
select * from t1 where a = 736494;
54
a
55
736494
56
select * from t1 where a=869751 or a=736494;
57
a
58
736494
59
869751
60
select * from t1 where a in (869751,736494,226312,802616);
61
a
62
226312
63
736494
64
802616
65
869751
66
alter table t1 engine=myisam;
67
explain select * from t1 where a in (869751,736494,226312,802616);
68
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
69
1	SIMPLE	t1	range	uniq_id	uniq_id	4	NULL	4	Using where; Using index
70
drop table t1;
71
create table t1 (x int not null, y int not null, key x  using BTREE (x,y), unique y  using BTREE (y))
72
engine=heap;
73
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
74
explain select * from t1 where x=1;
75
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
76
1	SIMPLE	t1	ref	x	x	4	const	1	
77
select * from t1 where x=1;
78
x	y
79
1	1
80
1	3
81
select * from t1,t1 as t2 where t1.x=t2.y;
82
x	y	x	y
83
1	1	1	1
84
2	2	2	2
85
1	3	1	1
86
2	4	2	2
87
2	5	2	2
88
2	6	2	2
89
explain select * from t1,t1 as t2 where t1.x=t2.y;
90
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
91
1	SIMPLE	t1	ALL	x	NULL	NULL	NULL	6	
92
1	SIMPLE	t2	eq_ref	y	y	4	test.t1.x	1	
93
drop table t1;
94
create table t1 (a int) engine=heap;
95
insert into t1 values(1);
96
select max(a) from t1;
97
max(a)
98
1
99
drop table t1;
100
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;
101
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
102
select * from t1 where a=1;
103
a	b
104
1	1
105
1	2
106
1	3
107
1	4
108
1	5
109
1	6
110
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
111
select * from t1 where a=1;
112
a	b
113
1	1
114
1	1
115
1	2
116
1	2
117
1	3
118
1	3
119
1	4
120
1	4
121
1	5
122
1	5
123
1	6
124
1	6
125
explain select * from tx where a=x order by a,b;
126
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
127
x	SIMPLE	tx	ref	a	a	x	const	x	Using where
128
explain select * from tx where a=x order by b;
129
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
130
x	SIMPLE	tx	ref	a	a	x	const	x	Using where
131
select * from t1 where b=1;
132
a	b
133
1	1
134
1	1
135
explain select * from tx where b=x;
136
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
137
x	SIMPLE	tx	ref	b	b	x	const	x	
138
drop table t1;
413.2.2 by Brian Aker
Removed UNSIGNED from parser.
139
create table t1 (id int not null, primary key  using BTREE (id)) engine=HEAP;
1 by brian
clean slate
140
insert into t1 values(1);
141
select max(id) from t1;
142
max(id)
143
1
144
insert into t1 values(2);
145
select max(id) from t1;
146
max(id)
147
2
148
replace into t1 values(1);
149
drop table t1;
150
create table t1 (n int) engine=heap;
151
drop table t1;
152
create table t1 (n int) engine=heap;
153
drop table if exists t1;
154
CREATE table t1(f1 int not null,f2 char(20) not 
155
null,index(f2)) engine=heap;
156
INSERT into t1 set f1=12,f2="bill";
157
INSERT into t1 set f1=13,f2="bill";
158
INSERT into t1 set f1=14,f2="bill";
159
INSERT into t1 set f1=15,f2="bill";
160
INSERT into t1 set f1=16,f2="ted";
161
INSERT into t1 set f1=12,f2="ted";
162
INSERT into t1 set f1=12,f2="ted";
163
INSERT into t1 set f1=12,f2="ted";
164
INSERT into t1 set f1=12,f2="ted";
165
delete from t1 where f2="bill";
166
select * from t1;
167
f1	f2
168
16	ted
169
12	ted
170
12	ted
171
12	ted
172
12	ted
173
drop table t1;
174
create table t1 (btn char(10) not null, key using BTREE (btn)) engine=heap;
175
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
176
explain select * from t1 where btn like "i%";
177
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
178
1	SIMPLE	t1	range	btn	btn	42	NULL	1	Using where
1 by brian
clean slate
179
explain select * from t1 where btn like "h%";
180
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
181
1	SIMPLE	t1	range	btn	btn	42	NULL	#	Using where
1 by brian
clean slate
182
explain select * from t1 where btn like "a%";
183
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
184
1	SIMPLE	t1	range	btn	btn	42	NULL	1	Using where
1 by brian
clean slate
185
explain select * from t1 where btn like "b%";
186
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
187
1	SIMPLE	t1	range	btn	btn	42	NULL	1	Using where
1 by brian
clean slate
188
select * from t1 where btn like "ff%";
189
btn
190
select * from t1 where btn like " %";
191
btn
192
select * from t1 where btn like "q%";
193
btn
194
alter table t1 add column new_col char(1) not null, add key using BTREE (btn,new_col), drop key btn;
195
update t1 set new_col=left(btn,1);
196
explain select * from t1 where btn="a";
197
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
198
1	SIMPLE	t1	ref	btn	btn	42	const	1	Using where
1 by brian
clean slate
199
explain select * from t1 where btn="a" and new_col="a";
200
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
383.1.16 by Brian Aker
Force client communication into UTF8
201
1	SIMPLE	t1	ref	btn	btn	48	const,const	1	Using where
1 by brian
clean slate
202
drop table t1;
203
CREATE TABLE t1 (
204
a int default NULL,
205
b int default NULL,
206
KEY a using BTREE (a),
207
UNIQUE b using BTREE (b)
208
) engine=heap;
209
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
210
SELECT * FROM t1 WHERE a=NULL;
211
a	b
212
explain SELECT * FROM t1 WHERE a IS NULL;
213
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
214
1	SIMPLE	t1	ref	a	a	5	const	1	Using where
215
SELECT * FROM t1 WHERE a<=>NULL;
216
a	b
217
NULL	99
218
SELECT * FROM t1 WHERE b=NULL;
219
a	b
220
explain SELECT * FROM t1 WHERE b IS NULL;
221
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
222
1	SIMPLE	t1	ref	b	b	5	const	1	Using where
223
SELECT * FROM t1 WHERE b<=>NULL;
224
a	b
225
99	NULL
226
INSERT INTO t1 VALUES (1,3);
227
ERROR 23000: Duplicate entry '3' for key 'b'
228
DROP TABLE t1;
229
CREATE TABLE t1 (a int, b int, c int, key using BTREE (a, b, c)) engine=heap;
230
INSERT INTO t1 VALUES (1, NULL, NULL), (1, 1, NULL), (1, NULL, 1);
231
SELECT * FROM t1 WHERE a=1 and b IS NULL;
232
a	b	c
233
1	NULL	NULL
234
1	NULL	1
235
SELECT * FROM t1 WHERE a=1 and c IS NULL;
236
a	b	c
237
1	NULL	NULL
238
1	1	NULL
239
SELECT * FROM t1 WHERE a=1 and b IS NULL and c IS NULL;
240
a	b	c
241
1	NULL	NULL
242
DROP TABLE t1;
243
CREATE TABLE t1 (a int not null, primary key using BTREE (a)) engine=heap;
244
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
245
DELETE from t1 where a < 100;
246
SELECT * from t1;
247
a
248
DROP TABLE t1;
249
create table t1(a int not null, key using btree(a)) engine=heap;
250
insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3);
251
select a from t1 where a > 2 order by a;
252
a
253
3
254
3
255
3
256
3
257
delete from t1 where a < 4;
258
select a from t1 order by a;
259
a
260
insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3);
261
select a from t1 where a > 4 order by a;
262
a
263
delete from t1 where a > 4;
264
select a from t1 order by a;
265
a
266
1
267
1
268
2
269
2
270
2
271
3
272
3
273
3
274
3
275
select a from t1 where a > 3 order by a;
276
a
277
delete from t1 where a >= 2;
278
select a from t1 order by a;
279
a
280
1
281
1
282
drop table t1;
283
CREATE TABLE t1 (
284
c1 CHAR(3),
285
c2 INTEGER,
286
KEY USING BTREE(c1),
287
KEY USING BTREE(c2)
288
) ENGINE= MEMORY;
289
INSERT INTO t1 VALUES ('ABC',0), ('A',0), ('B',0), ('C',0);
290
UPDATE t1 SET c2= c2 + 1 WHERE c1 = 'A';
291
SELECT * FROM t1;
292
c1	c2
293
ABC	0
294
A	1
295
B	0
296
C	0
297
DROP TABLE t1;
298
CREATE TABLE t1 (
299
c1 ENUM('1', '2'),
300
UNIQUE USING BTREE(c1)
377.1.4 by Brian Aker
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
301
) ENGINE= MEMORY;
1 by brian
clean slate
302
INSERT INTO t1 VALUES('1'), ('2');
303
DROP TABLE t1;
304
CREATE TABLE t1 (a INT, KEY USING BTREE(a)) ENGINE=MEMORY;
305
INSERT INTO t1 VALUES(1),(2),(2);
306
DELETE FROM t1 WHERE a=2;
307
SELECT * FROM t1;
308
a
309
1
310
DROP TABLE t1;
311
End of 4.1 tests
312
CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
313
INSERT INTO t1 VALUES(0);
314
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
315
INDEX_LENGTH
316
21
317
UPDATE t1 SET val=1;
318
SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1';
319
INDEX_LENGTH
320
21
321
DROP TABLE t1;
322
CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY;
323
INSERT INTO t1 VALUES(NULL),(NULL);
324
DROP TABLE t1;
325
create table t1(a varchar(255), b varchar(255), 
326
key using btree (a,b)) engine=memory;
327
insert into t1 values (1, 1), (3, 3), (2, 2), (NULL, 1), (NULL, NULL), (0, 0);
328
select * from t1 where a is null;
329
a	b
330
NULL	NULL
331
NULL	1
332
drop table t1;
333
End of 5.0 tests