6 drop table if exists t1,t2,t3;
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";
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);
20 alter table t1 add c int not null, add key (c,a);
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;
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";
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);
48 create table t1 (x int not null, y int not null, key x (x), unique y (y))
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;
56 create table t1 (a int) engine=heap;
57 insert into t1 values(1);
58 select max(a) from t1;
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;
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);
76 create table t1 (n int) engine=heap;
79 create table t1 (n int) engine=heap;
80 drop table if exists t1;
82 # Test of non unique index
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";
100 # Test when using part key searches
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";
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;
132 INSERT INTO t1 VALUES (1,3);
139 INSERT INTO t1 VALUES (10), (10), (10);
140 EXPLAIN SELECT * FROM t1 WHERE a=10;
141 SELECT * FROM t1 WHERE a=10;
145 # Test when deleting all rows
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;
155 # Bug#4411 Server hangs when trying to SELECT MAX(id) from an empty HEAP table
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`)
164 SELECT MAX(job_title_id) FROM job_titles;
166 DROP TABLE job_titles;
169 # Test of delete with NOT NULL
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;
180 # heap_rfirst() doesn't work (and never did!)
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;
189 # Bug #6878: a problem with small length records
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');
201 # We can't use varchar.inc becasue heap doesn't support blob's
204 let $default=`select @@storage_engine`;
205 set storage_engine=HEAP;
208 # Simple basic test that endspace is saved
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;
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;
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;
242 eval set @space=repeat(' ',10-$1);
245 eval set @char=char(ascii('a')+$2-1);
246 insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space));
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';
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';
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;
297 create table t1 (a char(10), unique (a));
298 insert into t1 values ('a');
300 insert into t1 values ('a ');
302 alter table t1 modify a varchar(10);
304 insert into t1 values ('a '),('a '),('a '),('a ');
306 insert into t1 values ('a ');
308 insert into t1 values ('a ');
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 ';
316 # Testing of btree keys
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;
326 eval set @space=repeat(' ',10-$1);
329 eval set @char=char(ascii('a')+$2-1);
330 insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space));
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 ';
346 select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
348 explain select count(*) from t1 where v='a ';
350 explain select count(*) from t1 where c='a ';
352 explain select count(*) from t1 where t='a ';
354 explain select count(*) from t1 where v like 'a%';
356 explain select count(*) from t1 where v between 'a' and 'a ';
358 explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n';
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
365 explain select * from t1 where v='a';
370 # Test unique btree keys
373 create table t1 (a char(10), unique using btree (a)) engine=heap;
374 insert into t1 values ('a');
376 insert into t1 values ('a ');
378 alter table t1 modify a varchar(10);
380 insert into t1 values ('a '),('a '),('a '),('a ');
382 insert into t1 values ('a ');
384 insert into t1 values ('a ');
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 ';
392 # test show create table
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;
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);
408 eval set storage_engine=$default;
411 # Bug #8489: Strange auto_increment behaviour
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);
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);
427 create table t1 (a int not null, b int not null auto_increment,
428 primary key(a, b)) engine=heap;
431 # Bug #10566: Verify that we can create a prefixed key with length > 255
433 create table t1 (c char(255), primary key(c(90)));
434 insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
436 insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz");
440 # Bug 12796: Record doesn't show when selecting through index
442 CREATE TABLE t1 (a int, key(a)) engine=heap;
443 insert into t1 values (0);
446 insert into t1 values (0), (1);
447 select * from t1 where a = 0;
453 # Bug #3094: Row format of memory tables should always be reported as Fixed
455 create table t1 (c char(10)) engine=memory;
456 create table t2 (c varchar(10)) engine=memory;
457 --replace_column 8 # 12 #
458 show table status like 't_';
462 # BUG#18233 - Memory tables INDEX USING HASH (a,b) returns 1 row on
463 # SELECT WHERE a= AND b=
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);
476 # BUG#26080 - Memory Storage engine not working properly
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);