~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/heap.test

change error message of scp .frm files

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 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 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 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(50);
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 t,count(*) from t1 group by t limit 10;
288
 
select t,count(t) from t1 group by t limit 10;
289
 
select sql_big_result trim(t),count(t) from t1 group by t limit 10;
290
 
drop table t1;
291
 
 
292
 
#
293
 
# Test unique keys
294
 
#
295
 
 
296
 
create table t1 (a char(10), unique (a));
297
 
insert into t1 values ('a');
298
 
--error ER_DUP_ENTRY
299
 
insert into t1 values ('a ');
300
 
 
301
 
alter table t1 modify a varchar(10);
302
 
--error ER_DUP_ENTRY
303
 
insert into t1 values ('a '),('a  '),('a   '),('a         ');
304
 
--error ER_DUP_ENTRY
305
 
insert into t1 values ('a     ');
306
 
--error ER_DUP_ENTRY
307
 
insert into t1 values ('a          ');
308
 
--error ER_DUP_ENTRY
309
 
insert into t1 values ('a ');
310
 
update t1 set a='a      ' where a like 'a ';
311
 
update t1 set a='a  ' where a like 'a      ';
312
 
drop table t1;
313
 
 
314
 
#
315
 
# Testing of btree keys
316
 
#
317
 
 
318
 
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)));
319
 
show create table t1;
320
 
disable_query_log;
321
 
let $1=10;
322
 
while ($1)
323
 
{
324
 
  let $2=27;
325
 
  eval set @space=repeat(' ',10-$1);
326
 
  while ($2)
327
 
  {
328
 
    eval set @char=char(ascii('a')+$2-1);
329
 
    insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space));
330
 
    dec $2;
331
 
  }
332
 
  dec $1;
333
 
}
334
 
enable_query_log;
335
 
select count(*) from t1;
336
 
insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1)));
337
 
select count(*) from t1 where v='a';
338
 
select count(*) from t1 where c='a';
339
 
select count(*) from t1 where t='a';
340
 
select count(*) from t1 where v='a  ';
341
 
select count(*) from t1 where c='a  ';
342
 
select count(*) from t1 where t='a  ';
343
 
select count(*) from t1 where v between 'a' and 'a ';
344
 
--replace_column 9 #
345
 
select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
346
 
--replace_column 9 #
347
 
explain select count(*) from t1 where v='a  ';
348
 
--replace_column 9 #
349
 
explain select count(*) from t1 where c='a  ';
350
 
--replace_column 9 #
351
 
explain select count(*) from t1 where t='a  ';
352
 
--replace_column 9 #
353
 
explain select count(*) from t1 where v like 'a%';
354
 
--replace_column 9 #
355
 
explain select count(*) from t1 where v between 'a' and 'a ';
356
 
--replace_column 9 #
357
 
explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a  ' and 'b\n';
358
 
 
359
 
--error ER_DUP_ENTRY
360
 
alter table t1 add unique(v);
361
 
select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*'));
362
 
# Number of rows is not constant for b-trees keys
363
 
--replace_column 9 #
364
 
explain select * from t1 where v='a';
365
 
 
366
 
drop table t1;
367
 
 
368
 
#
369
 
# Test unique btree keys
370
 
#
371
 
 
372
 
create table t1 (a char(10), unique using btree (a)) engine=heap;
373
 
insert into t1 values ('a');
374
 
--error ER_DUP_ENTRY
375
 
insert into t1 values ('a ');
376
 
 
377
 
alter table t1 modify a varchar(10);
378
 
--error ER_DUP_ENTRY
379
 
insert into t1 values ('a '),('a  '),('a   '),('a         ');
380
 
--error ER_DUP_ENTRY
381
 
insert into t1 values ('a     ');
382
 
--error ER_DUP_ENTRY
383
 
insert into t1 values ('a          ');
384
 
--error ER_DUP_ENTRY
385
 
insert into t1 values ('a ');
386
 
update t1 set a='a      ' where a like 'a ';
387
 
update t1 set a='a  ' where a like 'a      ';
388
 
drop table t1;
389
 
 
390
 
#
391
 
# test show create table
392
 
#
393
 
 
394
 
create table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5)));
395
 
show create table t1;
396
 
drop table t1;
397
 
 
398
 
create table t1 (v varchar(16383), key(v(10)));
399
 
show create table t1;
400
 
insert into t1 values(repeat('a',16383));
401
 
select length(v) from t1 where v=repeat('a',16383);
402
 
drop table t1;
403
 
 
404
 
#
405
 
# Reset varchar test
406
 
#
407
 
eval set storage_engine=$default;
408
 
 
409
 
#
410
 
# Bug #8489: Strange auto_increment behaviour
411
 
#
412
 
 
413
 
create table t1 (a bigint auto_increment primary key, b int,
414
 
  key (b, a)) engine=heap;
415
 
insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1);
416
 
select * from t1;
417
 
drop table t1;
418
 
 
419
 
create table t1 (a int not null, b int not null auto_increment,
420
 
  primary key(a, b), key(b)) engine=heap;
421
 
insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1);
422
 
select * from t1;
423
 
drop table t1;
424
 
 
425
 
--error 1075
426
 
create table t1 (a int not null, b int not null auto_increment,
427
 
  primary key(a, b)) engine=heap;
428
 
 
429
 
#
430
 
# Bug #10566: Verify that we can create a prefixed key with length > 255
431
 
#
432
 
create table t1 (c char(255), primary key(c(90)));
433
 
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
434
 
--error ER_DUP_ENTRY
435
 
insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
436
 
drop table t1;
437
 
 
438
 
#
439
 
# Bug 12796: Record doesn't show when selecting through index
440
 
#
441
 
CREATE TABLE t1 (a int, key(a)) engine=heap;
442
 
insert into t1 values (0);
443
 
delete from t1;
444
 
select * from t1;
445
 
insert into t1 values (0), (1);
446
 
select * from t1 where a = 0;
447
 
drop table t1;
448
 
 
449
 
# End of 4.1 tests
450
 
 
451
 
#
452
 
# Bug #3094: Row format of memory tables should always be reported as Fixed
453
 
#
454
 
create table t1 (c char(10)) engine=memory;
455
 
create table t2 (c varchar(10)) engine=memory;
456
 
--replace_column 3 # 8 #
457
 
show table status like 't_';
458
 
drop table t1, t2;
459
 
 
460
 
#
461
 
# BUG#18233 - Memory tables INDEX USING HASH (a,b) returns 1 row on
462
 
#             SELECT WHERE a= AND b=
463
 
#
464
 
CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256),
465
 
                KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY;
466
 
INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256));
467
 
SELECT COUNT(*) FROM t1 WHERE a='a';
468
 
SELECT COUNT(*) FROM t1 WHERE b='aa';
469
 
SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256);
470
 
DROP TABLE t1;
471
 
 
472
 
# End of 5.0 tests
473
 
 
474
 
#
475
 
# BUG#26080 - Memory Storage engine not working properly
476
 
#
477
 
CREATE TABLE t1(c1 VARCHAR(100), c2 INT) ENGINE=MEMORY;
478
 
INSERT INTO t1 VALUES('', 0);
479
 
ALTER TABLE t1 MODIFY c1 VARCHAR(101);
480
 
SELECT c2 FROM t1;
481
 
DROP TABLE t1;