diff options
author | Nayuta Yanagisawa <nayuta.yanagisawa@hey.com> | 2022-03-31 22:38:54 +0900 |
---|---|---|
committer | Nayuta Yanagisawa <nayuta.yanagisawa@hey.com> | 2022-04-01 00:18:22 +0900 |
commit | 8ffbaf59add999b70a2a51d8872ed3b1b9fb6614 (patch) | |
tree | 19051199a1add16b5d9389ce1d0a16618e095632 | |
parent | 35425cfc55b461176f3e1c60d0435595b772ff3a (diff) | |
download | mariadb-git-bb-10.2-MDEV-21618.tar.gz |
MDEV-21618 CREATE UNIQUE INDEX fails with "ERROR 1286 (42000): Unknown storage engine 'partition'"bb-10.2-MDEV-21618
The server doesn't use the enforced storage engine in ALTER TABLE
without ENGINE clause to avoid an unwanted engine change.
However, the server tries to use the enforced engine in CREATE
INDEX. As a result, the false positive error is raised. The server
should not apply the enforced engine in CREATE INDEX too.
-rw-r--r-- | mysql-test/r/enforce_storage_engine.result | 7 | ||||
-rw-r--r-- | mysql-test/t/enforce_storage_engine.test | 15 | ||||
-rw-r--r-- | sql/sql_table.cc | 19 |
3 files changed, 32 insertions, 9 deletions
diff --git a/mysql-test/r/enforce_storage_engine.result b/mysql-test/r/enforce_storage_engine.result index 296ed405a72..b838af9cce9 100644 --- a/mysql-test/r/enforce_storage_engine.result +++ b/mysql-test/r/enforce_storage_engine.result @@ -158,5 +158,12 @@ t3 CREATE TABLE `t3` ( PRIMARY KEY (`c1`) ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 DROP TABLE t3; +# +# MDEV-21618 CREATE UNIQUE INDEX fails with "ERROR 1286 (42000): Unknown storage engine 'partition'" +# +SET SESSION enforce_storage_engine=MyISAM; +CREATE TABLE t4 (a INT) ENGINE=MyISAM PARTITION BY HASH(a); +CREATE INDEX x on t4 (a); +DROP TABLE t4; SET SESSION enforce_storage_engine=NULL; SET GLOBAL enforce_storage_engine=NULL; diff --git a/mysql-test/t/enforce_storage_engine.test b/mysql-test/t/enforce_storage_engine.test index 6b422477fe6..7768ed1bf46 100644 --- a/mysql-test/t/enforce_storage_engine.test +++ b/mysql-test/t/enforce_storage_engine.test @@ -1,4 +1,5 @@ --- source include/not_embedded.inc +--source include/not_embedded.inc +--source include/have_partition.inc set local sql_mode=""; set global sql_mode=""; @@ -107,5 +108,15 @@ ALTER TABLE t3 ADD COLUMN c3 INT; SHOW CREATE TABLE t3; DROP TABLE t3; +--echo # +--echo # MDEV-21618 CREATE UNIQUE INDEX fails with "ERROR 1286 (42000): Unknown storage engine 'partition'" +--echo # +SET SESSION enforce_storage_engine=MyISAM; + +CREATE TABLE t4 (a INT) ENGINE=MyISAM PARTITION BY HASH(a); +CREATE INDEX x on t4 (a); + +DROP TABLE t4; + SET SESSION enforce_storage_engine=NULL; -SET GLOBAL enforce_storage_engine=NULL;
\ No newline at end of file +SET GLOBAL enforce_storage_engine=NULL; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index a2dc5c97aeb..f3e8ebb98b3 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -10728,13 +10728,18 @@ bool check_engine(THD *thd, const char *db_name, if (!*new_engine) DBUG_RETURN(true); - /* Enforced storage engine should not be used in - ALTER TABLE that does not use explicit ENGINE = x to - avoid unwanted unrelated changes.*/ - if (!(thd->lex->sql_command == SQLCOM_ALTER_TABLE && - !(create_info->used_fields & HA_CREATE_USED_ENGINE))) - enf_engine= thd->variables.enforced_table_plugin ? - plugin_hton(thd->variables.enforced_table_plugin) : NULL; + /* + Enforced storage engine should not be used in ALTER TABLE that does not + use explicit ENGINE = x to avoid unwanted unrelated changes. It should not + be used in CREATE INDEX too. + */ + if (!((thd->lex->sql_command == SQLCOM_ALTER_TABLE && + !(create_info->used_fields & HA_CREATE_USED_ENGINE)) || + thd->lex->sql_command == SQLCOM_CREATE_INDEX)) + { + plugin_ref enf_plugin= thd->variables.enforced_table_plugin; + enf_engine= enf_plugin ? plugin_hton(enf_plugin) : NULL; + } if (enf_engine && enf_engine != *new_engine) { |