Skip to content

Commit

Permalink
MDEV-8219: enforce_storage_engine cannot be set globally
Browse files Browse the repository at this point in the history
Change session only variable enforce_storage_engine to be
session variable and make sure that also global value
is used if session variable is not set.
  • Loading branch information
Jan Lindström committed Jun 26, 2015
1 parent a4b0063 commit d535728
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 6 deletions.
21 changes: 20 additions & 1 deletion mysql-test/r/enforce_storage_engine.result
Expand Up @@ -98,5 +98,24 @@ t1 CREATE TABLE `t1` (
PRIMARY KEY (`c1`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
SET GLOBAL enforce_storage_engine=Memory;
SET SESSION sql_mode='';
select @@session.enforce_storage_engine;
@@session.enforce_storage_engine
MEMORY
select @@global.enforce_storage_engine;
@@global.enforce_storage_engine
MEMORY
CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10));
Warnings:
Note 1266 Using storage engine MEMORY for table 't1'
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`c1` int(11) NOT NULL AUTO_INCREMENT,
`c2` varchar(10) DEFAULT NULL,
PRIMARY KEY (`c1`)
) ENGINE=MEMORY DEFAULT CHARSET=latin1
DROP TABLE t1;
SET SESSION enforce_storage_engine=NULL;
SET GLOBAL enforce_storage_engine=NULL;
ERROR HY000: Variable 'enforce_storage_engine' is a SESSION variable and can't be used with SET GLOBAL
4 changes: 2 additions & 2 deletions mysql-test/suite/sys_vars/r/sysvars_server_notembedded.result
Expand Up @@ -725,10 +725,10 @@ READ_ONLY YES
COMMAND_LINE_ARGUMENT OPTIONAL
VARIABLE_NAME ENFORCE_STORAGE_ENGINE
SESSION_VALUE
GLOBAL_VALUE NULL
GLOBAL_VALUE
GLOBAL_VALUE_ORIGIN COMPILE-TIME
DEFAULT_VALUE NULL
VARIABLE_SCOPE SESSION ONLY
VARIABLE_SCOPE SESSION
VARIABLE_TYPE VARCHAR
VARIABLE_COMMENT Force the use of a storage engine for new tables
NUMERIC_MIN_VALUE NULL
Expand Down
15 changes: 14 additions & 1 deletion mysql-test/t/enforce_storage_engine.test
Expand Up @@ -69,5 +69,18 @@ CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10));
SHOW CREATE TABLE t1;
DROP TABLE t1;

--error 1228
SET GLOBAL enforce_storage_engine=Memory;
SET SESSION sql_mode='';

connect (con1,localhost,root,,);
connection con1;
select @@session.enforce_storage_engine;
select @@global.enforce_storage_engine;
CREATE TABLE t1 (c1 INT PRIMARY KEY AUTO_INCREMENT, c2 VARCHAR(10));
SHOW CREATE TABLE t1;
DROP TABLE t1;
connection default;
disconnect con1;

SET SESSION enforce_storage_engine=NULL;
SET GLOBAL enforce_storage_engine=NULL;
3 changes: 2 additions & 1 deletion sql/sql_table.cc
Expand Up @@ -9772,7 +9772,8 @@ static bool check_engine(THD *thd, const char *db_name,
DBUG_ENTER("check_engine");
handlerton **new_engine= &create_info->db_type;
handlerton *req_engine= *new_engine;
handlerton *enf_engine= thd->variables.enforced_table_plugin ? plugin_hton(thd->variables.enforced_table_plugin) : NULL;
handlerton *enf_engine= thd->variables.enforced_table_plugin ?
plugin_hton(thd->variables.enforced_table_plugin) : NULL;
bool no_substitution= thd->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION;
*new_engine= ha_checktype(thd, req_engine, no_substitution);
DBUG_ASSERT(*new_engine);
Expand Down
2 changes: 1 addition & 1 deletion sql/sys_vars.cc
Expand Up @@ -3426,7 +3426,7 @@ static Sys_var_plugin Sys_default_tmp_storage_engine(

static Sys_var_plugin Sys_enforce_storage_engine(
"enforce_storage_engine", "Force the use of a storage engine for new tables",
SESSION_ONLY(enforced_table_plugin),
SESSION_VAR(enforced_table_plugin),
NO_CMD_LINE, MYSQL_STORAGE_ENGINE_PLUGIN,
DEFAULT(&enforced_storage_engine), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_has_super));

Expand Down

0 comments on commit d535728

Please sign in to comment.