diff options
author | Michael Widenius <monty@askmonty.org> | 2012-04-04 00:16:38 +0300 |
---|---|---|
committer | Michael Widenius <monty@askmonty.org> | 2012-04-04 00:16:38 +0300 |
commit | b04c4801b0529aebb39c8d9be95c123d2f3b7d46 (patch) | |
tree | 0a4f72935b5ac6816996172ae412b62327b4caf4 /mysql-test/suite/heap | |
parent | 34ed8f33795b639d21817003236ce0f6c069481d (diff) | |
download | mariadb-git-b04c4801b0529aebb39c8d9be95c123d2f3b7d46.tar.gz |
Created suites for heap, archive and csv.
Moved test from main suite to the new suites.
Move tests from maria/t and maria/r to maria
mysql-test/mysql-test-run.pl:
Added support for the new suites
Diffstat (limited to 'mysql-test/suite/heap')
-rw-r--r-- | mysql-test/suite/heap/heap.result | 740 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap.test | 487 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_auto_increment.result | 41 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_auto_increment.test | 35 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_btree.result | 381 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_btree.test | 281 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_hash.result | 430 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_hash.test | 319 |
8 files changed, 2714 insertions, 0 deletions
diff --git a/mysql-test/suite/heap/heap.result b/mysql-test/suite/heap/heap.result new file mode 100644 index 00000000000..f058c9f9c72 --- /dev/null +++ b/mysql-test/suite/heap/heap.result @@ -0,0 +1,740 @@ +drop table if exists t1,t2,t3; +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; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a=1 or a=0; +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 a NULL 3 NULL NULL HASH +select * from t1; +a b +2 2 +3 3 +4 4 +select * from t1 where a=4; +a b +4 4 +update t1 set b=5 where a=4; +update t1 set b=b+1 where a>=3; +replace t1 values (3,3); +select * from t1; +a b +2 2 +3 3 +4 6 +alter table t1 add c int not null, add key (c,a); +drop table t1; +create table t1 (a int not null,b int not null, primary key (a)) engine=memory comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a > 0; +select * from t1; +a b +drop table t1; +create table t1 (a int not null,b int not null, primary key (a)) engine=heap comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table"; +select * from t1; +a b +1 1 +2 2 +3 3 +4 4 +drop table t1; +create table t1 (a int not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +select * from t1 where a > 736494; +a +869751 +802616 +alter table t1 add unique uniq_id(a); +select * from t1 where a > 736494; +a +869751 +802616 +select * from t1 where a = 736494; +a +736494 +select * from t1 where a=869751 or a=736494; +a +736494 +869751 +select * from t1 where a in (869751,736494,226312,802616); +a +226312 +736494 +802616 +869751 +alter table t1 engine=myisam; +explain select * from t1 where a in (869751,736494,226312,802616); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range uniq_id uniq_id 4 NULL 4 Using where; Using index +drop table t1; +create table t1 (x int not null, y int not null, key x (x), unique y (y)) +engine=heap; +insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6); +select * from t1 where x=1; +x y +1 3 +1 1 +select * from t1,t1 as t2 where t1.x=t2.y; +x y x y +1 1 1 1 +2 2 2 2 +1 3 1 1 +2 4 2 2 +2 5 2 2 +2 6 2 2 +explain select * from t1,t1 as t2 where t1.x=t2.y; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL x NULL NULL NULL 6 +1 SIMPLE t2 eq_ref y y 4 test.t1.x 1 +drop table t1; +create table t1 (a int) engine=heap; +insert into t1 values(1); +select max(a) from t1; +max(a) +1 +drop table t1; +CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key(a), key(b) ) ENGINE=HEAP; +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +a b +1 6 +1 5 +1 4 +1 3 +1 2 +1 1 +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +a b +1 6 +1 5 +1 4 +1 3 +1 2 +1 1 +1 6 +1 5 +1 4 +1 3 +1 2 +1 1 +drop table t1; +create table t1 (id int unsigned not null, primary key (id)) engine=HEAP; +insert into t1 values(1); +select max(id) from t1; +max(id) +1 +insert into t1 values(2); +select max(id) from t1; +max(id) +2 +replace into t1 values(1); +drop table t1; +create table t1 (n int) engine=heap; +drop table t1; +create table t1 (n int) engine=heap; +drop table if exists t1; +CREATE table t1(f1 int not null,f2 char(20) not +null,index(f2)) engine=heap; +INSERT into t1 set f1=12,f2="bill"; +INSERT into t1 set f1=13,f2="bill"; +INSERT into t1 set f1=14,f2="bill"; +INSERT into t1 set f1=15,f2="bill"; +INSERT into t1 set f1=16,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +delete from t1 where f2="bill"; +select * from t1; +f1 f2 +16 ted +12 ted +12 ted +12 ted +12 ted +drop table t1; +create table t1 (btn char(10) not null, key(btn)) engine=heap; +insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); +explain select * from t1 where btn like "q%"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where +select * from t1 where btn like "q%"; +btn +alter table t1 add column new_col char(1) not null, add key (btn,new_col), drop key btn; +update t1 set new_col=left(btn,1); +explain select * from t1 where btn="a"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where +explain select * from t1 where btn="a" and new_col="a"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref btn btn 11 const,const 2 Using where +drop table t1; +CREATE TABLE t1 ( +a int default NULL, +b int default NULL, +KEY a (a), +UNIQUE b (b) +) engine=heap; +INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3); +SELECT * FROM t1 WHERE a=NULL; +a b +explain SELECT * FROM t1 WHERE a IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 5 const 2 Using where +SELECT * FROM t1 WHERE a<=>NULL; +a b +NULL 99 +SELECT * FROM t1 WHERE b=NULL; +a b +explain SELECT * FROM t1 WHERE b IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref b b 5 const 1 Using where +SELECT * FROM t1 WHERE b<=>NULL; +a b +99 NULL +INSERT INTO t1 VALUES (1,3); +ERROR 23000: Duplicate entry '3' for key 'b' +DROP TABLE t1; +CREATE TABLE t1 ( +a int default NULL, +key a (a) +) ENGINE=HEAP; +INSERT INTO t1 VALUES (10), (10), (10); +EXPLAIN SELECT * FROM t1 WHERE a=10; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 5 const 3 +SELECT * FROM t1 WHERE a=10; +a +10 +10 +10 +DROP TABLE t1; +CREATE TABLE t1 (a int not null, primary key(a)) engine=heap; +INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11); +DELETE from t1 where a < 100; +SELECT * from t1; +a +DROP TABLE t1; +CREATE TABLE `job_titles` ( +`job_title_id` int(6) unsigned NOT NULL default '0', +`job_title` char(18) NOT NULL default '', +PRIMARY KEY (`job_title_id`), +UNIQUE KEY `job_title_id` (`job_title_id`,`job_title`) +) ENGINE=HEAP; +SELECT MAX(job_title_id) FROM job_titles; +MAX(job_title_id) +NULL +DROP TABLE job_titles; +CREATE TABLE t1 (a INT NOT NULL, B INT, KEY(B)) ENGINE=HEAP; +INSERT INTO t1 VALUES(1,1), (1,NULL); +SELECT * FROM t1 WHERE B is not null; +a B +1 1 +DROP TABLE t1; +CREATE TABLE t1 (pseudo char(35) PRIMARY KEY, date int(10) unsigned NOT NULL) ENGINE=HEAP; +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); +DELETE FROM t1 WHERE date<1101106546; +SELECT * FROM t1; +pseudo date +ZoomZip 1101106546 +DROP TABLE t1; +create table t1(a char(2)) engine=memory; +insert into t1 values (NULL), (NULL); +delete from t1 where a is null; +insert into t1 values ('2'), ('3'); +select * from t1; +a +3 +2 +drop table t1; +set storage_engine=HEAP; +create table t1 (v varchar(10), c char(10), t varchar(50)); +insert into t1 values('+ ', '+ ', '+ '); +set @a=repeat(' ',20); +insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a)); +Warnings: +Note 1265 Data truncated for column 'v' at row 1 +select concat('*',v,'*',c,'*',t,'*') from t1; +concat('*',v,'*',c,'*',t,'*') +*+ *+*+ * +*+ *+*+ * +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` varchar(10) DEFAULT NULL, + `c` char(10) DEFAULT NULL, + `t` varchar(50) DEFAULT NULL +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +create table t2 like t1; +show create table t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `v` varchar(10) DEFAULT NULL, + `c` char(10) DEFAULT NULL, + `t` varchar(50) DEFAULT NULL +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +create table t3 select * from t1; +show create table t3; +Table Create Table +t3 CREATE TABLE `t3` ( + `v` varchar(10) DEFAULT NULL, + `c` char(10) DEFAULT NULL, + `t` varchar(50) DEFAULT NULL +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +alter table t1 modify c varchar(10); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` varchar(10) DEFAULT NULL, + `c` varchar(10) DEFAULT NULL, + `t` varchar(50) DEFAULT NULL +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +alter table t1 modify v char(10); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` char(10) DEFAULT NULL, + `c` varchar(10) DEFAULT NULL, + `t` varchar(50) DEFAULT NULL +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +alter table t1 modify t varchar(10); +Warnings: +Warning 1265 Data truncated for column 't' at row 2 +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` char(10) DEFAULT NULL, + `c` varchar(10) DEFAULT NULL, + `t` varchar(10) DEFAULT NULL +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +select concat('*',v,'*',c,'*',t,'*') from t1; +concat('*',v,'*',c,'*',t,'*') +*+*+*+ * +*+*+*+ * +drop table t1,t2,t3; +create table t1 (v varchar(10), c char(10), t varchar(50), key(v), key(c), key(t(10))); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` varchar(10) DEFAULT NULL, + `c` char(10) DEFAULT NULL, + `t` varchar(50) DEFAULT NULL, + KEY `v` (`v`), + KEY `c` (`c`), + KEY `t` (`t`(10)) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +select count(*) from t1; +count(*) +270 +insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1))); +select count(*) from t1 where v='a'; +count(*) +10 +select count(*) from t1 where c='a'; +count(*) +10 +select count(*) from t1 where t='a'; +count(*) +10 +select count(*) from t1 where v='a '; +count(*) +10 +select count(*) from t1 where c='a '; +count(*) +10 +select count(*) from t1 where t='a '; +count(*) +10 +select count(*) from t1 where v between 'a' and 'a '; +count(*) +10 +select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; +count(*) +10 +select count(*) from t1 where v like 'a%'; +count(*) +11 +select count(*) from t1 where c like 'a%'; +count(*) +11 +select count(*) from t1 where t like 'a%'; +count(*) +11 +select count(*) from t1 where v like 'a %'; +count(*) +9 +explain select count(*) from t1 where v='a '; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref v v 13 const 10 Using where +explain select count(*) from t1 where c='a '; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref c c 11 const 10 Using where +explain select count(*) from t1 where t='a '; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref t t 13 const 10 Using where +explain select count(*) from t1 where v like 'a%'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL v NULL NULL NULL 271 Using where +explain select count(*) from t1 where v between 'a' and 'a '; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref v v 13 const 10 Using where +explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref v v 13 const 10 Using where +alter table t1 add unique(v); +ERROR 23000: Duplicate entry '{ ' for key 'v_2' +select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*')); +qq +*a*a*a* +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +explain select * from t1 where v='a'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref v v 13 const 10 Using where +select v,count(*) from t1 group by v limit 10; +v count(*) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select v,count(t) from t1 group by v limit 10; +v count(t) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select v,count(c) from t1 group by v limit 10; +v count(c) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select sql_big_result trim(v),count(t) from t1 group by v limit 10; +trim(v) count(t) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select sql_big_result trim(v),count(c) from t1 group by v limit 10; +trim(v) count(c) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select c,count(*) from t1 group by c limit 10; +c count(*) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select c,count(t) from t1 group by c limit 10; +c count(t) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select sql_big_result c,count(t) from t1 group by c limit 10; +c count(t) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select t,count(*) from t1 group by t limit 10; +t count(*) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select t,count(t) from t1 group by t limit 10; +t count(t) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +select sql_big_result trim(t),count(t) from t1 group by t limit 10; +trim(t) count(t) +a 1 +a 10 +b 10 +c 10 +d 10 +e 10 +f 10 +g 10 +h 10 +i 10 +drop table t1; +create table t1 (a char(10), unique (a)); +insert into t1 values ('a'); +insert into t1 values ('a '); +ERROR 23000: Duplicate entry 'a' for key 'a' +alter table t1 modify a varchar(10); +insert into t1 values ('a '),('a '),('a '),('a '); +ERROR 23000: Duplicate entry 'a ' for key 'a' +insert into t1 values ('a '); +ERROR 23000: Duplicate entry 'a ' for key 'a' +insert into t1 values ('a '); +ERROR 23000: Duplicate entry 'a ' for key 'a' +insert into t1 values ('a '); +ERROR 23000: Duplicate entry 'a ' for key 'a' +update t1 set a='a ' where a like 'a '; +update t1 set a='a ' where a like 'a '; +drop table t1; +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))); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` varchar(10) DEFAULT NULL, + `c` char(10) DEFAULT NULL, + `t` varchar(50) DEFAULT NULL, + KEY `v` (`v`) USING BTREE, + KEY `c` (`c`) USING BTREE, + KEY `t` (`t`(10)) USING BTREE +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +select count(*) from t1; +count(*) +270 +insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1))); +select count(*) from t1 where v='a'; +count(*) +10 +select count(*) from t1 where c='a'; +count(*) +10 +select count(*) from t1 where t='a'; +count(*) +10 +select count(*) from t1 where v='a '; +count(*) +10 +select count(*) from t1 where c='a '; +count(*) +10 +select count(*) from t1 where t='a '; +count(*) +10 +select count(*) from t1 where v between 'a' and 'a '; +count(*) +10 +select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; +count(*) +10 +explain select count(*) from t1 where v='a '; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref v v 13 const # Using where +explain select count(*) from t1 where c='a '; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref c c 11 const # Using where +explain select count(*) from t1 where t='a '; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref t t 13 const # Using where +explain select count(*) from t1 where v like 'a%'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range v v 13 NULL # Using where +explain select count(*) from t1 where v between 'a' and 'a '; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref v v 13 const # Using where +explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref v v 13 const # Using where +alter table t1 add unique(v); +ERROR 23000: Duplicate entry '{ ' for key 'v_2' +select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*')); +qq +*a*a*a* +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +*a *a*a * +explain select * from t1 where v='a'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref v v 13 const # Using where +drop table t1; +create table t1 (a char(10), unique using btree (a)) engine=heap; +insert into t1 values ('a'); +insert into t1 values ('a '); +ERROR 23000: Duplicate entry 'a' for key 'a' +alter table t1 modify a varchar(10); +insert into t1 values ('a '),('a '),('a '),('a '); +ERROR 23000: Duplicate entry 'a ' for key 'a' +insert into t1 values ('a '); +ERROR 23000: Duplicate entry 'a ' for key 'a' +insert into t1 values ('a '); +ERROR 23000: Duplicate entry 'a ' for key 'a' +insert into t1 values ('a '); +ERROR 23000: Duplicate entry 'a ' for key 'a' +update t1 set a='a ' where a like 'a '; +update t1 set a='a ' where a like 'a '; +drop table t1; +create table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5))); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` varchar(10) DEFAULT NULL, + `c` char(10) DEFAULT NULL, + `t` varchar(50) DEFAULT NULL, + KEY `v` (`v`(5)), + KEY `c` (`c`(5)), + KEY `t` (`t`(5)) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +drop table t1; +create table t1 (v varchar(65530), key(v(10))); +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `v` varchar(65530) DEFAULT NULL, + KEY `v` (`v`(10)) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 +insert into t1 values(repeat('a',65530)); +select length(v) from t1 where v=repeat('a',65530); +length(v) +65530 +drop table t1; +set storage_engine=MyISAM; +create table t1 (a bigint unsigned auto_increment primary key, b int, +key (b, a)) engine=heap; +insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1); +select * from t1; +a b +1 1 +2 1 +3 1 +4 1 +5 1 +6 1 +7 1 +8 1 +drop table t1; +create table t1 (a int not null, b int not null auto_increment, +primary key(a, b), key(b)) engine=heap; +insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1); +select * from t1; +a b +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +1 7 +1 8 +drop table t1; +create table t1 (a int not null, b int not null auto_increment, +primary key(a, b)) engine=heap; +ERROR 42000: Incorrect table definition; there can be only one auto column and it must be defined as a key +create table t1 (c char(255), primary key(c(90))); +insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); +insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); +ERROR 23000: Duplicate entry 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl' for key 'PRIMARY' +drop table t1; +CREATE TABLE t1 (a int, key(a)) engine=heap; +insert into t1 values (0); +delete from t1; +select * from t1; +a +insert into t1 values (0), (1); +select * from t1 where a = 0; +a +0 +drop table t1; +create table t1 (c char(10)) engine=memory; +create table t2 (c varchar(10)) engine=memory; +show table status like 't_'; +Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment +t1 MEMORY 10 Fixed 0 11 0 # 0 0 NULL # NULL NULL latin1_swedish_ci NULL +t2 MEMORY 10 Fixed 0 12 0 # 0 0 NULL # NULL NULL latin1_swedish_ci NULL +drop table t1, t2; +CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256), +KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY; +INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256)); +SELECT COUNT(*) FROM t1 WHERE a='a'; +COUNT(*) +2 +SELECT COUNT(*) FROM t1 WHERE b='aa'; +COUNT(*) +2 +SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256); +COUNT(*) +2 +DROP TABLE t1; +CREATE TABLE t1(c1 VARCHAR(100), c2 INT) ENGINE=MEMORY; +INSERT INTO t1 VALUES('', 0); +ALTER TABLE t1 MODIFY c1 VARCHAR(101); +SELECT c2 FROM t1; +c2 +0 +DROP TABLE t1; diff --git a/mysql-test/suite/heap/heap.test b/mysql-test/suite/heap/heap.test new file mode 100644 index 00000000000..7d56425799a --- /dev/null +++ b/mysql-test/suite/heap/heap.test @@ -0,0 +1,487 @@ +# +# Test of heap tables. +# + +--disable_warnings +drop table if exists t1,t2,t3; +--enable_warnings + +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; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a=1 or a=0; +#show table status like "t1"; +show keys from t1; +select * from t1; +select * from t1 where a=4; +update t1 set b=5 where a=4; +update t1 set b=b+1 where a>=3; +replace t1 values (3,3); +select * from t1; +alter table t1 add c int not null, add key (c,a); +drop table t1; + +create table t1 (a int not null,b int not null, primary key (a)) engine=memory comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a > 0; +select * from t1; +drop table t1; + +create table t1 (a int not null,b int not null, primary key (a)) engine=heap comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table"; +#show table status like "t1"; +select * from t1; +drop table t1; + +create table t1 (a int not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +select * from t1 where a > 736494; +alter table t1 add unique uniq_id(a); +select * from t1 where a > 736494; +select * from t1 where a = 736494; +select * from t1 where a=869751 or a=736494; +select * from t1 where a in (869751,736494,226312,802616); +alter table t1 engine=myisam; +explain select * from t1 where a in (869751,736494,226312,802616); +drop table t1; + +create table t1 (x int not null, y int not null, key x (x), unique y (y)) +engine=heap; +insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6); +select * from t1 where x=1; +select * from t1,t1 as t2 where t1.x=t2.y; +explain select * from t1,t1 as t2 where t1.x=t2.y; +drop table t1; + +create table t1 (a int) engine=heap; +insert into t1 values(1); +select max(a) from t1; +drop table t1; + +CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key(a), key(b) ) ENGINE=HEAP; +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +drop table t1; + +create table t1 (id int unsigned not null, primary key (id)) engine=HEAP; +insert into t1 values(1); +select max(id) from t1; +insert into t1 values(2); +select max(id) from t1; +replace into t1 values(1); +drop table t1; + +create table t1 (n int) engine=heap; +drop table t1; + +create table t1 (n int) engine=heap; +drop table if exists t1; + +# Test of non unique index + +CREATE table t1(f1 int not null,f2 char(20) not +null,index(f2)) engine=heap; +INSERT into t1 set f1=12,f2="bill"; +INSERT into t1 set f1=13,f2="bill"; +INSERT into t1 set f1=14,f2="bill"; +INSERT into t1 set f1=15,f2="bill"; +INSERT into t1 set f1=16,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +delete from t1 where f2="bill"; +select * from t1; +drop table t1; + +# +# Test when using part key searches +# + +create table t1 (btn char(10) not null, key(btn)) engine=heap; +insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); +explain select * from t1 where btn like "q%"; +select * from t1 where btn like "q%"; +alter table t1 add column new_col char(1) not null, add key (btn,new_col), drop key btn; +update t1 set new_col=left(btn,1); +explain select * from t1 where btn="a"; +explain select * from t1 where btn="a" and new_col="a"; +drop table t1; + +# +# Test of NULL keys +# + +CREATE TABLE t1 ( + a int default NULL, + b int default NULL, + KEY a (a), + UNIQUE b (b) +) engine=heap; +INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3); +SELECT * FROM t1 WHERE a=NULL; +explain SELECT * FROM t1 WHERE a IS NULL; +SELECT * FROM t1 WHERE a<=>NULL; +SELECT * FROM t1 WHERE b=NULL; +explain SELECT * FROM t1 WHERE b IS NULL; +SELECT * FROM t1 WHERE b<=>NULL; + +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES (1,3); +DROP TABLE t1; + +CREATE TABLE t1 ( + a int default NULL, + key a (a) +) ENGINE=HEAP; +INSERT INTO t1 VALUES (10), (10), (10); +EXPLAIN SELECT * FROM t1 WHERE a=10; +SELECT * FROM t1 WHERE a=10; +DROP TABLE t1; + +# +# Test when deleting all rows +# + +CREATE TABLE t1 (a int not null, primary key(a)) engine=heap; +INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11); +DELETE from t1 where a < 100; +SELECT * from t1; +DROP TABLE t1; + +# +# Bug#4411 Server hangs when trying to SELECT MAX(id) from an empty HEAP table +# +CREATE TABLE `job_titles` ( + `job_title_id` int(6) unsigned NOT NULL default '0', + `job_title` char(18) NOT NULL default '', + PRIMARY KEY (`job_title_id`), + UNIQUE KEY `job_title_id` (`job_title_id`,`job_title`) +) ENGINE=HEAP; + +SELECT MAX(job_title_id) FROM job_titles; + +DROP TABLE job_titles; + +# +# Test of delete with NOT NULL +# (Bug #6082) +# + +CREATE TABLE t1 (a INT NOT NULL, B INT, KEY(B)) ENGINE=HEAP; +INSERT INTO t1 VALUES(1,1), (1,NULL); +SELECT * FROM t1 WHERE B is not null; +DROP TABLE t1; + +# +# Bug #6748 +# heap_rfirst() doesn't work (and never did!) +# +CREATE TABLE t1 (pseudo char(35) PRIMARY KEY, date int(10) unsigned NOT NULL) ENGINE=HEAP; +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); +DELETE FROM t1 WHERE date<1101106546; +SELECT * FROM t1; +DROP TABLE t1; + +# +# Bug #6878: a problem with small length records +# + +create table t1(a char(2)) engine=memory; +insert into t1 values (NULL), (NULL); +delete from t1 where a is null; +insert into t1 values ('2'), ('3'); +select * from t1; +drop table t1; + +# +# Test varchar +# We can't use varchar.inc becasue heap doesn't support blob's +# + +let $default=`select @@storage_engine`; +set storage_engine=HEAP; + +# +# Simple basic test that endspace is saved +# + +create table t1 (v varchar(10), c char(10), t varchar(50)); +insert into t1 values('+ ', '+ ', '+ '); +set @a=repeat(' ',20); +insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a)); +select concat('*',v,'*',c,'*',t,'*') from t1; + +# Check how columns are copied +show create table t1; +create table t2 like t1; +show create table t2; +create table t3 select * from t1; +show create table t3; +alter table t1 modify c varchar(10); +show create table t1; +alter table t1 modify v char(10); +show create table t1; +alter table t1 modify t varchar(10); +show create table t1; +select concat('*',v,'*',c,'*',t,'*') from t1; +drop table t1,t2,t3; + +# +# Testing of keys +# +create table t1 (v varchar(10), c char(10), t varchar(50), key(v), key(c), key(t(10))); +show create table t1; +--disable_query_log +begin; +let $1=10; +while ($1) +{ + let $2=27; + eval set @space=repeat(' ',10-$1); + while ($2) + { + eval set @char=char(ascii('a')+$2-1); + insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space)); + dec $2; + } + dec $1; +} +commit; +--enable_query_log + +select count(*) from t1; +insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1))); +select count(*) from t1 where v='a'; +select count(*) from t1 where c='a'; +select count(*) from t1 where t='a'; +select count(*) from t1 where v='a '; +select count(*) from t1 where c='a '; +select count(*) from t1 where t='a '; +select count(*) from t1 where v between 'a' and 'a '; +select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; +select count(*) from t1 where v like 'a%'; +select count(*) from t1 where c like 'a%'; +select count(*) from t1 where t like 'a%'; +select count(*) from t1 where v like 'a %'; +explain select count(*) from t1 where v='a '; +explain select count(*) from t1 where c='a '; +explain select count(*) from t1 where t='a '; +explain select count(*) from t1 where v like 'a%'; +explain select count(*) from t1 where v between 'a' and 'a '; +explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; + +--error ER_DUP_ENTRY +alter table t1 add unique(v); +select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*')); +explain select * from t1 where v='a'; + +# GROUP BY + +select v,count(*) from t1 group by v limit 10; +select v,count(t) from t1 group by v limit 10; +select v,count(c) from t1 group by v limit 10; +select sql_big_result trim(v),count(t) from t1 group by v limit 10; +select sql_big_result trim(v),count(c) from t1 group by v limit 10; +select c,count(*) from t1 group by c limit 10; +select c,count(t) from t1 group by c limit 10; +select sql_big_result c,count(t) from t1 group by c limit 10; +select t,count(*) from t1 group by t limit 10; +select t,count(t) from t1 group by t limit 10; +select sql_big_result trim(t),count(t) from t1 group by t limit 10; +drop table t1; + +# +# Test unique keys +# + +create table t1 (a char(10), unique (a)); +insert into t1 values ('a'); +--error ER_DUP_ENTRY +insert into t1 values ('a '); + +alter table t1 modify a varchar(10); +--error ER_DUP_ENTRY +insert into t1 values ('a '),('a '),('a '),('a '); +--error ER_DUP_ENTRY +insert into t1 values ('a '); +--error ER_DUP_ENTRY +insert into t1 values ('a '); +--error ER_DUP_ENTRY +insert into t1 values ('a '); +update t1 set a='a ' where a like 'a '; +update t1 set a='a ' where a like 'a '; +drop table t1; + +# +# Testing of btree keys +# + +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))); +show create table t1; +--disable_query_log +begin; +let $1=10; +while ($1) +{ + let $2=27; + eval set @space=repeat(' ',10-$1); + while ($2) + { + eval set @char=char(ascii('a')+$2-1); + insert into t1 values(concat(@char,@space),concat(@char,@space),concat(@char,@space)); + dec $2; + } + dec $1; +} +commit; +--enable_query_log +select count(*) from t1; +insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1))); +select count(*) from t1 where v='a'; +select count(*) from t1 where c='a'; +select count(*) from t1 where t='a'; +select count(*) from t1 where v='a '; +select count(*) from t1 where c='a '; +select count(*) from t1 where t='a '; +select count(*) from t1 where v between 'a' and 'a '; +--replace_column 9 # +select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; +--replace_column 9 # +explain select count(*) from t1 where v='a '; +--replace_column 9 # +explain select count(*) from t1 where c='a '; +--replace_column 9 # +explain select count(*) from t1 where t='a '; +--replace_column 9 # +explain select count(*) from t1 where v like 'a%'; +--replace_column 9 # +explain select count(*) from t1 where v between 'a' and 'a '; +--replace_column 9 # +explain select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; + +--error ER_DUP_ENTRY +alter table t1 add unique(v); +select concat('*',v,'*',c,'*',t,'*') as qq from t1 where v='a' order by length(concat('*',v,'*',c,'*',t,'*')); +# Number of rows is not constant for b-trees keys +--replace_column 9 # +explain select * from t1 where v='a'; + +drop table t1; + +# +# Test unique btree keys +# + +create table t1 (a char(10), unique using btree (a)) engine=heap; +insert into t1 values ('a'); +--error ER_DUP_ENTRY +insert into t1 values ('a '); + +alter table t1 modify a varchar(10); +--error ER_DUP_ENTRY +insert into t1 values ('a '),('a '),('a '),('a '); +--error ER_DUP_ENTRY +insert into t1 values ('a '); +--error ER_DUP_ENTRY +insert into t1 values ('a '); +--error ER_DUP_ENTRY +insert into t1 values ('a '); +update t1 set a='a ' where a like 'a '; +update t1 set a='a ' where a like 'a '; +drop table t1; + +# +# test show create table +# + +create table t1 (v varchar(10), c char(10), t varchar(50), key(v(5)), key(c(5)), key(t(5))); +show create table t1; +drop table t1; + +create table t1 (v varchar(65530), key(v(10))); +show create table t1; +insert into t1 values(repeat('a',65530)); +select length(v) from t1 where v=repeat('a',65530); +drop table t1; + +# +# Reset varchar test +# +eval set storage_engine=$default; + +# +# Bug #8489: Strange auto_increment behaviour +# + +create table t1 (a bigint unsigned auto_increment primary key, b int, + key (b, a)) engine=heap; +insert t1 (b) values (1),(1),(1),(1),(1),(1),(1),(1); +select * from t1; +drop table t1; + +create table t1 (a int not null, b int not null auto_increment, + primary key(a, b), key(b)) engine=heap; +insert t1 (a) values (1),(1),(1),(1),(1),(1),(1),(1); +select * from t1; +drop table t1; + +--error 1075 +create table t1 (a int not null, b int not null auto_increment, + primary key(a, b)) engine=heap; + +# +# Bug #10566: Verify that we can create a prefixed key with length > 255 +# +create table t1 (c char(255), primary key(c(90))); +insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); +--error ER_DUP_ENTRY +insert into t1 values ("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"); +drop table t1; + +# +# Bug 12796: Record doesn't show when selecting through index +# +CREATE TABLE t1 (a int, key(a)) engine=heap; +insert into t1 values (0); +delete from t1; +select * from t1; +insert into t1 values (0), (1); +select * from t1 where a = 0; +drop table t1; + +# End of 4.1 tests + +# +# Bug #3094: Row format of memory tables should always be reported as Fixed +# +create table t1 (c char(10)) engine=memory; +create table t2 (c varchar(10)) engine=memory; +--replace_column 8 # 12 # +show table status like 't_'; +drop table t1, t2; + +# +# BUG#18233 - Memory tables INDEX USING HASH (a,b) returns 1 row on +# SELECT WHERE a= AND b= +# +CREATE TABLE t1(a VARCHAR(1), b VARCHAR(2), c VARCHAR(256), + KEY(a), KEY(b), KEY(c)) ENGINE=MEMORY; +INSERT INTO t1 VALUES('a','aa',REPEAT('a', 256)),('a','aa',REPEAT('a',256)); +SELECT COUNT(*) FROM t1 WHERE a='a'; +SELECT COUNT(*) FROM t1 WHERE b='aa'; +SELECT COUNT(*) FROM t1 WHERE c=REPEAT('a',256); +DROP TABLE t1; + +# End of 5.0 tests + +# +# BUG#26080 - Memory Storage engine not working properly +# +CREATE TABLE t1(c1 VARCHAR(100), c2 INT) ENGINE=MEMORY; +INSERT INTO t1 VALUES('', 0); +ALTER TABLE t1 MODIFY c1 VARCHAR(101); +SELECT c2 FROM t1; +DROP TABLE t1; diff --git a/mysql-test/suite/heap/heap_auto_increment.result b/mysql-test/suite/heap/heap_auto_increment.result new file mode 100644 index 00000000000..5b04a77e9eb --- /dev/null +++ b/mysql-test/suite/heap/heap_auto_increment.result @@ -0,0 +1,41 @@ +drop table if exists t1; +create table t1 (a int not null auto_increment,b int, primary key (a)) engine=heap auto_increment=3; +insert into t1 values (1,1),(NULL,3),(NULL,4); +delete from t1 where a=4; +insert into t1 values (NULL,5),(NULL,6); +select * from t1; +a b +1 1 +3 3 +5 5 +6 6 +delete from t1 where a=6; +replace t1 values (3,1); +ALTER TABLE t1 add c int; +replace t1 values (3,3,3); +insert into t1 values (NULL,7,7); +update t1 set a=8,b=b+1,c=c+1 where a=7; +insert into t1 values (NULL,9,9); +select * from t1; +a b c +1 1 NULL +3 3 3 +5 5 NULL +8 8 8 +9 9 9 +drop table t1; +create table t1 ( +skey tinyint unsigned NOT NULL auto_increment PRIMARY KEY, +sval char(20) +) engine=heap; +insert into t1 values (NULL, "hello"); +insert into t1 values (NULL, "hey"); +select * from t1; +skey sval +1 hello +2 hey +select _rowid,t1._rowid,skey,sval from t1; +_rowid _rowid skey sval +1 1 1 hello +2 2 2 hey +drop table t1; diff --git a/mysql-test/suite/heap/heap_auto_increment.test b/mysql-test/suite/heap/heap_auto_increment.test new file mode 100644 index 00000000000..016bc946209 --- /dev/null +++ b/mysql-test/suite/heap/heap_auto_increment.test @@ -0,0 +1,35 @@ +# +# Test of auto_increment; The test for BDB tables is in bdb.test +# + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 (a int not null auto_increment,b int, primary key (a)) engine=heap auto_increment=3; +insert into t1 values (1,1),(NULL,3),(NULL,4); +delete from t1 where a=4; +insert into t1 values (NULL,5),(NULL,6); +select * from t1; +delete from t1 where a=6; +#show table status like "t1"; +replace t1 values (3,1); +ALTER TABLE t1 add c int; +replace t1 values (3,3,3); +insert into t1 values (NULL,7,7); +update t1 set a=8,b=b+1,c=c+1 where a=7; +insert into t1 values (NULL,9,9); +select * from t1; +drop table t1; + +create table t1 ( + skey tinyint unsigned NOT NULL auto_increment PRIMARY KEY, + sval char(20) +) engine=heap; +insert into t1 values (NULL, "hello"); +insert into t1 values (NULL, "hey"); +select * from t1; +select _rowid,t1._rowid,skey,sval from t1; +drop table t1; + +# End of 4.1 tests diff --git a/mysql-test/suite/heap/heap_btree.result b/mysql-test/suite/heap/heap_btree.result new file mode 100644 index 00000000000..12a011778c6 --- /dev/null +++ b/mysql-test/suite/heap/heap_btree.result @@ -0,0 +1,381 @@ +drop table if exists t1; +create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps" avg_row_length=100 min_rows=1 max_rows=100; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a=1 or a=0; +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 a A NULL NULL NULL BTREE +select * from t1; +a b +2 2 +3 3 +4 4 +select * from t1 where a=4; +a b +4 4 +update t1 set b=5 where a=4; +update t1 set b=b+1 where a>=3; +replace t1 values (3,3); +select * from t1; +a b +2 2 +3 3 +4 6 +alter table t1 add c int not null, add key using BTREE (c,a); +drop table t1; +create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps"; +insert into t1 values(-2,-2),(-1,-1),(0,0),(1,1),(2,2),(3,3),(4,4); +delete from t1 where a > -3; +select * from t1; +a b +drop table t1; +create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table"; +select * from t1; +a b +1 1 +2 2 +3 3 +4 4 +drop table t1; +create table t1 (a int not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +select * from t1 where a > 736494; +a +869751 +802616 +alter table t1 add unique uniq_id using BTREE (a); +select * from t1 where a > 736494; +a +802616 +869751 +select * from t1 where a = 736494; +a +736494 +select * from t1 where a=869751 or a=736494; +a +736494 +869751 +select * from t1 where a in (869751,736494,226312,802616); +a +226312 +736494 +802616 +869751 +alter table t1 engine=myisam; +explain select * from t1 where a in (869751,736494,226312,802616); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range uniq_id uniq_id 4 NULL 4 Using where; Using index +drop table t1; +create table t1 (x int not null, y int not null, key x using BTREE (x,y), unique y using BTREE (y)) +engine=heap; +insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6); +explain select * from t1 where x=1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref x x 4 const 1 +select * from t1 where x=1; +x y +1 1 +1 3 +select * from t1,t1 as t2 where t1.x=t2.y; +x y x y +1 1 1 1 +2 2 2 2 +1 3 1 1 +2 4 2 2 +2 5 2 2 +2 6 2 2 +explain select * from t1,t1 as t2 where t1.x=t2.y; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL x NULL NULL NULL 6 +1 SIMPLE t2 eq_ref y y 4 test.t1.x 1 +drop table t1; +create table t1 (a int) engine=heap; +insert into t1 values(1); +select max(a) from t1; +max(a) +1 +drop table t1; +CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key using BTREE (a,b), key using BTREE (b) ) ENGINE=HEAP; +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +a b +1 1 +1 2 +1 3 +1 4 +1 5 +1 6 +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +a b +1 1 +1 1 +1 2 +1 2 +1 3 +1 3 +1 4 +1 4 +1 5 +1 5 +1 6 +1 6 +explain select * from tx where a=x order by a,b; +id select_type table type possible_keys key key_len ref rows Extra +x SIMPLE tx ref a a x const x Using where +explain select * from tx where a=x order by b; +id select_type table type possible_keys key key_len ref rows Extra +x SIMPLE tx ref a a x const x Using where +select * from t1 where b=1; +a b +1 1 +1 1 +explain select * from tx where b=x; +id select_type table type possible_keys key key_len ref rows Extra +x SIMPLE tx ref b b x const x +drop table t1; +create table t1 (id int unsigned not null, primary key using BTREE (id)) engine=HEAP; +insert into t1 values(1); +select max(id) from t1; +max(id) +1 +insert into t1 values(2); +select max(id) from t1; +max(id) +2 +replace into t1 values(1); +drop table t1; +create table t1 (n int) engine=heap; +drop table t1; +create table t1 (n int) engine=heap; +drop table if exists t1; +CREATE table t1(f1 int not null,f2 char(20) not +null,index(f2)) engine=heap; +INSERT into t1 set f1=12,f2="bill"; +INSERT into t1 set f1=13,f2="bill"; +INSERT into t1 set f1=14,f2="bill"; +INSERT into t1 set f1=15,f2="bill"; +INSERT into t1 set f1=16,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +delete from t1 where f2="bill"; +select * from t1; +f1 f2 +16 ted +12 ted +12 ted +12 ted +12 ted +drop table t1; +create table t1 (btn char(10) not null, key using BTREE (btn)) engine=heap; +insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); +explain select * from t1 where btn like "i%"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range btn btn 10 NULL 1 Using where +explain select * from t1 where btn like "h%"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range btn btn 10 NULL # Using where +explain select * from t1 where btn like "a%"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range btn btn 10 NULL 1 Using where +explain select * from t1 where btn like "b%"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range btn btn 10 NULL 1 Using where +select * from t1 where btn like "ff%"; +btn +select * from t1 where btn like " %"; +btn +select * from t1 where btn like "q%"; +btn +alter table t1 add column new_col char(1) not null, add key using BTREE (btn,new_col), drop key btn; +update t1 set new_col=left(btn,1); +explain select * from t1 where btn="a"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref btn btn 10 const 1 Using where +explain select * from t1 where btn="a" and new_col="a"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref btn btn 11 const,const 1 Using where +drop table t1; +CREATE TABLE t1 ( +a int default NULL, +b int default NULL, +KEY a using BTREE (a), +UNIQUE b using BTREE (b) +) engine=heap; +INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3); +SELECT * FROM t1 WHERE a=NULL; +a b +explain SELECT * FROM t1 WHERE a IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 5 const 1 Using where +SELECT * FROM t1 WHERE a<=>NULL; +a b +NULL 99 +SELECT * FROM t1 WHERE b=NULL; +a b +explain SELECT * FROM t1 WHERE b IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref b b 5 const 1 Using where +SELECT * FROM t1 WHERE b<=>NULL; +a b +99 NULL +INSERT INTO t1 VALUES (1,3); +ERROR 23000: Duplicate entry '3' for key 'b' +DROP TABLE t1; +CREATE TABLE t1 (a int, b int, c int, key using BTREE (a, b, c)) engine=heap; +INSERT INTO t1 VALUES (1, NULL, NULL), (1, 1, NULL), (1, NULL, 1); +SELECT * FROM t1 WHERE a=1 and b IS NULL; +a b c +1 NULL NULL +1 NULL 1 +SELECT * FROM t1 WHERE a=1 and c IS NULL; +a b c +1 NULL NULL +1 1 NULL +SELECT * FROM t1 WHERE a=1 and b IS NULL and c IS NULL; +a b c +1 NULL NULL +DROP TABLE t1; +CREATE TABLE t1 (a int not null, primary key using BTREE (a)) engine=heap; +INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11); +DELETE from t1 where a < 100; +SELECT * from t1; +a +DROP TABLE t1; +create table t1(a int not null, key using btree(a)) engine=heap; +insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3); +select a from t1 where a > 2 order by a; +a +3 +3 +3 +3 +delete from t1 where a < 4; +select a from t1 order by a; +a +insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3); +select a from t1 where a > 4 order by a; +a +delete from t1 where a > 4; +select a from t1 order by a; +a +1 +1 +2 +2 +2 +3 +3 +3 +3 +select a from t1 where a > 3 order by a; +a +delete from t1 where a >= 2; +select a from t1 order by a; +a +1 +1 +drop table t1; +CREATE TABLE t1 ( +c1 CHAR(3), +c2 INTEGER, +KEY USING BTREE(c1), +KEY USING BTREE(c2) +) ENGINE= MEMORY; +INSERT INTO t1 VALUES ('ABC',0), ('A',0), ('B',0), ('C',0); +UPDATE t1 SET c2= c2 + 1 WHERE c1 = 'A'; +SELECT * FROM t1; +c1 c2 +ABC 0 +A 1 +B 0 +C 0 +DROP TABLE t1; +CREATE TABLE t1 ( +c1 ENUM('1', '2'), +UNIQUE USING BTREE(c1) +) ENGINE= MEMORY DEFAULT CHARSET= utf8; +INSERT INTO t1 VALUES('1'), ('2'); +DROP TABLE t1; +CREATE TABLE t1 ( +c1 SET('1', '2'), +UNIQUE USING BTREE(c1) +) ENGINE= MEMORY DEFAULT CHARSET= utf8; +INSERT INTO t1 VALUES('1'), ('2'); +DROP TABLE t1; +CREATE TABLE t1 (a INT, KEY USING BTREE(a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES(1),(2),(2); +DELETE FROM t1 WHERE a=2; +SELECT * FROM t1; +a +1 +DROP TABLE t1; +End of 4.1 tests +CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory; +INSERT INTO t1 VALUES(0); +SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1'; +INDEX_LENGTH +21 +UPDATE t1 SET val=1; +SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1'; +INDEX_LENGTH +21 +DROP TABLE t1; +CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES(NULL),(NULL); +DROP TABLE t1; +create table t1(a varchar(255), b varchar(255), +key using btree (a,b)) engine=memory; +insert into t1 values (1, 1), (3, 3), (2, 2), (NULL, 1), (NULL, NULL), (0, 0); +select * from t1 where a is null; +a b +NULL NULL +NULL 1 +drop table t1; +# +# bug#39918 - memory (heap) engine crashing while executing self join with delete +# +CREATE TABLE t1(a INT, KEY USING BTREE (a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES(1),(1); +DELETE a1 FROM t1 AS a1, t1 AS a2 WHERE a1.a=a2.a; +DROP TABLE t1; +End of 5.0 tests +# bit index in heap tables +create table t1 (a bit(63) not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +alter table t1 add unique uniq_id using BTREE (a); +select 0+a from t1 where a > 736494; +0+a +802616 +869751 +explain select 0+a from t1 where a > 736494; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range uniq_id uniq_id 8 NULL 3 Using where +select 0+a from t1 where a = 736494; +0+a +736494 +explain select 0+a from t1 where a = 736494; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const uniq_id uniq_id 8 const 1 +select 0+a from t1 where a=869751 or a=736494; +0+a +736494 +869751 +explain select 0+a from t1 where a=869751 or a=736494; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range uniq_id uniq_id 8 NULL 2 Using where +select 0+a from t1 where a in (869751,736494,226312,802616); +0+a +226312 +736494 +802616 +869751 +explain select 0+a from t1 where a in (869751,736494,226312,802616); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range uniq_id uniq_id 8 NULL 4 Using where +drop table t1; +End of 5.3 tests diff --git a/mysql-test/suite/heap/heap_btree.test b/mysql-test/suite/heap/heap_btree.test new file mode 100644 index 00000000000..02c09f52263 --- /dev/null +++ b/mysql-test/suite/heap/heap_btree.test @@ -0,0 +1,281 @@ +# +# Test of heap tables. +# + +--disable_warnings +drop table if exists t1; +--enable_warnings + +create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps" avg_row_length=100 min_rows=1 max_rows=100; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a=1 or a=0; +#show table status like "t1"; +show keys from t1; +select * from t1; +select * from t1 where a=4; +update t1 set b=5 where a=4; +update t1 set b=b+1 where a>=3; +replace t1 values (3,3); +select * from t1; +alter table t1 add c int not null, add key using BTREE (c,a); +drop table t1; + +create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps"; +insert into t1 values(-2,-2),(-1,-1),(0,0),(1,1),(2,2),(3,3),(4,4); +delete from t1 where a > -3; +select * from t1; +drop table t1; + +create table t1 (a int not null,b int not null, primary key using BTREE (a)) engine=heap comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table"; +#show table status like "t1"; +select * from t1; +drop table t1; + +create table t1 (a int not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +select * from t1 where a > 736494; +alter table t1 add unique uniq_id using BTREE (a); +select * from t1 where a > 736494; +select * from t1 where a = 736494; +select * from t1 where a=869751 or a=736494; +select * from t1 where a in (869751,736494,226312,802616); +alter table t1 engine=myisam; +explain select * from t1 where a in (869751,736494,226312,802616); +drop table t1; + +create table t1 (x int not null, y int not null, key x using BTREE (x,y), unique y using BTREE (y)) +engine=heap; +insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6); +explain select * from t1 where x=1; +select * from t1 where x=1; +select * from t1,t1 as t2 where t1.x=t2.y; +explain select * from t1,t1 as t2 where t1.x=t2.y; +drop table t1; + +create table t1 (a int) engine=heap; +insert into t1 values(1); +select max(a) from t1; +drop table t1; + +CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key using BTREE (a,b), key using BTREE (b) ) ENGINE=HEAP; +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +--replace_result 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 x 13 x 14 x +explain select * from t1 where a=1 order by a,b; +--replace_result 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 x 13 x 14 x +explain select * from t1 where a=1 order by b; +select * from t1 where b=1; +--replace_result 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 x 13 x 14 x +explain select * from t1 where b=1; +drop table t1; + +create table t1 (id int unsigned not null, primary key using BTREE (id)) engine=HEAP; +insert into t1 values(1); +select max(id) from t1; +insert into t1 values(2); +select max(id) from t1; +replace into t1 values(1); +drop table t1; + +create table t1 (n int) engine=heap; +drop table t1; + +create table t1 (n int) engine=heap; +drop table if exists t1; + +# Test of non unique index + +CREATE table t1(f1 int not null,f2 char(20) not +null,index(f2)) engine=heap; +INSERT into t1 set f1=12,f2="bill"; +INSERT into t1 set f1=13,f2="bill"; +INSERT into t1 set f1=14,f2="bill"; +INSERT into t1 set f1=15,f2="bill"; +INSERT into t1 set f1=16,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +delete from t1 where f2="bill"; +select * from t1; +drop table t1; + +# +# Test when using part key searches +# + +create table t1 (btn char(10) not null, key using BTREE (btn)) engine=heap; +insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); +explain select * from t1 where btn like "i%"; +--replace_column 9 # +explain select * from t1 where btn like "h%"; +explain select * from t1 where btn like "a%"; +explain select * from t1 where btn like "b%"; +# For the following the BTREE MAY notice that there is no possible matches +select * from t1 where btn like "ff%"; +select * from t1 where btn like " %"; +select * from t1 where btn like "q%"; +alter table t1 add column new_col char(1) not null, add key using BTREE (btn,new_col), drop key btn; +update t1 set new_col=left(btn,1); +explain select * from t1 where btn="a"; +explain select * from t1 where btn="a" and new_col="a"; +drop table t1; + +# +# Test of NULL keys +# + +CREATE TABLE t1 ( + a int default NULL, + b int default NULL, + KEY a using BTREE (a), + UNIQUE b using BTREE (b) +) engine=heap; +INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3); +SELECT * FROM t1 WHERE a=NULL; +explain SELECT * FROM t1 WHERE a IS NULL; +SELECT * FROM t1 WHERE a<=>NULL; +SELECT * FROM t1 WHERE b=NULL; +explain SELECT * FROM t1 WHERE b IS NULL; +SELECT * FROM t1 WHERE b<=>NULL; + +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES (1,3); +DROP TABLE t1; + +CREATE TABLE t1 (a int, b int, c int, key using BTREE (a, b, c)) engine=heap; +INSERT INTO t1 VALUES (1, NULL, NULL), (1, 1, NULL), (1, NULL, 1); +SELECT * FROM t1 WHERE a=1 and b IS NULL; +SELECT * FROM t1 WHERE a=1 and c IS NULL; +SELECT * FROM t1 WHERE a=1 and b IS NULL and c IS NULL; +DROP TABLE t1; + +# +# Test when deleting all rows +# + +CREATE TABLE t1 (a int not null, primary key using BTREE (a)) engine=heap; +INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11); +DELETE from t1 where a < 100; +SELECT * from t1; +DROP TABLE t1; + +# +# Bug #9719: problem with delete +# + +create table t1(a int not null, key using btree(a)) engine=heap; +insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3); +select a from t1 where a > 2 order by a; +delete from t1 where a < 4; +select a from t1 order by a; +insert into t1 values (2), (2), (2), (1), (1), (3), (3), (3), (3); +select a from t1 where a > 4 order by a; +delete from t1 where a > 4; +select a from t1 order by a; +select a from t1 where a > 3 order by a; +delete from t1 where a >= 2; +select a from t1 order by a; +drop table t1; + +# +# Bug#26996 - Update of a Field in a Memory Table ends with wrong result +# +CREATE TABLE t1 ( + c1 CHAR(3), + c2 INTEGER, + KEY USING BTREE(c1), + KEY USING BTREE(c2) +) ENGINE= MEMORY; +INSERT INTO t1 VALUES ('ABC',0), ('A',0), ('B',0), ('C',0); +UPDATE t1 SET c2= c2 + 1 WHERE c1 = 'A'; +SELECT * FROM t1; +DROP TABLE t1; + +# +# Bug#24985 - UTF8 ENUM primary key on MEMORY using BTREE +# causes incorrect duplicate entries +# +CREATE TABLE t1 ( + c1 ENUM('1', '2'), + UNIQUE USING BTREE(c1) +) ENGINE= MEMORY DEFAULT CHARSET= utf8; +INSERT INTO t1 VALUES('1'), ('2'); +DROP TABLE t1; +CREATE TABLE t1 ( + c1 SET('1', '2'), + UNIQUE USING BTREE(c1) +) ENGINE= MEMORY DEFAULT CHARSET= utf8; +INSERT INTO t1 VALUES('1'), ('2'); +DROP TABLE t1; + +# +# BUG#30590 - delete from memory table with composite btree primary key +# +CREATE TABLE t1 (a INT, KEY USING BTREE(a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES(1),(2),(2); +DELETE FROM t1 WHERE a=2; +SELECT * FROM t1; +DROP TABLE t1; + +--echo End of 4.1 tests + +# +# BUG#18160 - Memory-/HEAP Table endless growing indexes +# +CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory; +INSERT INTO t1 VALUES(0); +--replace_result 37 21 +SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1'; +UPDATE t1 SET val=1; +--replace_result 37 21 +SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1'; +DROP TABLE t1; + +# +# BUG#12873 - BTREE index on MEMORY table with multiple NULL values doesn't +# work properly +# +CREATE TABLE t1 (a INT, UNIQUE USING BTREE(a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES(NULL),(NULL); +DROP TABLE t1; + +# +# Bug #30885: MEMORY returns incorrect data if BTREE index is used for NULL lookup +# +create table t1(a varchar(255), b varchar(255), + key using btree (a,b)) engine=memory; +insert into t1 values (1, 1), (3, 3), (2, 2), (NULL, 1), (NULL, NULL), (0, 0); +select * from t1 where a is null; +drop table t1; + +-- echo # +-- echo # bug#39918 - memory (heap) engine crashing while executing self join with delete +-- echo # + +CREATE TABLE t1(a INT, KEY USING BTREE (a)) ENGINE=MEMORY; +INSERT INTO t1 VALUES(1),(1); +DELETE a1 FROM t1 AS a1, t1 AS a2 WHERE a1.a=a2.a; +DROP TABLE t1; +--echo End of 5.0 tests + +-- echo # bit index in heap tables + +create table t1 (a bit(63) not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +alter table t1 add unique uniq_id using BTREE (a); +select 0+a from t1 where a > 736494; +explain select 0+a from t1 where a > 736494; +select 0+a from t1 where a = 736494; +explain select 0+a from t1 where a = 736494; +select 0+a from t1 where a=869751 or a=736494; +explain select 0+a from t1 where a=869751 or a=736494; +select 0+a from t1 where a in (869751,736494,226312,802616); +explain select 0+a from t1 where a in (869751,736494,226312,802616); +drop table t1; + +--echo End of 5.3 tests diff --git a/mysql-test/suite/heap/heap_hash.result b/mysql-test/suite/heap/heap_hash.result new file mode 100644 index 00000000000..453bfc0c165 --- /dev/null +++ b/mysql-test/suite/heap/heap_hash.result @@ -0,0 +1,430 @@ +drop table if exists t1,t2; +create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps" avg_row_length=100 min_rows=1 max_rows=100; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a=1 or a=0; +show keys from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 a NULL 3 NULL NULL HASH +select * from t1; +a b +2 2 +3 3 +4 4 +select * from t1 where a=4; +a b +4 4 +update t1 set b=5 where a=4; +update t1 set b=b+1 where a>=3; +replace t1 values (3,3); +select * from t1; +a b +2 2 +3 3 +4 6 +alter table t1 add c int not null, add key using HASH (c,a); +drop table t1; +create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a > 0; +select * from t1; +a b +drop table t1; +create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table"; +select * from t1; +a b +1 1 +2 2 +3 3 +4 4 +drop table t1; +create table t1 (a int not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +select * from t1 where a > 736494; +a +869751 +802616 +alter table t1 add unique uniq_id using HASH (a); +select * from t1 where a > 736494; +a +869751 +802616 +select * from t1 where a = 736494; +a +736494 +select * from t1 where a=869751 or a=736494; +a +736494 +869751 +select * from t1 where a in (869751,736494,226312,802616); +a +226312 +736494 +802616 +869751 +alter table t1 engine=myisam; +explain select * from t1 where a in (869751,736494,226312,802616); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range uniq_id uniq_id 4 NULL 4 Using where; Using index +drop table t1; +create table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y)) +engine=heap; +insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6); +select * from t1 where x=1; +x y +1 3 +1 1 +select * from t1,t1 as t2 where t1.x=t2.y; +x y x y +1 1 1 1 +2 2 2 2 +1 3 1 1 +2 4 2 2 +2 5 2 2 +2 6 2 2 +explain select * from t1,t1 as t2 where t1.x=t2.y; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL x NULL NULL NULL 6 +1 SIMPLE t2 eq_ref y y 4 test.t1.x 1 +drop table t1; +create table t1 (a int) engine=heap; +insert into t1 values(1); +select max(a) from t1; +max(a) +1 +drop table t1; +CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key using HASH (a), key using HASH (b) ) ENGINE=HEAP; +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +a b +1 6 +1 5 +1 4 +1 3 +1 2 +1 1 +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +a b +1 6 +1 5 +1 4 +1 3 +1 2 +1 1 +1 6 +1 5 +1 4 +1 3 +1 2 +1 1 +drop table t1; +create table t1 (id int unsigned not null, primary key using HASH (id)) engine=HEAP; +insert into t1 values(1); +select max(id) from t1; +max(id) +1 +insert into t1 values(2); +select max(id) from t1; +max(id) +2 +replace into t1 values(1); +drop table t1; +create table t1 (n int) engine=heap; +drop table t1; +create table t1 (n int) engine=heap; +drop table if exists t1; +CREATE table t1(f1 int not null,f2 char(20) not +null,index(f2)) engine=heap; +INSERT into t1 set f1=12,f2="bill"; +INSERT into t1 set f1=13,f2="bill"; +INSERT into t1 set f1=14,f2="bill"; +INSERT into t1 set f1=15,f2="bill"; +INSERT into t1 set f1=16,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +delete from t1 where f2="bill"; +select * from t1; +f1 f2 +16 ted +12 ted +12 ted +12 ted +12 ted +drop table t1; +create table t1 (btn char(10) not null, key using HASH (btn)) engine=heap; +insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); +explain select * from t1 where btn like "q%"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where +select * from t1 where btn like "q%"; +btn +alter table t1 add column new_col char(1) not null, add key using HASH (btn,new_col), drop key btn; +update t1 set new_col=left(btn,1); +explain select * from t1 where btn="a"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL btn NULL NULL NULL 14 Using where +explain select * from t1 where btn="a" and new_col="a"; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref btn btn 11 const,const 2 Using where +drop table t1; +CREATE TABLE t1 ( +a int default NULL, +b int default NULL, +KEY a using HASH (a), +UNIQUE b using HASH (b) +) engine=heap; +INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3); +SELECT * FROM t1 WHERE a=NULL; +a b +explain SELECT * FROM t1 WHERE a IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 5 const 2 Using where +SELECT * FROM t1 WHERE a<=>NULL; +a b +NULL 99 +SELECT * FROM t1 WHERE b=NULL; +a b +explain SELECT * FROM t1 WHERE b IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref b b 5 const 1 Using where +SELECT * FROM t1 WHERE b<=>NULL; +a b +99 NULL +INSERT INTO t1 VALUES (1,3); +ERROR 23000: Duplicate entry '3' for key 'b' +DROP TABLE t1; +CREATE TABLE t1 (a int not null, primary key using HASH (a)) engine=heap; +INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11); +DELETE from t1 where a < 100; +SELECT * from t1; +a +DROP TABLE t1; +create table t1 +( +a char(8) not null, +b char(20) not null, +c int not null, +key (a) +) engine=heap; +insert into t1 values ('aaaa', 'prefill-hash=5',0); +insert into t1 values ('aaab', 'prefill-hash=0',0); +insert into t1 values ('aaac', 'prefill-hash=7',0); +insert into t1 values ('aaad', 'prefill-hash=2',0); +insert into t1 values ('aaae', 'prefill-hash=1',0); +insert into t1 values ('aaaf', 'prefill-hash=4',0); +insert into t1 values ('aaag', 'prefill-hash=3',0); +insert into t1 values ('aaah', 'prefill-hash=6',0); +explain select * from t1 where a='aaaa'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaab'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaac'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaad'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +insert into t1 select * from t1; +flush tables; +explain select * from t1 where a='aaaa'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaab'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaac'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaad'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +flush tables; +explain select * from t1 where a='aaaa'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaab'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaac'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaad'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +create table t2 as select * from t1; +delete from t1; +insert into t1 select * from t2; +explain select * from t1 where a='aaaa'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaab'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaac'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +explain select * from t1 where a='aaad'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 8 const 2 Using where +drop table t1, t2; +create table t1 ( +id int unsigned not null primary key auto_increment, +name varchar(20) not null, +index heap_idx(name), +index btree_idx using btree(name) +) engine=heap; +create table t2 ( +id int unsigned not null primary key auto_increment, +name varchar(20) not null, +index btree_idx using btree(name), +index heap_idx(name) +) engine=heap; +insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'), +('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'), +('Emily'), ('Mike'); +insert into t2 select * from t1; +explain select * from t1 where name='matt'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where +explain select * from t2 where name='matt'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where +explain select * from t1 where name='Lilu'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where +explain select * from t2 where name='Lilu'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where +explain select * from t1 where name='Phil'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where +explain select * from t2 where name='Phil'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where +explain select * from t1 where name='Lilu'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref heap_idx,btree_idx btree_idx 22 const 1 Using where +explain select * from t2 where name='Lilu'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 ref btree_idx,heap_idx btree_idx 22 const 1 Using where +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +flush tables; +select count(*) from t1 where name='Matt'; +count(*) +7 +explain select * from t1 ignore index (btree_idx) where name='matt'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref heap_idx heap_idx 22 const 7 Using where +show index from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH +t1 1 heap_idx 1 name NULL 13 NULL NULL HASH +t1 1 btree_idx 1 name A NULL NULL NULL BTREE +show index from t1; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH +t1 1 heap_idx 1 name NULL 13 NULL NULL HASH +t1 1 btree_idx 1 name A NULL NULL NULL BTREE +create table t3 +( +a varchar(20) not null, +b varchar(20) not null, +key (a,b) +) engine=heap; +insert into t3 select name, name from t1; +show index from t3; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t3 1 a 1 a NULL NULL NULL NULL HASH +t3 1 a 2 b NULL 13 NULL NULL HASH +show index from t3; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment +t3 1 a 1 a NULL NULL NULL NULL HASH +t3 1 a 2 b NULL 13 NULL NULL HASH +explain select * from t1 ignore key(btree_idx), t3 where t1.name='matt' and t3.a = concat('',t1.name) and t3.b=t1.name; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref heap_idx heap_idx 22 const 7 Using where +1 SIMPLE t3 ref a a 44 func,const 7 Using where +drop table t1, t2, t3; +create temporary table t1 ( a int, index (a) ) engine=memory; +insert into t1 values (1),(2),(3),(4),(5); +select a from t1 where a in (1,3); +a +1 +3 +explain select a from t1 where a in (1,3); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 5 NULL 4 Using where +drop table t1; +End of 4.1 tests +CREATE TABLE t1(col1 VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +col2 VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, +UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY; +INSERT INTO t1 VALUES('A', 'A'); +INSERT INTO t1 VALUES('A ', 'A '); +ERROR 23000: Duplicate entry 'A -A ' for key 'key1' +DROP TABLE t1; +CREATE TABLE t1(col1 VARCHAR(32) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL, +col2 VARCHAR(32) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL, +UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY; +INSERT INTO t1 VALUES('A', 'A'); +INSERT INTO t1 VALUES('A ', 'A '); +ERROR 23000: Duplicate entry 'A -A ' for key 'key1' +DROP TABLE t1; +End of 5.0 tests +# bit index in heap tables +create table t1 (a bit(63) not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +alter table t1 add unique uniq_id using HASH (a); +select 0+a from t1 where a > 736494; +0+a +869751 +802616 +explain select 0+a from t1 where a > 736494; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL uniq_id NULL NULL NULL 5 Using where +select 0+a from t1 where a = 736494; +0+a +736494 +explain select 0+a from t1 where a = 736494; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 const uniq_id uniq_id 8 const 1 +select 0+a from t1 where a=869751 or a=736494; +0+a +736494 +869751 +explain select 0+a from t1 where a=869751 or a=736494; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range uniq_id uniq_id 8 NULL 2 Using where +select 0+a from t1 where a in (869751,736494,226312,802616); +0+a +226312 +736494 +802616 +869751 +explain select 0+a from t1 where a in (869751,736494,226312,802616); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range uniq_id uniq_id 8 NULL 4 Using where +drop table t1; +End of 5.3 tests +# +# Bug #55472: Assertion failed in heap_rfirst function of hp_rfirst.c +# on DELETE statement +# +CREATE TABLE t1 (col_int_nokey INT, +col_int_key INT, +INDEX(col_int_key) USING HASH) ENGINE = HEAP; +INSERT INTO t1 (col_int_nokey, col_int_key) VALUES (3, 0), (4, 0), (3, 1); +DELETE FROM t1 WHERE col_int_nokey = 5 ORDER BY col_int_key LIMIT 2; +DROP TABLE t1; +End of 5.5 tests diff --git a/mysql-test/suite/heap/heap_hash.test b/mysql-test/suite/heap/heap_hash.test new file mode 100644 index 00000000000..80ae01e9547 --- /dev/null +++ b/mysql-test/suite/heap/heap_hash.test @@ -0,0 +1,319 @@ +# +# Test of heap tables. +# + +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + +create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps" avg_row_length=100 min_rows=1 max_rows=100; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a=1 or a=0; +#show table status like "t1"; +show keys from t1; +select * from t1; +select * from t1 where a=4; +update t1 set b=5 where a=4; +update t1 set b=b+1 where a>=3; +replace t1 values (3,3); +select * from t1; +alter table t1 add c int not null, add key using HASH (c,a); +drop table t1; + +create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +delete from t1 where a > 0; +select * from t1; +drop table t1; + +create table t1 (a int not null,b int not null, primary key using HASH (a)) engine=heap comment="testing heaps"; +insert into t1 values(1,1),(2,2),(3,3),(4,4); +alter table t1 modify a int not null auto_increment, engine=myisam, comment="new myisam table"; +#show table status like "t1"; +select * from t1; +drop table t1; + +create table t1 (a int not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +select * from t1 where a > 736494; +alter table t1 add unique uniq_id using HASH (a); +select * from t1 where a > 736494; +select * from t1 where a = 736494; +select * from t1 where a=869751 or a=736494; +select * from t1 where a in (869751,736494,226312,802616); +alter table t1 engine=myisam; +explain select * from t1 where a in (869751,736494,226312,802616); +drop table t1; + +create table t1 (x int not null, y int not null, key x using HASH (x), unique y using HASH (y)) +engine=heap; +insert into t1 values (1,1),(2,2),(1,3),(2,4),(2,5),(2,6); +select * from t1 where x=1; +select * from t1,t1 as t2 where t1.x=t2.y; +explain select * from t1,t1 as t2 where t1.x=t2.y; +drop table t1; + +create table t1 (a int) engine=heap; +insert into t1 values(1); +select max(a) from t1; +drop table t1; + +CREATE TABLE t1 ( a int not null default 0, b int not null default 0, key using HASH (a), key using HASH (b) ) ENGINE=HEAP; +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +insert into t1 values(1,1),(1,2),(2,3),(1,3),(1,4),(1,5),(1,6); +select * from t1 where a=1; +drop table t1; + +create table t1 (id int unsigned not null, primary key using HASH (id)) engine=HEAP; +insert into t1 values(1); +select max(id) from t1; +insert into t1 values(2); +select max(id) from t1; +replace into t1 values(1); +drop table t1; + +create table t1 (n int) engine=heap; +drop table t1; + +create table t1 (n int) engine=heap; +drop table if exists t1; + +# Test of non unique index + +CREATE table t1(f1 int not null,f2 char(20) not +null,index(f2)) engine=heap; +INSERT into t1 set f1=12,f2="bill"; +INSERT into t1 set f1=13,f2="bill"; +INSERT into t1 set f1=14,f2="bill"; +INSERT into t1 set f1=15,f2="bill"; +INSERT into t1 set f1=16,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +INSERT into t1 set f1=12,f2="ted"; +delete from t1 where f2="bill"; +select * from t1; +drop table t1; + +# +# Test when using part key searches +# + +create table t1 (btn char(10) not null, key using HASH (btn)) engine=heap; +insert into t1 values ("hello"),("hello"),("hello"),("hello"),("hello"),("a"),("b"),("c"),("d"),("e"),("f"),("g"),("h"),("i"); +explain select * from t1 where btn like "q%"; +select * from t1 where btn like "q%"; +alter table t1 add column new_col char(1) not null, add key using HASH (btn,new_col), drop key btn; +update t1 set new_col=left(btn,1); +explain select * from t1 where btn="a"; +explain select * from t1 where btn="a" and new_col="a"; +drop table t1; + +# +# Test of NULL keys +# + +CREATE TABLE t1 ( + a int default NULL, + b int default NULL, + KEY a using HASH (a), + UNIQUE b using HASH (b) +) engine=heap; +INSERT INTO t1 VALUES (NULL,99),(99,NULL),(1,1),(2,2),(1,3); +SELECT * FROM t1 WHERE a=NULL; +explain SELECT * FROM t1 WHERE a IS NULL; +SELECT * FROM t1 WHERE a<=>NULL; +SELECT * FROM t1 WHERE b=NULL; +explain SELECT * FROM t1 WHERE b IS NULL; +SELECT * FROM t1 WHERE b<=>NULL; + +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES (1,3); +DROP TABLE t1; + +# +# Test when deleting all rows +# + +CREATE TABLE t1 (a int not null, primary key using HASH (a)) engine=heap; +INSERT into t1 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11); +DELETE from t1 where a < 100; +SELECT * from t1; +DROP TABLE t1; + + +# +# Hash index # records estimate test +# +create table t1 +( + a char(8) not null, + b char(20) not null, + c int not null, + key (a) +) engine=heap; + +insert into t1 values ('aaaa', 'prefill-hash=5',0); +insert into t1 values ('aaab', 'prefill-hash=0',0); +insert into t1 values ('aaac', 'prefill-hash=7',0); +insert into t1 values ('aaad', 'prefill-hash=2',0); +insert into t1 values ('aaae', 'prefill-hash=1',0); +insert into t1 values ('aaaf', 'prefill-hash=4',0); +insert into t1 values ('aaag', 'prefill-hash=3',0); +insert into t1 values ('aaah', 'prefill-hash=6',0); + +explain select * from t1 where a='aaaa'; +explain select * from t1 where a='aaab'; +explain select * from t1 where a='aaac'; +explain select * from t1 where a='aaad'; +insert into t1 select * from t1; + +# avoid statistics differences between normal and ps-protocol tests +flush tables; +explain select * from t1 where a='aaaa'; +explain select * from t1 where a='aaab'; +explain select * from t1 where a='aaac'; +explain select * from t1 where a='aaad'; + +# a known effect: table reload causes statistics to be updated: +flush tables; +explain select * from t1 where a='aaaa'; +explain select * from t1 where a='aaab'; +explain select * from t1 where a='aaac'; +explain select * from t1 where a='aaad'; + +# Check if delete_all_rows() updates #hash_buckets +create table t2 as select * from t1; +delete from t1; +insert into t1 select * from t2; +explain select * from t1 where a='aaaa'; +explain select * from t1 where a='aaab'; +explain select * from t1 where a='aaac'; +explain select * from t1 where a='aaad'; +drop table t1, t2; + + +# Btree and hash index use costs. +create table t1 ( + id int unsigned not null primary key auto_increment, + name varchar(20) not null, + index heap_idx(name), + index btree_idx using btree(name) +) engine=heap; + +create table t2 ( + id int unsigned not null primary key auto_increment, + name varchar(20) not null, + index btree_idx using btree(name), + index heap_idx(name) +) engine=heap; + +insert into t1 (name) values ('Matt'), ('Lilu'), ('Corbin'), ('Carly'), + ('Suzy'), ('Hoppy'), ('Burrito'), ('Mimi'), ('Sherry'), ('Ben'), ('Phil'), + ('Emily'), ('Mike'); +insert into t2 select * from t1; +explain select * from t1 where name='matt'; +explain select * from t2 where name='matt'; + +explain select * from t1 where name='Lilu'; +explain select * from t2 where name='Lilu'; + +explain select * from t1 where name='Phil'; +explain select * from t2 where name='Phil'; + +explain select * from t1 where name='Lilu'; +explain select * from t2 where name='Lilu'; + +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +insert into t1 (name) select name from t2; +flush tables; +select count(*) from t1 where name='Matt'; +explain select * from t1 ignore index (btree_idx) where name='matt'; +show index from t1; + +show index from t1; + +create table t3 +( + a varchar(20) not null, + b varchar(20) not null, + key (a,b) +) engine=heap; +insert into t3 select name, name from t1; +show index from t3; +show index from t3; + +# test rec_per_key use for joins. +explain select * from t1 ignore key(btree_idx), t3 where t1.name='matt' and t3.a = concat('',t1.name) and t3.b=t1.name; + +drop table t1, t2, t3; + +# Fix for BUG#8371: wrong rec_per_key value for hash index on temporary table +create temporary table t1 ( a int, index (a) ) engine=memory; +insert into t1 values (1),(2),(3),(4),(5); +select a from t1 where a in (1,3); +explain select a from t1 where a in (1,3); +drop table t1; + +--echo End of 4.1 tests + +# +# Bug #27643: query failed : 1114 (The table '' is full) +# +# Check that HASH indexes disregard trailing spaces when comparing +# strings with binary collations + +CREATE TABLE t1(col1 VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + col2 VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, + UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY; +INSERT INTO t1 VALUES('A', 'A'); +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES('A ', 'A '); +DROP TABLE t1; +CREATE TABLE t1(col1 VARCHAR(32) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL, + col2 VARCHAR(32) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL, + UNIQUE KEY key1 USING HASH (col1, col2)) ENGINE=MEMORY; +INSERT INTO t1 VALUES('A', 'A'); +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES('A ', 'A '); +DROP TABLE t1; + +--echo End of 5.0 tests + +-- echo # bit index in heap tables + +create table t1 (a bit(63) not null) engine=heap; +insert into t1 values (869751),(736494),(226312),(802616),(728912); +alter table t1 add unique uniq_id using HASH (a); +select 0+a from t1 where a > 736494; +explain select 0+a from t1 where a > 736494; +select 0+a from t1 where a = 736494; +explain select 0+a from t1 where a = 736494; +select 0+a from t1 where a=869751 or a=736494; +explain select 0+a from t1 where a=869751 or a=736494; +select 0+a from t1 where a in (869751,736494,226312,802616); +explain select 0+a from t1 where a in (869751,736494,226312,802616); +drop table t1; + +--echo End of 5.3 tests + +--echo # +--echo # Bug #55472: Assertion failed in heap_rfirst function of hp_rfirst.c +--echo # on DELETE statement +--echo # + +CREATE TABLE t1 (col_int_nokey INT, + col_int_key INT, + INDEX(col_int_key) USING HASH) ENGINE = HEAP; +INSERT INTO t1 (col_int_nokey, col_int_key) VALUES (3, 0), (4, 0), (3, 1); + +DELETE FROM t1 WHERE col_int_nokey = 5 ORDER BY col_int_key LIMIT 2; + +DROP TABLE t1; + +--echo End of 5.5 tests |