Skip to content

Commit

Permalink
MDEV-22719 Long unique keys are not created when individual key_part-…
Browse files Browse the repository at this point in the history
…>length < max_key_length but SUM(key_parts->length) > max_key_length

Make UNIQUE HASH key in case when key_info->key_length > max_key_length
  • Loading branch information
mariadb-SachinSetiya committed Jun 7, 2020
1 parent e208f91 commit eb14e07
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mysql-test/main/long_unique_bugs.result
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,14 @@ create table t2(id int primary key, a blob, b varchar(20) as (LEFT(a,2)));
INSERT INTO t2 VALUES (1, 'foo', default);
DROP TABLE t1, t2;
SET binlog_row_image= FULL;
CREATE TABLE t1 (a int, b VARCHAR(1000), UNIQUE (a,b)) ENGINE=MyISAM;
show index from t1;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t1 0 a 1 a A NULL NULL NULL YES HASH
t1 0 a 2 b A NULL NULL NULL YES HASH
CREATE TABLE t2 (a varchar(900), b VARCHAR(900), UNIQUE (a,b)) ENGINE=MyISAM;
show index from t2;
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
t2 0 a 1 a A NULL NULL NULL YES HASH
t2 0 a 2 b A NULL NULL NULL YES HASH
DROP TABLE t1,t2;
12 changes: 12 additions & 0 deletions mysql-test/main/long_unique_bugs.test
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,15 @@ INSERT INTO t2 VALUES (1, 'foo', default);
# Cleanup
DROP TABLE t1, t2;
SET binlog_row_image= FULL;

#
# MDEV-22719 Long unique keys are not created when individual key_part->length < max_key_length but SUM(key_parts->length) > max_key_length
#

CREATE TABLE t1 (a int, b VARCHAR(1000), UNIQUE (a,b)) ENGINE=MyISAM;
show index from t1;
CREATE TABLE t2 (a varchar(900), b VARCHAR(900), UNIQUE (a,b)) ENGINE=MyISAM;
show index from t2;

# Cleanup
DROP TABLE t1,t2;
2 changes: 2 additions & 0 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4168,6 +4168,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
if (key->type == Key::UNIQUE && !(key_info->flags & HA_NULL_PART_KEY))
unique_key=1;
key_info->key_length=(uint16) key_length;
if (key_info->key_length > max_key_length && key->type == Key::UNIQUE)
is_hash_field_needed= true;
if (key_length > max_key_length && key->type != Key::FULLTEXT &&
!is_hash_field_needed)
{
Expand Down

0 comments on commit eb14e07

Please sign in to comment.