~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,t2,t3;
7
--enable_warnings
8
9
create table t1 (a int not null,b int not null, primary key (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 (c,a);
21
drop table t1;
22
23
create table t1 (a int not null,b int not null, primary key (a)) engine=memory comment="testing heaps";
24
insert into t1 values(1,1),(2,2),(3,3),(4,4);
25
delete from t1 where a > 0;
26
select * from t1;
27
drop table t1;
28
29
create table t1 (a int not null,b int not null, primary key (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(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 (x), unique y (y))
49
engine=heap;
50
insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6);
51
select * from t1 where x=1;
52
select * from t1,t1 as t2 where t1.x=t2.y;
53
explain select * from t1,t1 as t2 where t1.x=t2.y;
54
drop table t1;
55
56
create table t1 (a int) engine=heap;
57
insert into t1 values(1);
58
select max(a) from t1;
59
drop table t1;
60
61
CREATE TABLE t1 ( a int not null default 0, b int not null default 0,  key(a),  key(b)  ) ENGINE=HEAP;
62
insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6);
63
select * from t1 where a=1; 
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
drop table t1;
67
68
create table t1 (id int unsigned not null, primary key (id)) engine=HEAP;
69
insert into t1 values(1);
70
select max(id) from t1; 
71
insert into t1 values(2);
72
select max(id) from t1; 
73
replace into t1 values(1);
74
drop table t1;
75
76
create table t1 (n int) engine=heap;
77
drop table t1;
78
79
create table t1 (n int) engine=heap;
80
drop table if exists t1;
81
82
# Test of non unique index
83
84
CREATE table t1(f1 int not null,f2 char(20) not 
85
null,index(f2)) engine=heap;
86
INSERT into t1 set f1=12,f2="bill";
87
INSERT into t1 set f1=13,f2="bill";
88
INSERT into t1 set f1=14,f2="bill";
89
INSERT into t1 set f1=15,f2="bill";
90
INSERT into t1 set f1=16,f2="ted";
91
INSERT into t1 set f1=12,f2="ted";
92
INSERT into t1 set f1=12,f2="ted";
93
INSERT into t1 set f1=12,f2="ted";
94
INSERT into t1 set f1=12,f2="ted";
95
delete from t1 where f2="bill";
96
select * from t1;
97
drop table t1;
98
99
#
100
# Test when using part key searches
101
#
102
103
create table t1 (btn char(10) not null, key(btn)) engine=heap;
104
insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i");
105
explain select * from t1 where btn like "q%";
106
select * from t1 where btn like "q%";
107
alter table t1 add column new_col char(1) not null, add key (btn,new_col), drop key btn;
108
update t1 set new_col=left(btn,1);
109
explain select * from t1 where btn="a";
110
explain select * from t1 where btn="a" and new_col="a";
111
drop table t1;
112
113
#
114
# Test of NULL keys
115
#
116
117
CREATE TABLE t1 (
118
  a int default NULL,
119
  b int default NULL,
120
  KEY a (a),
121
  UNIQUE b (b)
122
) engine=heap;
123
INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3);
124
SELECT * FROM t1 WHERE a=NULL;
125
explain SELECT * FROM t1 WHERE a IS NULL;
126
SELECT * FROM t1 WHERE a<=>NULL;
127
SELECT * FROM t1 WHERE b=NULL;
128
explain SELECT * FROM t1 WHERE b IS NULL;
129
SELECT * FROM t1 WHERE b<=>NULL;
130
131
--error ER_DUP_ENTRY
132
INSERT INTO t1 VALUES (1,3);
133
DROP TABLE t1;
134
135
CREATE TABLE t1 (
136
  a int default NULL,
137
  key a (a)
138
) ENGINE=HEAP;
139
INSERT INTO t1 VALUES (10), (10), (10);
140
EXPLAIN SELECT * FROM t1 WHERE a=10;
141
SELECT * FROM t1 WHERE a=10;
142
DROP TABLE t1;
143
144
#
145
# Test when deleting all rows
146
#
147
148
CREATE TABLE t1 (a int not null, primary key(a)) engine=heap;
149
INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11);
150
DELETE from t1 where a < 100;
151
SELECT * from t1;
152
DROP TABLE t1;
153
154
#
155
# Bug#4411 Server hangs when trying to SELECT MAX(id) from an empty HEAP table
156
#
157
CREATE TABLE `job_titles` (
158
  `job_title_id` int(6) unsigned NOT NULL default '0',
159
  `job_title` char(18) NOT NULL default '',
160
  PRIMARY KEY  (`job_title_id`),
161
  UNIQUE KEY `job_title_id` (`job_title_id`,`job_title`)
162
) ENGINE=HEAP;
163
164
SELECT MAX(job_title_id) FROM job_titles;
165
166
DROP TABLE job_titles;
167
168
#
169
# Test of delete with NOT NULL
170
# (Bug #6082)
171
#
172
173
CREATE TABLE t1 (a INT NOT NULL, B INT, KEY(B)) ENGINE=HEAP;
174
INSERT INTO t1 VALUES(1,1), (1,NULL);
175
SELECT * FROM t1 WHERE B is not null;
176
DROP TABLE t1;
177
178
#
179
# Bug #6748
180
# heap_rfirst() doesn't work (and never did!)
181
#
182
CREATE TABLE t1 (pseudo char(35) PRIMARY KEY, date int(10) unsigned NOT NULL) ENGINE=HEAP;
183
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);
184
DELETE FROM t1 WHERE date<1101106546;
185
SELECT * FROM t1;
186
DROP TABLE t1;
187
188
#
189
# Bug #6878: a problem with small length records
190
#
191
192
create table t1(a char(2)) engine=memory;
193
insert into t1 values (NULL), (NULL);
194
delete from t1 where a is null;
195
insert into t1 values ('2'), ('3');
196
select * from t1;
197
drop table t1;
198
199
#
200
# Test varchar
201
# We can't use varchar.inc becasue heap doesn't support blob's
202
#
203
204
let $default=`select @@storage_engine`;
205
set storage_engine=HEAP;
206
207
#
208
# Simple basic test that endspace is saved
209
#
210
211
create table t1 (v varchar(10), c char(10), t varchar(50));
212
insert into t1 values('+ ', '+ ', '+ ');
213
set @a=repeat(' ',20);
214
insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a));
215
select concat('*',v,'*',c,'*',t,'*') from t1;
216
217
# Check how columns are copied
218
show create table t1;
219
create table t2 like t1;
220
show create table t2;
221
create table t3 select * from t1;
222
show create table t3;
223
alter table t1 modify c varchar(10);
224
show create table t1;
225
alter table t1 modify v char(10);
226
show create table t1;
227
alter table t1 modify t varchar(10);
228
show create table t1;
229
select concat('*',v,'*',c,'*',t,'*') from t1;
230
drop table t1,t2,t3;
231
232
#
233
# Testing of keys
234
#
235
create table t1 (v varchar(10), c char(10), t varchar(50), key(v), key(c), key(t(10)));
236
show create table t1;
237
disable_query_log;
238
let $1=10;
239
while ($1)
240
{
241
  let $2=27;
242
  eval set @space=repeat(' ',10-$1);
243
  while ($2)
244
  {
245
    eval set @char=char(ascii('a')+$2-1);
246
    insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space));
