Skip to content

Commit f7216fa

Browse files
committed
MDEV-12914: Engine for temporary tables which are implicitly created as RocksDB is substituted silently
- There should be no substitution if engine exists, only when doesn't exist - Handling of an error when sys_var `default_tmp_storage_engine` is assigned to unsupported engine. - rocksdb doesn't support embedded server ebfc4e6 so is excluded Closes PR #774 Reviewed by: serg@mariadb.com vicentiu@mariadb.org
1 parent 57f14ea commit f7216fa

File tree

8 files changed

+135
-14
lines changed

8 files changed

+135
-14
lines changed

mysql-test/main/partition_error.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ ERROR HY000: Field 'c' is of a not allowed type for this type of partitioning
754754
#
755755
CREATE TABLE t1 (a INT) PARTITION BY HASH(a);
756756
CREATE TEMPORARY TABLE tmp_t1 LIKE t1;
757-
ERROR HY000: Partitioned tables do not support CREATE TEMPORARY TABLE
757+
ERROR HY000: Table storage engine 'partition' does not support the create option 'TEMPORARY'
758758
DROP TABLE t1;
759759
#
760760
# Bug#42954: SQL MODE 'NO_DIR_IN_CREATE' does not work with

mysql-test/main/partition_error.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ PARTITION BY HASH (c) PARTITIONS 4;
788788
--echo # with temporary table and partitions
789789
--echo #
790790
CREATE TABLE t1 (a INT) PARTITION BY HASH(a);
791-
--error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING
791+
--error ER_ILLEGAL_HA_CREATE_OPTION
792792
CREATE TEMPORARY TABLE tmp_t1 LIKE t1;
793793
DROP TABLE t1;
794794
--echo #
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# MDEV-12914: Engine for temporary tables which are implicitly
3+
# created as RocksDB is substitued siliently with MyIsam
4+
SET default_tmp_storage_engine = engine_doesnt_exist;
5+
ERROR 42000: Unknown storage engine 'engine_doesnt_exist'
6+
SET default_tmp_storage_engine = rocksdb;
7+
ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY'
8+
SET default_tmp_storage_engine = CONCAT('rocks','db');
9+
ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY'
10+
CREATE TABLE t1 (i int) ENGINE = RocksDB;
11+
SHOW CREATE TABLE t1;
12+
Table Create Table
13+
t1 CREATE TABLE `t1` (
14+
`i` int(11) DEFAULT NULL
15+
) ENGINE=ROCKSDB DEFAULT CHARSET=latin1
16+
CREATE TEMPORARY TABLE t2 LIKE t1;
17+
ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY'
18+
DROP TABLE t1;
19+
SET default_storage_engine = DEFAULT;
20+
SET default_tmp_storage_engine = DEFAULT;
21+
CREATE TABLE t1 (t int);
22+
SHOW CREATE TABLE t1;
23+
Table Create Table
24+
t1 CREATE TABLE `t1` (
25+
`t` int(11) DEFAULT NULL
26+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
27+
CREATE TEMPORARY TABLE t2 LIKE t1;
28+
SHOW CREATE TABLE t2;
29+
Table Create Table
30+
t2 CREATE TEMPORARY TABLE `t2` (
31+
`t` int(11) DEFAULT NULL
32+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
33+
DROP TABLE t1, t2;
34+
SET default_storage_engine = rocksdb;
35+
SET default_tmp_storage_engine = default;
36+
CREATE TABLE t1 (t int);
37+
SHOW CREATE TABLE t1;
38+
Table Create Table
39+
t1 CREATE TABLE `t1` (
40+
`t` int(11) DEFAULT NULL
41+
) ENGINE=ROCKSDB DEFAULT CHARSET=latin1
42+
CREATE TEMPORARY TABLE t2 LIKE t1;
43+
ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY'
44+
CREATE TEMPORARY TABLE t2 (t int);
45+
ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY'
46+
SET default_tmp_storage_engine = aria;
47+
CREATE TEMPORARY TABLE t2 (t int);
48+
DROP TABLE t2;
49+
CREATE TEMPORARY TABLE t2 LIKE t1;
50+
ERROR HY000: Table storage engine 'ROCKSDB' does not support the create option 'TEMPORARY'
51+
DROP TABLE t1;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--echo #
2+
--echo # MDEV-12914: Engine for temporary tables which are implicitly
3+
--echo # created as RocksDB is substitued siliently with MyIsam
4+
5+
--source include/have_rocksdb.inc
6+
--source include/not_embedded.inc
7+
--error ER_UNKNOWN_STORAGE_ENGINE
8+
SET default_tmp_storage_engine = engine_doesnt_exist;
9+
--error ER_ILLEGAL_HA_CREATE_OPTION
10+
SET default_tmp_storage_engine = rocksdb;
11+
--error ER_ILLEGAL_HA_CREATE_OPTION
12+
SET default_tmp_storage_engine = CONCAT('rocks','db');
13+
14+
CREATE TABLE t1 (i int) ENGINE = RocksDB;
15+
SHOW CREATE TABLE t1;
16+
17+
--error ER_ILLEGAL_HA_CREATE_OPTION
18+
CREATE TEMPORARY TABLE t2 LIKE t1;
19+
20+
DROP TABLE t1;
21+
22+
SET default_storage_engine = DEFAULT;
23+
SET default_tmp_storage_engine = DEFAULT;
24+
25+
CREATE TABLE t1 (t int);
26+
SHOW CREATE TABLE t1;
27+
CREATE TEMPORARY TABLE t2 LIKE t1;
28+
SHOW CREATE TABLE t2;
29+
30+
DROP TABLE t1, t2;
31+
32+
SET default_storage_engine = rocksdb;
33+
# setting default or null for tmp SE should use default SE
34+
SET default_tmp_storage_engine = default;
35+
36+
CREATE TABLE t1 (t int);
37+
SHOW CREATE TABLE t1;
38+
39+
--error ER_ILLEGAL_HA_CREATE_OPTION
40+
CREATE TEMPORARY TABLE t2 LIKE t1;
41+
42+
--error ER_ILLEGAL_HA_CREATE_OPTION
43+
CREATE TEMPORARY TABLE t2 (t int);
44+
45+
SET default_tmp_storage_engine = aria;
46+
CREATE TEMPORARY TABLE t2 (t int);
47+
DROP TABLE t2;
48+
49+
--error ER_ILLEGAL_HA_CREATE_OPTION
50+
CREATE TEMPORARY TABLE t2 LIKE t1;
51+
52+
DROP TABLE t1;

mysql-test/suite/sysschema/r/pr_diagnostics.result

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ SET @sys.debug = 'OFF',
66
@sys.diagnostics.allow_i_s_tables = 'OFF',
77
@sys.diagnostics.include_raw = 'OFF';
88
CALL sys.diagnostics(0, 0, 'full');
9-
summary
10-
Disabled 1 thread
119
ERROR 45000: in_max_runtime must be greater than 0
1210
CALL sys.diagnostics(2, 0, 'full');
1311
ERROR 45000: in_interval must be greater than 0

mysql-test/suite/sysschema/t/pr_diagnostics.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SET @sys.debug = 'ON',
1919
@sys.diagnostics.allow_i_s_tables = 'ON',
2020
@sys.diagnostics.include_raw = 'ON';
2121

22+
--error ER_ILLEGAL_HA_CREATE_OPTION
2223
CALL sys.diagnostics(4, 2, 'full');
2324

2425
SET @sys.debug = 'OFF',

sql/sql_table.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11470,16 +11470,11 @@ bool check_engine(THD *thd, const char *db_name,
1147011470
if (create_info->tmp_table() &&
1147111471
ha_check_storage_engine_flag(*new_engine, HTON_TEMPORARY_NOT_SUPPORTED))
1147211472
{
11473-
if (create_info->used_fields & HA_CREATE_USED_ENGINE)
11474-
{
11475-
my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0),
11476-
hton_name(*new_engine)->str, "TEMPORARY");
11477-
*new_engine= 0;
11478-
DBUG_RETURN(true);
11479-
}
11480-
*new_engine= myisam_hton;
11473+
my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0),
11474+
hton_name(*new_engine)->str, "TEMPORARY");
11475+
*new_engine= 0;
11476+
DBUG_RETURN(true);
1148111477
}
11482-
1148311478
lex_string_set(&create_info->new_storage_engine_name,
1148411479
ha_resolve_storage_engine_name(*new_engine));
1148511480
DBUG_RETURN(false);

