mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
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
This commit is contained in:
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user