247
    dec $2;
248
  }
249
  dec $1;
250
}
251
enable_query_log;
252
select count(*) from t1;
253
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
254
select count(*) from t1 where v='a';
255
select count(*) from t1 where c='a';
256
select count(*) from t1 where t='a';
257
select count(*) from t1 where v='a  ';
258
select count(*) from t1 where c='a  ';
259
select count(*) from t1 where t='a  ';
260
select count(*) from t1 where v between 'a' and 'a ';
261
select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
262
select count(*) from t1 where v like 'a%';
263
select count(*) from t1 where c like 'a%';
264
select count(*) from t1 where t like 'a%';
265
select count(*) from t1 where v like 'a %';
266
explain select count(*) from t1 where v='a  ';
267
explain select count(*) from t1 where c='a  ';
268
explain select count(*) from t1 where t='a  ';
269
explain select count(*) from t1 where v like 'a%';
270
explain select count(*) from t1 where v between 'a' and 'a ';
271
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
272
273
--error ER_DUP_ENTRY
274
alter table t1 add unique(v);
275
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*'));
276
explain select * from t1 where v='a';
277
278
# GROUP BY
279
280
select v,count(*) from t1 group by v limit 10;
281
select v,count(t) from t1 group by v limit 10;
282
select v,count(c) from t1 group by v limit 10;
283
select sql_big_result trim(v),count(t) from t1 group by v limit 10;
284
select sql_big_result trim(v),count(c) from t1 group by v limit 10;
285
select c,count(*) from t1 group by c limit 10;
286
select c,count(t) from t1 group by c limit 10;
287
select sql_big_result c,count(t) from t1 group by c limit 10;
288
select t,count(*) from t1 group by t limit 10;
289
select t,count(t) from t1 group by t limit 10;
290
select sql_big_result trim(t),count(t) from t1 group by t limit 10;
291
drop table t1;
292
293
#
294
# Test unique keys
295
#
296
297
create table t1 (a char(10), unique (a));
298
insert into t1 values ('a');
299
--error ER_DUP_ENTRY
300
insert into t1 values ('a ');
301
302
alter table t1 modify a varchar(10);
303
--error ER_DUP_ENTRY
304
insert into t1 values ('a '),('a  '),('a   '),('a         ');
305
--error ER_DUP_ENTRY
306
insert into t1 values ('a     ');
307
--error ER_DUP_ENTRY
308
insert into t1 values ('a          ');
309
--error ER_DUP_ENTRY
310
insert into t1 values ('a ');
311
update t1 set a='a      ' where a like 'a ';
312
update t1 set a='a  ' where a like 'a      ';
313
drop table t1;
314
315
#
316
# Testing of btree keys
317
#
318
319
create table t1 (v varchar(10), c char(10), t varchar(50), key using btree (v), key using btree (c), key using btree (t(10)));
320
show create table t1;
321
disable_query_log;
322
let $1=10;
323
while ($1)
324
{
325
  let $2=27;
326
  eval set @space=repeat(' ',10-$1);
327
  while ($2)
328
  {
329
    eval set @char=char(ascii('a')+$2-1);
330
    insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space));
