~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/t/heap.test

  • Committer: Lee
  • Date: 2008-10-30 22:02:01 UTC
  • mto: (572.1.2 devel)
  • mto: This revision was merged to the branch mainline in revision 573.
  • Revision ID: lbieber@lbieber-desktop-20081030220201-elb6qprbzpn7c5a4
add my name to the AUTHORS file

Show diffs side-by-side

added added

removed removed

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