sql/sys_vars.cc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,29 @@ static Sys_var_charptr_fscs Sys_character_sets_dir(
741741
READ_ONLY GLOBAL_VAR(charsets_dir), CMD_LINE(REQUIRED_ARG),
742742
DEFAULT(0));
743743

744+
static bool check_engine_supports_temporary(sys_var *self, THD *thd, set_var *var)
745+
{
746+
String str, *res;
747+
LEX_CSTRING name;
748+
if (!var->value || var->value->is_null())
749+
return false;
750+
res= var->value->val_str(&str);
751+
res->get_value(&name);
752+
plugin_ref plugin= ha_resolve_by_name(thd, &name, true);
753+
DBUG_ASSERT(plugin);
754+
handlerton *hton= plugin_hton(plugin);
755+
DBUG_ASSERT(hton);
756+
if (ha_check_storage_engine_flag(hton, HTON_TEMPORARY_NOT_SUPPORTED))
757+
{
758+
my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0), hton_name(hton)->str,
759+
"TEMPORARY");
760+
plugin_unlock(thd, plugin);
761+
return true;
762+
}
763+
plugin_unlock(thd, plugin);
764+
return false;
765+
}
766+
744767
static bool check_not_null(sys_var *self, THD *thd, set_var *var)
745768
{
746769
return var->value && var->value->is_null();
@@ -4239,7 +4262,8 @@ static Sys_var_plugin Sys_storage_engine(
42394262
static Sys_var_plugin Sys_default_tmp_storage_engine(
42404263
"default_tmp_storage_engine", "The default storage engine for user-created temporary tables",
42414264
SESSION_VAR(tmp_table_plugin), NO_CMD_LINE,
4242-
MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_tmp_storage_engine));
4265+
MYSQL_STORAGE_ENGINE_PLUGIN, DEFAULT(&default_tmp_storage_engine),
4266+
NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(check_engine_supports_temporary));
42434267

42444268
static Sys_var_plugin Sys_enforce_storage_engine(
42454269
"enforce_storage_engine", "Force the use of a storage engine for new tables",

0 commit comments

Comments
 (0)