From 62bfb2fe492f2eb789476ce4517113d2f18be2c6 Mon Sep 17 00:00:00 2001 From: sachin Date: Mon, 4 Mar 2019 14:48:11 +0530 Subject: [PATCH] MDEV-18800 Server crash in instant_alter_column_possible or Assertion... `!pk->has_virtual()' failed in instant_alter_column_possible upon adding key Hash key can't be primary key. --- mysql-test/main/long_unique_bugs.result | 17 +++++++++++++++++ mysql-test/main/long_unique_bugs.test | 9 +++++++++ sql/sql_table.cc | 1 + 3 files changed, 27 insertions(+) diff --git a/mysql-test/main/long_unique_bugs.result b/mysql-test/main/long_unique_bugs.result index ec0105bccb5..b787683440f 100644 --- a/mysql-test/main/long_unique_bugs.result +++ b/mysql-test/main/long_unique_bugs.result @@ -112,3 +112,20 @@ ERROR 42000: Can't DROP COLUMN `x`; check that it exists SELECT * FROM t1 WHERE f LIKE 'foo'; f DROP TABLE t1; +CREATE TABLE t1 (pk INT, PRIMARY KEY USING HASH (pk)) ENGINE=InnoDB; +show keys from t1;; +Table t1 +Non_unique 0 +Key_name PRIMARY +Seq_in_index 1 +Column_name pk +Collation A +Cardinality 0 +Sub_part NULL +Packed NULL +Null +Index_type BTREE +Comment +Index_comment +ALTER TABLE t1 ADD INDEX (pk); +DROP TABLE t1; diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test index a3cf60c17f6..5b4fcc5b09f 100644 --- a/mysql-test/main/long_unique_bugs.test +++ b/mysql-test/main/long_unique_bugs.test @@ -141,3 +141,12 @@ CREATE TABLE t1 (f VARCHAR(4096), UNIQUE(f)) ENGINE=InnoDB; ALTER TABLE t1 DROP x; SELECT * FROM t1 WHERE f LIKE 'foo'; DROP TABLE t1; + +# +# MDEV-18800 Server crash in instant_alter_column_possible or +# Assertion `!pk->has_virtual()' failed in instant_alter_column_possible upon adding key +# +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; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 80aebd2f9ad..e1337a0f710 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4179,6 +4179,7 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, } if (is_hash_field_needed || (key_info->algorithm == HA_KEY_ALG_HASH && + key->type != Key::PRIMARY && key_info->flags & HA_NOSAME && !(file->ha_table_flags() & HA_CAN_HASH_KEYS ) && file->ha_table_flags() & HA_CAN_VIRTUAL_COLUMNS))