Skip to content

Commit eb14e07

Browse files
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
1 parent e208f91 commit eb14e07

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

mysql-test/main/long_unique_bugs.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,3 +277,14 @@ create table t2(id int primary key, a blob, b varchar(20) as (LEFT(a,2)));
277277
INSERT INTO t2 VALUES (1, 'foo', default);
278278
DROP TABLE t1, t2;
279279
SET binlog_row_image= FULL;
280+
CREATE TABLE t1 (a int, b VARCHAR(1000), UNIQUE (a,b)) ENGINE=MyISAM;
281+
show index from t1;
282+
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
283+
t1 0 a 1 a A NULL NULL NULL YES HASH
284+
t1 0 a 2 b A NULL NULL NULL YES HASH
285+
CREATE TABLE t2 (a varchar(900), b VARCHAR(900), UNIQUE (a,b)) ENGINE=MyISAM;
286+
show index from t2;
287+
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment
288+
t2 0 a 1 a A NULL NULL NULL YES HASH
289+
t2 0 a 2 b A NULL NULL NULL YES HASH
290+
DROP TABLE t1,t2;

mysql-test/main/long_unique_bugs.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,15 @@ INSERT INTO t2 VALUES (1, 'foo', default);
356356
# Cleanup
357357
DROP TABLE t1, t2;
358358
SET binlog_row_image= FULL;
359+
360+
#
361+
# MDEV-22719 Long unique keys are not created when individual key_part->length < max_key_length but SUM(key_parts->length) > max_key_length
362+
#
363+
364+
CREATE TABLE t1 (a int, b VARCHAR(1000), UNIQUE (a,b)) ENGINE=MyISAM;
365+
show index from t1;
366+
CREATE TABLE t2 (a varchar(900), b VARCHAR(900), UNIQUE (a,b)) ENGINE=MyISAM;
367+
show index from t2;
368+
369+
# Cleanup
370+
DROP TABLE t1,t2;

sql/sql_table.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4168,6 +4168,8 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
41684168
if (key->type == Key::UNIQUE && !(key_info->flags & HA_NULL_PART_KEY))
41694169
unique_key=1;
41704170
key_info->key_length=(uint16) key_length;
4171+
if (key_info->key_length > max_key_length && key->type == Key::UNIQUE)
4172+
is_hash_field_needed= true;
41714173
if (key_length > max_key_length && key->type != Key::FULLTEXT &&
41724174
!is_hash_field_needed)
41734175
{

0 commit comments

Comments
 (0)