Browse Source

MDEV-36852 Table definition gets corrupt after adding unique hash key

bb-10.6-mdev-31516
Sergei Golubchik 5 months ago
parent
commit
cda1826201
  1. 26
      mysql-test/main/long_unique_bugs.result
  2. 12
      mysql-test/main/long_unique_bugs.test
  3. 5
      sql/sql_table.cc
  4. 1
      sql/table.cc

26
mysql-test/main/long_unique_bugs.result

@ -809,3 +809,29 @@ hex(c1) hex(c2) c3 hex(c4)
NULL NULL NULL NULL
drop table t1;
# End of 10.5 tests
#
# MDEV-36852 Table definition gets corrupt after adding unique hash key
#
create table t1 (a text, b int, foreign key(a) references x(x)) engine=myisam;
Warnings:
Note 1071 Specified key was too long; max key length is 1000 bytes
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` text DEFAULT NULL,
`b` int(11) DEFAULT NULL,
KEY `a` (`a`(1000))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
alter table t1 add unique(a), add key(a);
Warnings:
Note 1071 Specified key was too long; max key length is 1000 bytes
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` text DEFAULT NULL,
`b` int(11) DEFAULT NULL,
UNIQUE KEY `a` (`a`) USING HASH,
KEY `a_2` (`a`(1000))
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
drop table t1;
# End of 10.6 tests

12
mysql-test/main/long_unique_bugs.test

@ -772,3 +772,15 @@ select hex(c1), hex(c2), c3, hex(c4) from t1;
drop table t1;
--echo # End of 10.5 tests
--echo #
--echo # MDEV-36852 Table definition gets corrupt after adding unique hash key
--echo #
create table t1 (a text, b int, foreign key(a) references x(x)) engine=myisam;
show create table t1;
alter table t1 add unique(a), add key(a);
show create table t1;
drop table t1;
--echo # End of 10.6 tests

5
sql/sql_table.cc

@ -3337,8 +3337,6 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
Create_field *auto_increment_key= 0;
Key_part_spec *column;
bool is_hash_field_needed= key->key_create_info.algorithm
== HA_KEY_ALG_LONG_HASH;
if (key->type == Key::IGNORE_KEY)
{
/* ignore redundant keys */
@ -3349,6 +3347,9 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
break;
}
bool is_hash_field_needed= key->key_create_info.algorithm
== HA_KEY_ALG_LONG_HASH;
if (key_check_without_overlaps(thd, create_info, alter_info, *key))
DBUG_RETURN(true);

1
sql/table.cc

@ -2838,6 +2838,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
hash_keypart->fieldnr= hash_field_used_no + 1;
hash_field= share->field[hash_field_used_no];
hash_field->flags|= LONG_UNIQUE_HASH_FIELD;//Used in parse_vcol_defs
DBUG_ASSERT(hash_field->invisible == INVISIBLE_FULL);
keyinfo->flags|= HA_NOSAME;
share->virtual_fields++;
share->stored_fields--;

Loading…
Cancel
Save