~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/heap.test

  • Committer: Stewart Smith
  • Date: 2008-07-13 06:56:15 UTC
  • mto: (210.1.1 drizzle)
  • mto: This revision was merged to the branch mainline in revision 211.
  • Revision ID: stewart@flamingspork.com-20080713065615-vzok75kgnnviokl9
Move MD5() into a UDF

Show diffs side-by-side

added added

removed removed

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