diff --git a/mysql-test/r/heap_btree.result b/mysql-test/r/heap_btree.result index 7a0e46a2a1c..91f51a95936 100644 --- a/mysql-test/r/heap_btree.result +++ b/mysql-test/r/heap_btree.result @@ -295,6 +295,18 @@ 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; End of 4.1 tests CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory; INSERT INTO t1 VALUES(0); diff --git a/mysql-test/t/heap_btree.test b/mysql-test/t/heap_btree.test index 2dd5f64014a..af8f9d9c9e8 100644 --- a/mysql-test/t/heap_btree.test +++ b/mysql-test/t/heap_btree.test @@ -196,6 +196,23 @@ 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; + --echo End of 4.1 tests # diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index d1a931b07f2..8838aa99c1a 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -604,7 +604,10 @@ int ha_heap::create(const char *name, TABLE *table_arg, seg->length= (uint) key_part->length; seg->flag= key_part->key_part_flag; - seg->charset= field->charset(); + if (field->flags & (ENUM_FLAG | SET_FLAG)) + seg->charset= &my_charset_bin; + else + seg->charset= field->charset(); if (field->null_ptr) { seg->null_bit= field->null_bit;