diff --git a/mysql-test/main/long_unique_bugs.result b/mysql-test/main/long_unique_bugs.result index b787683440fb1..26d4fe14575b5 100644 --- a/mysql-test/main/long_unique_bugs.result +++ b/mysql-test/main/long_unique_bugs.result @@ -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; diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test index 5b4fcc5b09fdb..550ef39359522 100644 --- a/mysql-test/main/long_unique_bugs.test +++ b/mysql-test/main/long_unique_bugs.test @@ -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; diff --git a/sql/table.cc b/sql/table.cc index d0615962f337b..011a2bb2c9a22 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -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) {