diff --git a/mysql-test/main/partition_error.result b/mysql-test/main/partition_error.result index 25c29938f91..f98e940cfda 100644 --- a/mysql-test/main/partition_error.result +++ b/mysql-test/main/partition_error.result @@ -754,7 +754,7 @@ ERROR HY000: Field 'c' is of a not allowed type for this type of partitioning # CREATE TABLE t1 (a INT) PARTITION BY HASH(a); CREATE TEMPORARY TABLE tmp_t1 LIKE t1; -ERROR HY000: Partitioned tables do not support CREATE TEMPORARY TABLE +ERROR HY000: Table storage engine 'partition' does not support the create option 'TEMPORARY' DROP TABLE t1; # # Bug#42954: SQL MODE 'NO_DIR_IN_CREATE' does not work with diff --git a/mysql-test/main/partition_error.test b/mysql-test/main/partition_error.test index 7436bb060d2..25b15578248 100644 --- a/mysql-test/main/partition_error.test +++ b/mysql-test/main/partition_error.test @@ -788,7 +788,7 @@ PARTITION BY HASH (c) PARTITIONS 4; --echo # with temporary table and partitions --echo # CREATE TABLE t1 (a INT) PARTITION BY HASH(a); ---error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING +--error ER_ILLEGAL_HA_CREATE_OPTION CREATE TEMPORARY TABLE tmp_t1 LIKE t1; DROP TABLE t1; --echo # diff --git a/mysql-test/suite/sys_vars/r/default_tmp_storage_engine_rocksdb.result b/mysql-test/suite/sys_vars/r/default_tmp_storage_engine_rocksdb.result new file mode 100644 index 00000000000..a93be903deb --- /dev/null +++ b/mysql-test/suite/sys_vars/r/default_tmp_storage_engine_rocksdb.result @@ -0,0 +1,51 @@ +# +# MDEV-12914: Engine for temporary tables which are implicitly +# created as RocksDB is substitued siliently with MyIsam +SET default_tmp_storage_engine = engine_doesnt_exist; +ERROR 42000: Unknown storage engine 'engine_doesnt_exist' +SET default_tmp_storage_engine = rocksdb; +ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY' +SET default_tmp_storage_engine = CONCAT('rocks','db'); +ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY' +CREATE TABLE t1 (i int) ENGINE = RocksDB; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `i` int(11) DEFAULT NULL +) ENGINE=ROCKSDB DEFAULT CHARSET=latin1 +CREATE TEMPORARY TABLE t2 LIKE t1; +ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY' +DROP TABLE t1; +SET default_storage_engine = DEFAULT; +SET default_tmp_storage_engine = DEFAULT; +CREATE TABLE t1 (t int); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `t` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +CREATE TEMPORARY TABLE t2 LIKE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TEMPORARY TABLE `t2` ( + `t` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; +SET default_storage_engine = rocksdb; +SET default_tmp_storage_engine = default; +CREATE TABLE t1 (t int); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `t` int(11) DEFAULT NULL +) ENGINE=ROCKSDB DEFAULT CHARSET=latin1 +CREATE TEMPORARY TABLE t2 LIKE t1; +ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY' +CREATE TEMPORARY TABLE t2 (t int); +ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY' +SET default_tmp_storage_engine = aria; +CREATE TEMPORARY TABLE t2 (t int); +DROP TABLE t2; +CREATE TEMPORARY TABLE t2 LIKE t1; +ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY' +DROP TABLE t1; diff --git a/mysql-test/suite/sys_vars/t/default_tmp_storage_engine_rocksdb.test b/mysql-test/suite/sys_vars/t/default_tmp_storage_engine_rocksdb.test new file mode 100644 index 00000000000..a3436059e39 --- /dev/null +++ b/mysql-test/suite/sys_vars/t/default_tmp_storage_engine_rocksdb.test @@ -0,0 +1,52 @@ +--echo # +--echo # MDEV-12914: Engine for temporary tables which are implicitly +--echo # created as RocksDB is substitued siliently with MyIsam + +--source include/have_rocksdb.inc +--source include/not_embedded.inc +--error ER_UNKNOWN_STORAGE_ENGINE +SET default_tmp_storage_engine = engine_doesnt_exist; +--error ER_ILLEGAL_HA_CREATE_OPTION +SET default_tmp_storage_engine = rocksdb; +--error ER_ILLEGAL_HA_CREATE_OPTION +SET default_tmp_storage_engine = CONCAT('rocks','db'); + +CREATE TABLE t1 (i int) ENGINE = RocksDB; +SHOW CREATE TABLE t1; + +--error ER_ILLEGAL_HA_CREATE_OPTION +CREATE TEMPORARY TABLE t2 LIKE t1; + +DROP TABLE t1; + +SET default_storage_engine = DEFAULT; +SET default_tmp_storage_engine = DEFAULT; + +CREATE TABLE t1 (t int); +SHOW CREATE TABLE t1; +CREATE TEMPORARY TABLE t2 LIKE t1; +SHOW CREATE TABLE t2; + +DROP TABLE t1, t2; + +SET default_storage_engine = rocksdb; +# setting default or null for tmp SE should use default SE +SET default_tmp_storage_engine = default; + +CREATE TABLE t1 (t int); +SHOW CREATE TABLE t1; + +--error ER_ILLEGAL_HA_CREATE_OPTION +CREATE TEMPORARY TABLE t2 LIKE t1; + +--error ER_ILLEGAL_HA_CREATE_OPTION +CREATE TEMPORARY TABLE t2 (t int); + +SET default_tmp_storage_engine = aria; +CREATE TEMPORARY TABLE t2 (t int); +DROP TABLE t2; + +--error ER_ILLEGAL_HA_CREATE_OPTION +CREATE TEMPORARY TABLE t2 LIKE t1; + +DROP TABLE t1; diff --git a/mysql-test/suite/sysschema/r/pr_diagnostics.result b/mysql-test/suite/sysschema/r/pr_diagnostics.result index d07295bdbe9..90021f636d8 100644 --- a/mysql-test/suite/sysschema/r/pr_diagnostics.result +++ b/mysql-test/suite/sysschema/r/pr_diagnostics.result @@ -6,8 +6,6 @@ SET @sys.debug = 'OFF', @sys.diagnostics.allow_i_s_tables = 'OFF', @sys.diagnostics.include_raw = 'OFF'; CALL sys.diagnostics(0, 0, 'full'); -summary -Disabled 1 thread ERROR 45000: in_max_runtime must be greater than 0 CALL sys.diagnostics(2, 0, 'full'); ERROR 45000: in_interval must be greater than 0 diff --git a/mysql-test/suite/sysschema/t/pr_diagnostics.test b/mysql-test/suite/sysschema/t/pr_diagnostics.test index 40ea90005a9..01825a1274e 100644 --- a/mysql-test/suite/sysschema/t/pr_diagnostics.test +++ b/mysql-test/suite/sysschema/t/pr_diagnostics.test @@ -19,6 +19,7 @@ SET @sys.debug = 'ON', @sys.diagnostics.allow_i_s_tables = 'ON', @sys.diagnostics.include_raw = 'ON'; +--error ER_ILLEGAL_HA_CREATE_OPTION CALL sys.diagnostics(4, 2, 'full'); SET @sys.debug = 'OFF', diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 88fe883c2a4..909b6fb6a07 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -11470,16 +11470,11 @@ bool check_engine(THD *thd, const char *db_name, if (create_info->tmp_table() && ha_check_storage_engine_flag(*new_engine, HTON_TEMPORARY_NOT_SUPPORTED)) { - if (create_info->used_fields & HA_CREATE_USED_ENGINE) - { - my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0), - hton_name(*new_engine)->str, "TEMPORARY"); - *new_engine= 0; - DBUG_RETURN(true); - } - *new_engine= myisam_hton; + my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0), + hton_name(*new_engine)->str, "TEMPORARY"); + *new_engine= 0; + DBUG_RETURN(true); } - lex_string_set(&create_info->new_storage_engine_name, ha_resolve_storage_engine_name(*new_engine)); DBUG_RETURN(false); diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index fa4e769232d..3ce01ebe3c2 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -741,6 +741,29 @@ static Sys_var_charptr_fscs Sys_character_sets_dir( READ_ONLY GLOBAL_VAR(charsets_dir), CMD_LINE(REQUIRED_ARG), DEFAULT(0)); +static bool check_engine_supports_temporary(sys_var *self, THD *thd, set_var *var) +{ + String str, *res; + LEX_CSTRING name; + if (!var->value || var->value->is_null()) + return false; + res= var->value->val_str(&str); + res->get_value(&name); + plugin_ref plugin= ha_resolve_by_name(thd, &name, true); + DBUG_ASSERT(plugin); + handlerton *hton= plugin_hton(plugin); + DBUG_ASSERT(hton); + if (ha_check_storage_engine_flag(hton, HTON_TEMPORARY_NOT_SUPPORTED)) + { + my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0), hton_name(hton)->str, + "TEMPORARY"); + plugin_unlock(thd, plugin); + return true; + } + plugin_unlock(thd, plugin); + return false; +} + static bool check_not_null(sys_var *self, THD *thd, set_var *var) { return var->value && var->value->is_null(); @@ -4239,7 +4262,8 @@ static Sys_var_plugin Sys_storage_engine( static Sys_var_plugin Sys_default_tmp_storage_engine( "default_tmp_storage_engine", "The default storage engine for user-created temporary tables", SESSION_VAR(tmp_table_plugin), NO_CMD_LINE, - MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_tmp_storage_engine)); + MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_tmp_storage_engine), + NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_engine_supports_temporary)); static Sys_var_plugin Sys_enforce_storage_engine( "enforce_storage_engine", "Force the use of a storage engine for new tables",