Skip to content

Commit

Permalink
MDEV-18922 Alter on long unique varchar column makes result null
Browse files Browse the repository at this point in the history
Don't add long key into share->keys_for_keyread
  • Loading branch information
SachinSetiya committed Mar 15, 2019
1 parent 1ef50a3 commit 050280c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 14 additions & 0 deletions mysql-test/main/long_unique_bugs.result
Expand Up @@ -129,3 +129,17 @@ Comment
Index_comment
ALTER TABLE t1 ADD INDEX (pk);
DROP TABLE t1;
CREATE TABLE t1 (b int, a varchar(4000));
INSERT INTO t1 VALUES (1, 2),(2,3),(3,4);
ALTER TABLE t1 ADD UNIQUE INDEX (a);
SELECT * FROM t1;
b a
1 2
2 3
3 4
SELECT a FROM t1;
a
2
3
4
drop table t1;
10 changes: 10 additions & 0 deletions mysql-test/main/long_unique_bugs.test
Expand Up @@ -150,3 +150,13 @@ CREATE TABLE t1 (pk INT, PRIMARY KEY USING HASH (pk)) ENGINE=InnoDB;
--query_vertical show keys from t1;
ALTER TABLE t1 ADD INDEX (pk);
DROP TABLE t1;

#
# MDEV-18922 Alter on long unique varchar column makes result null
#
CREATE TABLE t1 (b int, a varchar(4000));
INSERT INTO t1 VALUES (1, 2),(2,3),(3,4);
ALTER TABLE t1 ADD UNIQUE INDEX (a);
SELECT * FROM t1;
SELECT a FROM t1;
drop table t1;
3 changes: 2 additions & 1 deletion sql/table.cc
Expand Up @@ -2684,7 +2684,8 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write,
if (i == 0)
field->key_start.set_bit(key);
if (field->key_length() == key_part->length &&
!(field->flags & BLOB_FLAG))
!(field->flags & BLOB_FLAG) &&
key_info->algorithm != HA_KEY_ALG_LONG_HASH)
{
if (handler_file->index_flags(key, i, 0) & HA_KEYREAD_ONLY)
{
Expand Down

0 comments on commit 050280c

Please sign in to comment.