summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSachin <sachin.setiya@mariadb.com>2020-06-03 13:36:36 +0530
committerSachin <sachin.setiya@mariadb.com>2020-06-07 12:07:41 +0530
commiteb14e073ea121954fb5be6fac92fd84b7d57bb07 (patch)
tree8bd3404730de0fe9f8e806bb172cbea11c4552e4
parente208f91ba8e8d674b276d52ba1645e4fef1f974a (diff)
downloadmariadb-git-eb14e073ea121954fb5be6fac92fd84b7d57bb07.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_length
Make UNIQUE HASH key in case when key_info->key_length > max_key_length
-rw-r--r--mysql-test/main/long_unique_bugs.result11
-rw-r--r--mysql-test/main/long_unique_bugs.test12
-rw-r--r--sql/sql_table.cc2
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 0645de40b59..72dab5bb181 100644
--- a/mysql-test/main/long_unique_bugs.result
+++ b/mysql-test/main/long_unique_bugs.result
@@ -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;
diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test
index e91c46ca90c..34d02b1c8f4 100644
--- a/mysql-test/main/long_unique_bugs.test
+++ b/mysql-test/main/long_unique_bugs.test
@@ -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;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 1c5aac08584..def29d78203 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -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)
{