Skip to content

Commit

Permalink
MDEV-18888 Server crashes in Item_field::register_field_in_read_map u…
Browse files Browse the repository at this point in the history
…pon...

MODIFY COLUMN

Do Not create prefix field for long unique key
  • Loading branch information
SachinSetiya committed Mar 17, 2019
1 parent 8995f33 commit 3943fe5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
15 changes: 15 additions & 0 deletions mysql-test/main/long_unique_bugs.result
Expand Up @@ -171,3 +171,18 @@ insert into t1(a,b) values(2,2);
insert into t1(a,b) values(2,3);
insert into t1(a,b) values(3,2);
drop table t1;
CREATE TABLE t1 (
a CHAR(128),
b CHAR(128) AS (a),
c DATETIME,
UNIQUE(c,b(64))
) ENGINE=InnoDB;
ALTER TABLE t1 MODIFY COLUMN c VARCHAR(4096);
drop table t1;
CREATE TABLE t1 (
a CHAR(128),
b CHAR(128) AS (a),
c varchar(5000),
UNIQUE(c,b(64))
) ENGINE=InnoDB;
drop table t1;
19 changes: 19 additions & 0 deletions mysql-test/main/long_unique_bugs.test
Expand Up @@ -196,3 +196,22 @@ insert into t1(a,b) values(2,2);
insert into t1(a,b) values(2,3);
insert into t1(a,b) values(3,2);
drop table t1;

#
# MDEV-18888 Server crashes in Item_field::register_field_in_read_map upon MODIFY COLUMN
#
CREATE TABLE t1 (
a CHAR(128),
b CHAR(128) AS (a),
c DATETIME,
UNIQUE(c,b(64))
) ENGINE=InnoDB;
ALTER TABLE t1 MODIFY COLUMN c VARCHAR(4096);
drop table t1;
CREATE TABLE t1 (
a CHAR(128),
b CHAR(128) AS (a),
c varchar(5000),
UNIQUE(c,b(64))
) ENGINE=InnoDB;
drop table t1;
9 changes: 7 additions & 2 deletions sql/table.cc
Expand Up @@ -3708,9 +3708,14 @@ enum open_frm_error open_table_from_share(THD *thd, TABLE_SHARE *share,
for ( ; key_part < key_part_end; key_part++)
{
Field *field= key_part->field= outparam->field[key_part->fieldnr - 1];

/*
There's no need to create a prefix
Field for HA_KEY_ALG_LONG_HASH indexes, as they implement prefixing via
Iten_func_left anyway (see parse_vcol_defs())
*/
if (field->key_length() != key_part->length &&
!(field->flags & BLOB_FLAG))
!(field->flags & BLOB_FLAG) &&
key_info->algorithm != HA_KEY_ALG_LONG_HASH)
{
/*
We are using only a prefix of the column as a key:
Expand Down

0 comments on commit 3943fe5

Please sign in to comment.