331
    dec $2;
332
  }
333
  dec $1;
334
}
335
enable_query_log;
336
select count(*) from t1;
337
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
338
select count(*) from t1 where v='a';
339
select count(*) from t1 where c='a';
340
select count(*) from t1 where t='a';
341
select count(*) from t1 where v='a  ';
342
select count(*) from t1 where c='a  ';
343
select count(*) from t1 where t='a  ';
344
select count(*) from t1 where v between 'a' and 'a ';
345
--replace_column 9 #
346
select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
347
--replace_column 9 #
348
explain select count(*) from t1 where v='a  ';
349
--replace_column 9 #
350
explain select count(*) from t1 where c='a  ';
351
--replace_column 9 #
352
explain select count(*) from t1 where t='a  ';
353
--replace_column 9 #
354
explain select count(*) from t1 where v like 'a%';
355
--replace_column 9 #
356
explain select count(*) from t1 where v between 'a' and 'a ';
357
--replace_column 9 #
358
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
359
360
--error ER_DUP_ENTRY
361
alter table t1 add unique(v);
362
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*'));
363
# Number of rows is not constant for b-trees keys
364
--replace_column 9 #
365
explain select * from t1 where v='a';
366
367
drop table t1;
368
369
#
370
# Test unique btree keys
371
#
372
373
create table t1 (a char(10), unique using btree (a)) engine=heap;
374
insert into t1 values ('a');
375
--error ER_DUP_ENTRY
376
insert into t1 values ('a ');
377
378
alter table t1 modify a varchar(10);
379
--error ER_DUP_ENTRY
380
insert into t1 values ('a '),('a  '),('a   '),('a         ');
381
--error ER_DUP_ENTRY
382
insert into t1 values ('a     ');
383
--error ER_DUP_ENTRY
384
insert into t1 values ('a          ');
385
--error ER_DUP_ENTRY
386
insert into t1 values ('a ');
387
update t1 set a='a      ' where a like 'a ';
388
update t1 set a='a  ' where a like 'a      ';
389
drop table t1;
390
391
#
392
# test show create table
393
#
394
395
create table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5)));
396
show create table t1;
397
drop table t1;
398
399
create table t1 (v varchar(65530), key(v(10)));
400
show create table t1;
401
insert into t1 values(repeat('a',65530));
402
select length(v) from t1 where v=repeat('a',65530);
403
drop table t1;
404
405
#
406
# Reset varchar test
407
#
408
eval set storage_engine=$default;
409
410
#
411
# Bug #8489: Strange auto_increment behaviour
412
#
413
414
create table t1 (a bigint unsigned auto_increment primary key, b int,
415
  key (b, a)) engine=heap;
416
insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1);
417
select * from t1;
418
drop table t1;
419
420
create table t1 (a int not null, b int not null auto_increment,
421
  primary key(a, b), key(b)) engine=heap;
422
insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1);
423
select * from t1;
424
drop table t1;
425
426
--error 1075
427
create table t1 (a int not null, b int not null auto_increment,
428
  primary key(a, b)) engine=heap;
429
430
#
431
# Bug #10566: Verify that we can create a prefixed key with length > 255
432
#
433
create table t1 (c char(255), primary key(c(90)));
434
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
435
--error ER_DUP_ENTRY
436
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
437
drop table t1;
438
439
#
440
# Bug 12796: Record doesn't show when selecting through index
441
#
442
CREATE TABLE t1 (a int, key(a)) engine=heap;
443
insert into t1 values (0);
444
delete from t1;
445
select * from t1;
446
insert into t1 values (0), (1);
447
select * from t1 where a = 0;
448
drop table t1;
449
450
# End of 4.1 tests
451
452
#
453
# Bug #3094: Row format of memory tables should always be reported as Fixed
454
#
455
create table t1 (c char(10)) engine=memory;
456
create table t2 (c varchar(10)) engine=memory;
457
--replace_column 8 #
458
show table status like 't_';
459
drop table t1, t2;
460
461
#
462
# BUG#18233 - Memory tables INDEX USING HASH (a,b) returns 1 row on
463
#             SELECT WHERE a= AND b=
464
#
465
CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
466
                KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY;
467
INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256));
468
SELECT COUNT(*) FROM t1 WHERE a='a';
469
SELECT COUNT(*) FROM t1 WHERE b='aa';
470
SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256);
471
DROP TABLE t1;
472
473
# End of 5.0 tests
474
475
#
476
# BUG#26080 - Memory Storage engine not working properly
477
#
478
CREATE TABLE t1(c1 VARCHAR(100), c2 INT) ENGINE=MEMORY;
479
INSERT INTO t1 VALUES('', 0);
480
ALTER TABLE t1 MODIFY c1 VARCHAR(101);
481
SELECT c2 FROM t1;
482
DROP TABLE t1;