diff options
author | Sachin <sachin.setiya@mariadb.com> | 2020-06-03 13:36:36 +0530 |
---|---|---|
committer | Sachin <sachin.setiya@mariadb.com> | 2020-06-03 13:47:39 +0530 |
commit | 7df57cc82062cbe808ef63f43009731065310398 (patch) | |
tree | 488f8e2325fa84d3629238284366d8c659db87a2 | |
parent | 0f91c62d332be5cf53f59901562a7bd6e1683a57 (diff) | |
download | mariadb-git-bb-10.4-sachin2.tar.gz |
MDEV-22719 Long unique keys are not created when individual key_part->length < max_key_length but SUM(key_parts->length) > max_key_lengthbb-10.4-sachin2
Make UNIQUE HASH key in case when key_info->key_length > max_key_length
-rw-r--r-- | mysql-test/main/long_unique_bugs.result | 11 | ||||
-rw-r--r-- | mysql-test/main/long_unique_bugs.test | 12 | ||||
-rw-r--r-- | sql/sql_table.cc | 2 |
3 files changed, 25 insertions, 0 deletions
diff --git a/mysql-test/main/long_unique_bugs.result b/mysql-test/main/long_unique_bugs.result index ca30e642d8c..e71dcecccab 100644 --- a/mysql-test/main/long_unique_bugs.result +++ b/mysql-test/main/long_unique_bugs.result @@ -291,3 +291,14 @@ test.t1 analyze status Engine-independent statistics collected test.t1 analyze Warning Engine-independent statistics are not collected for column 'f' test.t1 analyze status OK DROP TABLE t1; +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; diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test index b2d4dd96831..99f83b09191 100644 --- a/mysql-test/main/long_unique_bugs.test +++ b/mysql-test/main/long_unique_bugs.test @@ -373,3 +373,15 @@ ANALYZE TABLE t1 PERSISTENT FOR ALL; # Cleanup DROP TABLE t1; + +# +# 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; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 4498e1d1c51..77b7070743c 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4171,6 +4171,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) { |