Commit eb14e073 authored by Sachin's avatar Sachin

MDEV-22719 Long unique keys are not created when individual key_part->length <...

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
parent e208f91b
...@@ -277,3 +277,14 @@ create table t2(id int primary key, a blob, b varchar(20) as (LEFT(a,2))); ...@@ -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); INSERT INTO t2 VALUES (1, 'foo', default);
DROP TABLE t1, t2; DROP TABLE t1, t2;
SET binlog_row_image= FULL; 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;
...@@ -356,3 +356,15 @@ INSERT INTO t2 VALUES (1, 'foo', default); ...@@ -356,3 +356,15 @@ INSERT INTO t2 VALUES (1, 'foo', default);
# Cleanup # Cleanup
DROP TABLE t1, t2; DROP TABLE t1, t2;
SET binlog_row_image= FULL; 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;
...@@ -4168,6 +4168,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, ...@@ -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)) if (key->type == Key::UNIQUE && !(key_info->flags & HA_NULL_PART_KEY))
unique_key=1; unique_key=1;
key_info->key_length=(uint16) key_length; 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 && if (key_length > max_key_length && key->type != Key::FULLTEXT &&
!is_hash_field_needed) !is_hash_field_needed)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment