diff options
Diffstat (limited to 'mysql-test/suite/heap')
-rw-r--r-- | mysql-test/suite/heap/btree_varchar_null.result | 6 | ||||
-rw-r--r-- | mysql-test/suite/heap/btree_varchar_null.test | 7 | ||||
-rw-r--r-- | mysql-test/suite/heap/drop.result | 3 | ||||
-rw-r--r-- | mysql-test/suite/heap/drop.test | 11 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap.result | 879 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap.test | 661 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_auto_increment.result | 190 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_auto_increment.test | 67 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_btree.result | 389 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_btree.test | 297 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_hash.result | 488 | ||||
-rw-r--r-- | mysql-test/suite/heap/heap_hash.test | 359 |
12 files changed, 3357 insertions, 0 deletions
diff --git a/mysql-test/suite/heap/btree_varchar_null.result b/mysql-test/suite/heap/btree_varchar_null.result new file mode 100644 index 00000000..9199cf6e --- /dev/null +++ b/mysql-test/suite/heap/btree_varchar_null.result @@ -0,0 +1,6 @@ +create table t1 (f1 varchar(128), f2 varchar(128), key (f2,f1) using btree) engine=memory; +insert into t1 values (null,'not'),('one',null),('two',null),('three',''); +select * from t1 where f1 = 'one' and f2 is null; +f1 f2 +one NULL +drop table t1; diff --git a/mysql-test/suite/heap/btree_varchar_null.test b/mysql-test/suite/heap/btree_varchar_null.test new file mode 100644 index 00000000..8e6625a2 --- /dev/null +++ b/mysql-test/suite/heap/btree_varchar_null.test @@ -0,0 +1,7 @@ +# +# MDEV-4813 Replication fails on updating a MEMORY table with an index using btree +# +create table t1 (f1 varchar(128), f2 varchar(128), key (f2,f1) using btree) engine=memory; +insert into t1 values (null,'not'),('one',null),('two',null),('three',''); +select * from t1 where f1 = 'one' and f2 is null; +drop table t1; diff --git a/mysql-test/suite/heap/drop.result b/mysql-test/suite/heap/drop.result new file mode 100644 index 00000000..cbc784fd --- /dev/null +++ b/mysql-test/suite/heap/drop.result @@ -0,0 +1,3 @@ +create table t1 (a int) engine=memory; +drop table t1; +drop table t2; diff --git a/mysql-test/suite/heap/drop.test b/mysql-test/suite/heap/drop.test new file mode 100644 index 00000000..ef61d440 --- /dev/null +++ b/mysql-test/suite/heap/drop.test @@ -0,0 +1,11 @@ +create table t1 (a int) engine=memory; +let $DATADIR= `select @@datadir`; +copy_file $DATADIR/test/t1.frm $DATADIR/test/t2.frm; +# +# drop a newly created MEMORY table +# +drop table t1; +# +# drop a MEMORY table after a server restart (frm only, nothing in memory) +# +drop table t2; diff --git a/mysql-test/suite/heap/heap.result b/mysql-test/suite/heap/heap.result new file mode 100644 index 00000000..bef3913d --- /dev/null +++ b/mysql-test/suite/heap/heap.result @@ -0,0 +1,879 @@ +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 Ignored +t1 0 PRIMARY 1 a NULL 3 NULL NULL HASH NO +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 default_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 COLLATE=latin1_swedish_ci +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 COLLATE=latin1_swedish_ci +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 COLLATE=latin1_swedish_ci +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 COLLATE=latin1_swedish_ci +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 COLLATE=latin1_swedish_ci +SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR +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 COLLATE=latin1_swedish_ci +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 COLLATE=latin1_swedish_ci +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 COLLATE=latin1_swedish_ci +select count(*) from t1; +count(*) +267 +insert into t1 values(concat('a',char(1)),concat('a',char(1)),concat('a',char(1))); +select count(*) from t1 where v='a'; +count(*) +7 +select count(*) from t1 where c='a'; +count(*) +7 +select count(*) from t1 where t='a'; +count(*) +7 +select count(*) from t1 where v='a '; +count(*) +7 +select count(*) from t1 where c='a '; +count(*) +7 +select count(*) from t1 where t='a '; +count(*) +7 +select count(*) from t1 where v between 'a' and 'a '; +count(*) +7 +select count(*) from t1 where v between 'a' and 'a ' and v between 'a ' and 'b\n'; +count(*) +7 +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 * +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 COLLATE=latin1_swedish_ci +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 COLLATE=latin1_swedish_ci +insert into t1 values(repeat('a',65530)); +select length(v) from t1 where v=repeat('a',65530); +length(v) +65530 +drop table t1; +set default_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 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi...' 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 Max_index_length Temporary +t1 MEMORY 10 Fixed 0 11 0 # 0 0 NULL # NULL NULL latin1_swedish_ci NULL 0 N +t2 MEMORY 10 Fixed 0 12 0 # 0 0 NULL # NULL NULL latin1_swedish_ci NULL 0 N +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; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +color enum('GREEN', 'WHITE') DEFAULT NULL, +ts int, +PRIMARY KEY (id), +KEY color (color) USING HASH +) ENGINE=MEMORY DEFAULT CHARSET=utf8; +INSERT INTO t1 VALUES("1","GREEN",1); +INSERT INTO t1 VALUES("2","GREEN",1); +INSERT INTO t1 VALUES("3","GREEN",1); +INSERT INTO t1 VALUES("4","GREEN",1); +INSERT INTO t1 VALUES("5","GREEN",1); +INSERT INTO t1 VALUES("6","GREEN",1); +DELETE FROM t1 WHERE id = 1; +INSERT INTO t1 VALUES("7","GREEN", 2); +DELETE FROM t1 WHERE ts = 1 AND color = 'GREEN'; +SELECT * from t1; +id color ts +7 GREEN 2 +DROP TABLE t1; +CREATE TABLE t1 (id INT); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (2); +SET @@max_heap_table_size = 1024*1024*1024*20; +CREATE TEMPORARY TABLE tmp ENGINE=MEMORY +SELECT id FROM t1; +DROP TEMPORARY TABLE tmp; +drop table t1; +# +# BUG#11825482: Broken key length calculation for btree index +# +CREATE TABLE h1 (f1 VARCHAR(1), f2 INT NOT NULL, +UNIQUE KEY h1i (f1,f2) USING BTREE ) ENGINE=HEAP; +INSERT INTO h1 VALUES(NULL,0),(NULL,1); +SELECT 'wrong' as 'result' FROM dual WHERE ('h', 0) NOT IN (SELECT * FROM h1); +result +CREATE TABLE t1 ( +pk int NOT NULL, +col_int_nokey INT, +col_varchar_nokey VARCHAR(1), +PRIMARY KEY (pk) +); +INSERT INTO t1 VALUES (19,5,'h'),(20,5,'h'); +CREATE TABLE t2 (col_int_nokey INT); +INSERT INTO t2 VALUES (1),(2); +CREATE VIEW v1 AS +SELECT col_varchar_nokey, COUNT( col_varchar_nokey ) +FROM t1 +WHERE col_int_nokey <= 141 AND pk <= 4 +; +SELECT col_int_nokey FROM t2 +WHERE ('h', 0) NOT IN ( SELECT * FROM v1); +col_int_nokey +# shouldn't crash +EXPLAIN SELECT col_int_nokey FROM t2 +WHERE ('h', 0) NOT IN ( SELECT * FROM v1); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t2 ALL NULL NULL NULL NULL 2 +2 SUBQUERY <derived3> ALL NULL NULL NULL NULL 2 Using where +3 DERIVED t1 range PRIMARY PRIMARY 4 NULL 1 Using index condition; Using where +DROP TABLE t1,t2,h1; +DROP VIEW v1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=100; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +1600 2400 +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=10000; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +16000 24000 +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=3000 max_rows=3000; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +48000 72000 +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap max_rows=15000; +insert into t1 values(1); +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +24000 36000 +drop table t1; +create table t1 (c1 int, index(c1)) engine=heap max_rows=10000; +insert into t1 select rand(100000000); +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1 limit 488; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +16000 24000 +insert into t1 select rand(100000000) from t1 limit 1; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +33024 49024 +insert into t1 select rand(100000000) from t1 limit 1000; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +49024 73024 +insert into t1 select rand(100000000) from t1; +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +data_length index_length +81024 121024 +drop table t1; +CREATE TABLE t1 (id INT); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (2); +SET @@max_heap_table_size = 1024*1024*1024*20; +CREATE TEMPORARY TABLE tmp ENGINE=MEMORY +SELECT id FROM t1; +DROP TEMPORARY TABLE tmp; +drop table t1; +CREATE TABLE t1 ( +id int(11) NOT NULL AUTO_INCREMENT, +color enum('GREEN', 'WHITE') DEFAULT NULL, +ts int, +PRIMARY KEY (id), +KEY color (color) USING HASH +) ENGINE=MEMORY DEFAULT CHARSET=utf8; +INSERT INTO t1 VALUES("1","GREEN",1); +INSERT INTO t1 VALUES("2","GREEN",1); +INSERT INTO t1 VALUES("3","GREEN",1); +INSERT INTO t1 VALUES("4","GREEN",1); +INSERT INTO t1 VALUES("5","GREEN",1); +INSERT INTO t1 VALUES("6","GREEN",1); +DELETE FROM t1 WHERE id = 1; +INSERT INTO t1 VALUES("7","GREEN", 2); +DELETE FROM t1 WHERE ts = 1 AND color = 'GREEN'; +SELECT * from t1 WHERE ts = 1 AND color = 'GREEN'; +id color ts +DROP TABLE t1; diff --git a/mysql-test/suite/heap/heap.test b/mysql-test/suite/heap/heap.test new file mode 100644 index 00000000..ef950da5 --- /dev/null +++ b/mysql-test/suite/heap/heap.test @@ -0,0 +1,661 @@ +# +# 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 @@default_storage_engine`; +set default_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; +SET STATEMENT sql_mode = 'NO_ENGINE_SUBSTITUTION' FOR +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; +} +delete from t1 where v like 'a%' and length(v) > 7; +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 default_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; + +# +# BUG#51763 Can't delete rows from MEMORY table with HASH key +# + +CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + color enum('GREEN', 'WHITE') DEFAULT NULL, + ts int, + PRIMARY KEY (id), + KEY color (color) USING HASH +) ENGINE=MEMORY DEFAULT CHARSET=utf8; + +INSERT INTO t1 VALUES("1","GREEN",1); +INSERT INTO t1 VALUES("2","GREEN",1); +INSERT INTO t1 VALUES("3","GREEN",1); +INSERT INTO t1 VALUES("4","GREEN",1); +INSERT INTO t1 VALUES("5","GREEN",1); +INSERT INTO t1 VALUES("6","GREEN",1); +DELETE FROM t1 WHERE id = 1; +INSERT INTO t1 VALUES("7","GREEN", 2); +DELETE FROM t1 WHERE ts = 1 AND color = 'GREEN'; +SELECT * from t1; +DROP TABLE t1; + + +# +# MDEV-5905 Creating tmp. memory table kills the server +# + +CREATE TABLE t1 (id INT); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (2); + +--disable_warnings +SET @@max_heap_table_size = 1024*1024*1024*20; +--enable_warnings + +CREATE TEMPORARY TABLE tmp ENGINE=MEMORY + SELECT id FROM t1; +DROP TEMPORARY TABLE tmp; +drop table t1; + +--echo # +--echo # BUG#11825482: Broken key length calculation for btree index +--echo # +CREATE TABLE h1 (f1 VARCHAR(1), f2 INT NOT NULL, + UNIQUE KEY h1i (f1,f2) USING BTREE ) ENGINE=HEAP; +INSERT INTO h1 VALUES(NULL,0),(NULL,1); +SELECT 'wrong' as 'result' FROM dual WHERE ('h', 0) NOT IN (SELECT * FROM h1); + +CREATE TABLE t1 ( + pk int NOT NULL, + col_int_nokey INT, + col_varchar_nokey VARCHAR(1), + PRIMARY KEY (pk) +); + +INSERT INTO t1 VALUES (19,5,'h'),(20,5,'h'); + +CREATE TABLE t2 (col_int_nokey INT); + +INSERT INTO t2 VALUES (1),(2); + +CREATE VIEW v1 AS + SELECT col_varchar_nokey, COUNT( col_varchar_nokey ) + FROM t1 + WHERE col_int_nokey <= 141 AND pk <= 4 +; + +SELECT col_int_nokey FROM t2 +WHERE ('h', 0) NOT IN ( SELECT * FROM v1); +--echo # shouldn't crash +EXPLAIN SELECT col_int_nokey FROM t2 +WHERE ('h', 0) NOT IN ( SELECT * FROM v1); + +DROP TABLE t1,t2,h1; +DROP VIEW v1; +# End of 5.1 tests + +# +# Show that MIN_ROWS and MAX_ROWS have an effect on how data_length +# and index_length are allocated. +# Result is different for 32 / 64 bit machines as pointer lengths are different +# + +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=100; +insert into t1 values(1); +--replace_result 800 1600 1200 2400 +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=10 max_rows=10000; +insert into t1 values(1); +--replace_result 8000 16000 12000 24000 +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap min_rows=3000 max_rows=3000; +insert into t1 values(1); +--replace_result 24000 48000 36000 72000 +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; +CREATE TABLE t1 (a int, index(a)) engine=heap max_rows=15000; +insert into t1 values(1); +--replace_result 12000 24000 18000 36000 +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; + +create table t1 (c1 int, index(c1)) engine=heap max_rows=10000; +insert into t1 select rand(100000000); +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1; +insert into t1 select rand(100000000) from t1 limit 488; +--replace_result 8000 16000 12000 24000 +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +insert into t1 select rand(100000000) from t1 limit 1; +--replace_result 16512 33024 24512 49024 +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +insert into t1 select rand(100000000) from t1 limit 1000; +--replace_result 24512 49024 36512 73024 +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +insert into t1 select rand(100000000) from t1; +--replace_result 40512 81024 60512 121024 +select data_length,index_length from information_schema.tables where table_schema="test" and table_name="t1"; +drop table t1; + +# +# MDEV-5905 Creating tmp. memory table kills the server +# + +CREATE TABLE t1 (id INT); +INSERT INTO t1 VALUES (1); +INSERT INTO t1 VALUES (2); + +--disable_warnings +SET @@max_heap_table_size = 1024*1024*1024*20; +--enable_warnings + +CREATE TEMPORARY TABLE tmp ENGINE=MEMORY + SELECT id FROM t1; +DROP TEMPORARY TABLE tmp; +drop table t1; + +# +# BUG#51763 Can't delete rows from MEMORY table with HASH key +# + +CREATE TABLE t1 ( + id int(11) NOT NULL AUTO_INCREMENT, + color enum('GREEN', 'WHITE') DEFAULT NULL, + ts int, + PRIMARY KEY (id), + KEY color (color) USING HASH +) ENGINE=MEMORY DEFAULT CHARSET=utf8; + +INSERT INTO t1 VALUES("1","GREEN",1); +INSERT INTO t1 VALUES("2","GREEN",1); +INSERT INTO t1 VALUES("3","GREEN",1); +INSERT INTO t1 VALUES("4","GREEN",1); +INSERT INTO t1 VALUES("5","GREEN",1); +INSERT INTO t1 VALUES("6","GREEN",1); +DELETE FROM t1 WHERE id = 1; +INSERT INTO t1 VALUES("7","GREEN", 2); +DELETE FROM t1 WHERE ts = 1 AND color = 'GREEN'; +SELECT * from t1 WHERE ts = 1 AND color = 'GREEN'; +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 00000000..0501de22 --- /dev/null +++ b/mysql-test/suite/heap/heap_auto_increment.result @@ -0,0 +1,190 @@ +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; +# +# MDEV-16534 PPC64: Unexpected error with a negative values into auto-increment columns in HEAP, MyISAM, ARIA +# +CREATE TABLE t1 ( +id TINYINT NOT NULL AUTO_INCREMENT, +name CHAR(30) NOT NULL, +PRIMARY KEY (id) +) ENGINE=MEMORY; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` tinyint(4) NOT NULL AUTO_INCREMENT, + `name` char(30) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +INSERT INTO t1 (name) VALUES ('dog'); +UPDATE t1 SET id=-1 WHERE id=1; +INSERT INTO t1 (name) VALUES ('cat'); +SELECT * FROM t1; +id name +-1 dog +2 cat +DROP TABLE t1; +# +# End of 5.5 tests +# +# +# MDEV-15352 AUTO_INCREMENT breaks after updating a column value to a negative number +# +SET @engine='MEMORY'; +CREATE PROCEDURE autoinc_mdev15353_one(engine VARCHAR(64), t VARCHAR(64)) +BEGIN +DECLARE query TEXT DEFAULT 'CREATE TABLE t1 (' + ' id TTT NOT NULL AUTO_INCREMENT,' + ' name CHAR(30) NOT NULL,' + ' PRIMARY KEY (id)) ENGINE=EEE'; +EXECUTE IMMEDIATE REPLACE(REPLACE(query,'TTT', t), 'EEE', engine); +SHOW CREATE TABLE t1; +INSERT INTO t1 (name) VALUES ('dog'); +SELECT * FROM t1; +UPDATE t1 SET id=-1 WHERE id=1; +SELECT * FROM t1; +INSERT INTO t1 (name) VALUES ('cat'); +SELECT * FROM t1; +DROP TABLE t1; +END; +$$ +CALL autoinc_mdev15353_one(@engine, 'tinyint'); +Table Create Table +t1 CREATE TABLE `t1` ( + `id` tinyint(4) NOT NULL AUTO_INCREMENT, + `name` char(30) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +id name +1 dog +id name +-1 dog +id name +-1 dog +2 cat +CALL autoinc_mdev15353_one(@engine, 'smallint'); +Table Create Table +t1 CREATE TABLE `t1` ( + `id` smallint(6) NOT NULL AUTO_INCREMENT, + `name` char(30) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +id name +1 dog +id name +-1 dog +id name +-1 dog +2 cat +CALL autoinc_mdev15353_one(@engine, 'mediumint'); +Table Create Table +t1 CREATE TABLE `t1` ( + `id` mediumint(9) NOT NULL AUTO_INCREMENT, + `name` char(30) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +id name +1 dog +id name +-1 dog +id name +-1 dog +2 cat +CALL autoinc_mdev15353_one(@engine, 'int'); +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` char(30) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +id name +1 dog +id name +-1 dog +id name +-1 dog +2 cat +CALL autoinc_mdev15353_one(@engine, 'bigint'); +Table Create Table +t1 CREATE TABLE `t1` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `name` char(30) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +id name +1 dog +id name +-1 dog +id name +-1 dog +2 cat +CALL autoinc_mdev15353_one(@engine, 'float'); +Table Create Table +t1 CREATE TABLE `t1` ( + `id` float NOT NULL AUTO_INCREMENT, + `name` char(30) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +id name +1 dog +id name +-1 dog +id name +-1 dog +2 cat +CALL autoinc_mdev15353_one(@engine, 'double'); +Table Create Table +t1 CREATE TABLE `t1` ( + `id` double NOT NULL AUTO_INCREMENT, + `name` char(30) NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +id name +1 dog +id name +-1 dog +id name +-1 dog +2 cat +DROP PROCEDURE autoinc_mdev15353_one; +# +# End of 10.2 tests +# 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 00000000..a480251f --- /dev/null +++ b/mysql-test/suite/heap/heap_auto_increment.test @@ -0,0 +1,67 @@ +# +# 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 + +--echo # +--echo # MDEV-16534 PPC64: Unexpected error with a negative values into auto-increment columns in HEAP, MyISAM, ARIA +--echo # + +CREATE TABLE t1 ( + id TINYINT NOT NULL AUTO_INCREMENT, + name CHAR(30) NOT NULL, + PRIMARY KEY (id) +) ENGINE=MEMORY; +SHOW CREATE TABLE t1; +INSERT INTO t1 (name) VALUES ('dog'); +UPDATE t1 SET id=-1 WHERE id=1; +INSERT INTO t1 (name) VALUES ('cat'); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # End of 5.5 tests +--echo # + +--echo # +--echo # MDEV-15352 AUTO_INCREMENT breaks after updating a column value to a negative number +--echo # + +SET @engine='MEMORY'; +--source include/autoinc_mdev15353.inc + +--echo # +--echo # End of 10.2 tests +--echo # + diff --git a/mysql-test/suite/heap/heap_btree.result b/mysql-test/suite/heap/heap_btree.result new file mode 100644 index 00000000..526c76a5 --- /dev/null +++ b/mysql-test/suite/heap/heap_btree.result @@ -0,0 +1,389 @@ +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 Ignored +t1 0 PRIMARY 1 a A NULL NULL NULL BTREE NO +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 +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 +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"),("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 +insert into t1 (a) select * from seq_1_to_100; +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 +create table t1 (id int, a varchar(300) not null, key using btree(a)) engine=heap; +insert t1 values (1, repeat('a', 300)); +drop table t1; +End of 5.5 tests diff --git a/mysql-test/suite/heap/heap_btree.test b/mysql-test/suite/heap/heap_btree.test new file mode 100644 index 00000000..d3fbe4cc --- /dev/null +++ b/mysql-test/suite/heap/heap_btree.test @@ -0,0 +1,297 @@ +--source include/have_sequence.inc + +# +# 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); +--sorted_result +select * from t1 where a > 736494; +select * from t1 where a = 736494; +select * from t1 where a=869751 or a=736494; +--sorted_result +select * from t1 where a in (869751,736494,226312,802616); +explain 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"),("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); +--sorted_result +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; +insert into t1 (a) select * from seq_1_to_100; +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 + +# +# Bug#27799513: POTENTIAL DOUBLE FREE OR CORRUPTION OF HEAP INFO (HP_INFO) +# +create table t1 (id int, a varchar(300) not null, key using btree(a)) engine=heap; +insert t1 values (1, repeat('a', 300)); +drop table t1; + +--echo End of 5.5 tests diff --git a/mysql-test/suite/heap/heap_hash.result b/mysql-test/suite/heap/heap_hash.result new file mode 100644 index 00000000..e523920b --- /dev/null +++ b/mysql-test/suite/heap/heap_hash.result @@ -0,0 +1,488 @@ +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 Ignored +t1 0 PRIMARY 1 a NULL 3 NULL NULL HASH NO +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 ALL uniq_id NULL NULL NULL 5 Using where +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 Ignored +t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH NO +t1 1 heap_idx 1 name NULL 13 NULL NULL HASH NO +t1 1 btree_idx 1 name A NULL NULL NULL BTREE NO +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 Ignored +t1 0 PRIMARY 1 id NULL 91 NULL NULL HASH NO +t1 1 heap_idx 1 name NULL 13 NULL NULL HASH NO +t1 1 btree_idx 1 name A NULL NULL NULL BTREE NO +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 Ignored +t3 1 a 1 a NULL NULL NULL NULL HASH NO +t3 1 a 2 b NULL 13 NULL NULL HASH NO +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 Ignored +t3 1 a 1 a NULL NULL NULL NULL HASH NO +t3 1 a 2 b NULL 13 NULL NULL HASH NO +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 +# +# MDEV-568 (AKA LP BUG#1007981, AKA MySQL bug#44771) +# Wrong result for a hash index look-up if the index is unique and +# the key is NULL +# +CREATE TABLE t1 ( pk INT PRIMARY KEY, val INT, UNIQUE KEY USING HASH(val)) ENGINE=MEMORY; +INSERT INTO t1 VALUES (1, NULL); +INSERT INTO t1 VALUES (2, NULL); +INSERT INTO t1 VALUES (3, 1); +INSERT INTO t1 VALUES (4, NULL); +EXPLAIN SELECT * FROM t1 WHERE val IS NULL; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref val val 5 const 1 Using where +SELECT * FROM t1 WHERE val IS NULL; +pk val +4 NULL +2 NULL +1 NULL +drop table t1; +End of 5.2 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,728912); +0+a +226312 +728912 +736494 +802616 +869751 +explain select 0+a from t1 where a in (869751,736494,226312,802616,728912); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range uniq_id uniq_id 8 NULL 5 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; +# +# Bug #1002564: Wrong result for a lookup query from a heap table +# +CREATE TABLE t1 (c1 VARCHAR(10) NOT NULL, KEY i1 (c1(3))) ENGINE=MEMORY DEFAULT CHARSET=latin1; +INSERT INTO t1 VALUES ('foo1'), ('bar2'), ('baz3'); +explain SELECT * FROM t1 WHERE c1='bar2'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref i1 i1 5 const 2 Using where +SELECT * FROM t1 WHERE c1='bar2'; +c1 +bar2 +ALTER TABLE t1 DROP KEY i1, ADD KEY il (c1(3)) using btree; +explain SELECT * FROM t1 WHERE c1='bar2'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref il il 5 const 1 Using where +SELECT * FROM t1 WHERE c1='bar2'; +c1 +bar2 +DROP TABLE t1; +# +# End of 5.5 tests +# +# +# MDEV-27406 Index on a HEAP table retains DESC attribute despite being hash +# +create table t1 (a int, key(a desc)) engine=memory; +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 Ignored +t1 1 a 1 a NULL 0 NULL NULL YES HASH NO +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + KEY `a` (`a`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +drop table t1; +# +# End of 10.8 tests +# diff --git a/mysql-test/suite/heap/heap_hash.test b/mysql-test/suite/heap/heap_hash.test new file mode 100644 index 00000000..3d3855d8 --- /dev/null +++ b/mysql-test/suite/heap/heap_hash.test @@ -0,0 +1,359 @@ +# +# Test of heap tables. +# + +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 # +--echo # MDEV-568 (AKA LP BUG#1007981, AKA MySQL bug#44771) +--echo # Wrong result for a hash index look-up if the index is unique and +--echo # the key is NULL +--echo # +CREATE TABLE t1 ( pk INT PRIMARY KEY, val INT, UNIQUE KEY USING HASH(val)) ENGINE=MEMORY; + +INSERT INTO t1 VALUES (1, NULL); +INSERT INTO t1 VALUES (2, NULL); +INSERT INTO t1 VALUES (3, 1); +INSERT INTO t1 VALUES (4, NULL); +EXPLAIN SELECT * FROM t1 WHERE val IS NULL; +SELECT * FROM t1 WHERE val IS NULL; +drop table t1; + +--echo End of 5.2 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,728912); +explain select 0+a from t1 where a in (869751,736494,226312,802616,728912); +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 # +--echo # Bug #1002564: Wrong result for a lookup query from a heap table +--echo # + +CREATE TABLE t1 (c1 VARCHAR(10) NOT NULL, KEY i1 (c1(3))) ENGINE=MEMORY DEFAULT CHARSET=latin1; +INSERT INTO t1 VALUES ('foo1'), ('bar2'), ('baz3'); +explain SELECT * FROM t1 WHERE c1='bar2'; +SELECT * FROM t1 WHERE c1='bar2'; +ALTER TABLE t1 DROP KEY i1, ADD KEY il (c1(3)) using btree; +explain SELECT * FROM t1 WHERE c1='bar2'; +SELECT * FROM t1 WHERE c1='bar2'; +DROP TABLE t1; + +--echo # +--echo # End of 5.5 tests +--echo # + +--echo # +--echo # MDEV-27406 Index on a HEAP table retains DESC attribute despite being hash +--echo # +create table t1 (a int, key(a desc)) engine=memory; +show index from t1; +show create table t1; +drop table t1; + +--echo # +--echo # End of 10.8 tests +--echo # |