Skip to content

Commit 4c9cba4

Browse files
WL#8594 - PROVIDE AN OPTION TO REJECT USER TABLE CREATION UNDER SPECIFIED STORAGE ENGINES.
This worklog addresses the following functional requirements: * Provide a global command-line server startup option --disabled-storage-engines which accepts comma delimited storage engine names. DDL's which end-up creating new table or tablespace on these engines will be disallowed. Specifically, 'CREATE [TEMPORARY] TABLE', 'ALTER TABLE ... ENGINE' and 'CREATE/ALTER TABLESPACE' using one of above engine. * The SQL statements 'CREATE [TEMPORARY] TABLE', 'ALTER TABLE ... ENGINE' and 'CREATE/ALTER TABLESPACE' shall fail with the error "Storage engine 'storage engine name' is disabled (Table creation is disallowed.)" for the storage engines specified by disabled-storage-engine option. This option shall be noop and will have no effect when the server is either started with --bootstrap or --skip-grant-tables options. * This option does not affect any other DDL statements except for, 'CREATE [TEMPORARY] TABLE', 'ALTER TABLE ... ENGINE' and 'CREATE/ALTER TABLESPACE' * This option shall be noop and will have no effect when the server is either started with --bootstrap or --initialize or --initialize-insecure or --skip-grant-tables. The bootstrap and related options are used by sys admin to initialize system tables to prepare the server to operate normally and --skip-grant-tables is meant to provide full control with no authorization required.
1 parent 7a595ca commit 4c9cba4

20 files changed

+308
-1
lines changed

include/my_global.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,4 +768,7 @@ static inline ulonglong diff_timespec(struct timespec *ts1, struct timespec *ts2
768768
#define DEFAULT_SSL_SERVER_CERT "server-cert.pem"
769769
#define DEFAULT_SSL_SERVER_KEY "server-key.pem"
770770

771+
#if defined(_WIN32) || defined(_WIN64)
772+
#define strcasecmp _stricmp
773+
#endif
771774
#endif // MY_GLOBAL_INCLUDED

libmysqld/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ SET(SQL_EMBEDDED_SOURCES
102102

103103
INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake)
104104
ADD_COMPILE_FLAGS(
105+
../sql/handler.cc
105106
../sql/item_geofunc.cc
106107
../sql/item_geofunc_buffer.cc
107108
../sql/item_geofunc_relchecks.cc
@@ -115,6 +116,7 @@ ADD_COMPILE_FLAGS(
115116
MY_CHECK_CXX_COMPILER_FLAG("-Wno-unused-local-typedefs" HAVE_NO_UNUSED_TYPEDEFS)
116117
IF(HAVE_NO_UNUSED_TYPEDEFS)
117118
ADD_COMPILE_FLAGS(
119+
../sql/handler.cc
118120
../sql/item_geofunc.cc
119121
../sql/item_geofunc_buffer.cc
120122
../sql/item_geofunc_relchecks.cc
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
CREATE TABLE t1(c1 int) ENGINE=HEAP;
2+
ERROR HY000: Storage engine MEMORY is disabled (Table creation is disallowed).
3+
CREATE TABLE t1 (c1 int) ENGINE=MYISAM;
4+
INSERT INTO t1 VALUES(1);
5+
CREATE TABLESPACE tb1 ADD DATAFILE 't1.ibd' ENGINE=INNODB;
6+
CREATE TABLE tp1 (c1 int) PARTITION BY KEY (c1) PARTITIONS 1;
7+
SHOW VARIABLES LIKE 'disabled_storage_engines';
8+
Variable_name Value
9+
disabled_storage_engines innodb,myisam,heap,example
10+
SELECT * FROM t1;
11+
c1
12+
1
13+
ALTER TABLE t1 ENGINE=MyISAM, ADD COLUMN c2 INT;
14+
ALTER TABLE t1 ADD COLUMN c3 INT;
15+
DROP TABLESPACE tb1;
16+
CREATE TABLE t2 LIKE t1;
17+
ERROR HY000: Storage engine MyISAM is disabled (Table creation is disallowed).
18+
CREATE TABLE t2 AS SELECT * FROM t1;
19+
ERROR HY000: Storage engine InnoDB is disabled (Table creation is disallowed).
20+
ALTER TABLE t1 ENGINE=InnoDB;
21+
ERROR HY000: Storage engine InnoDB is disabled (Table creation is disallowed).
22+
ALTER TABLE t1 ENGINE=HEAP;
23+
ERROR HY000: Storage engine MEMORY is disabled (Table creation is disallowed).
24+
CREATE TABLE t2(c1 int) ENGINE=INNODB SELECT c1 FROM t1;
25+
ERROR HY000: Storage engine InnoDB is disabled (Table creation is disallowed).
26+
CREATE TABLE t2(c1 int) ENGINE=HEAP SELECT c1 FROM t1;
27+
ERROR HY000: Storage engine MEMORY is disabled (Table creation is disallowed).
28+
TRUNCATE TABLE t1;
29+
DROP TABLE t1;
30+
CREATE TABLESPACE t1 ADD DATAFILE 't1.ibd' ENGINE=INNODB;
31+
ERROR HY000: Storage engine InnoDB is disabled (Table creation is disallowed).
32+
CREATE TABLESPACE t1 ADD DATAFILE 't1.ibd' ENGINE=HEAP;
33+
ERROR HY000: Storage engine MEMORY is disabled (Table creation is disallowed).
34+
ALTER TABLESPACE ts ADD DATAFILE 'ts.ibd' ENGINE=INNODB;
35+
ERROR HY000: Storage engine InnoDB is disabled (Table creation is disallowed).
36+
ALTER TABLESPACE ts ADD DATAFILE 'ts.ibd' ENGINE=HEAP;
37+
ERROR HY000: Storage engine MEMORY is disabled (Table creation is disallowed).
38+
ALTER TABLESPACE ts ADD DATAFILE 'ts.ibd';
39+
ERROR HY000: Storage engine InnoDB is disabled (Table creation is disallowed).
40+
CREATE TEMPORARY TABLE t1 (c1 int) ENGINE=INNODB;
41+
ERROR HY000: Storage engine InnoDB is disabled (Table creation is disallowed).
42+
CREATE TEMPORARY TABLE t1 (c1 int) ENGINE=HEAP;
43+
ERROR HY000: Storage engine MEMORY is disabled (Table creation is disallowed).
44+
CREATE PROCEDURE p1()
45+
BEGIN
46+
CREATE TABLE t1 (c1 int) ENGINE=MYISAM;
47+
END |
48+
CALL p1();
49+
ERROR HY000: Storage engine MyISAM is disabled (Table creation is disallowed).
50+
DROP PROCEDURE p1;
51+
CREATE TABLE t1 (c1 int) PARTITION BY KEY (c1) PARTITIONS 1;
52+
ERROR HY000: Storage engine InnoDB is disabled (Table creation is disallowed).
53+
INSERT INTO tp1 VALUES(1);
54+
DROP TABLE tp1;
55+
INSTALL PLUGIN example SONAME 'ha_example.so';
56+
CREATE TABLE t1(a int) ENGINE=EXAMPLE;
57+
ERROR HY000: Storage engine EXAMPLE is disabled (Table creation is disallowed).
58+
UNINSTALL PLUGIN example;
59+
INSTALL PLUGIN example SONAME 'ha_example.so';
60+
CREATE TABLE t1(a int) ENGINE=EXAMPLE;
61+
ERROR HY000: Storage engine EXAMPLE is disabled (Table creation is disallowed).
62+
UNINSTALL PLUGIN example;
63+
CREATE TABLE t1(a int) ENGINE=MYISAM;
64+
DROP TABLE t1;
65+
# restart

mysql-test/r/mysqld--help-notwin.result

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ The following options may be given as the first argument:
214214
client that does INSERT DELAYED will wait until there is
215215
room in the queue again. This variable is deprecated
216216
along with INSERT DELAYED.
217+
--disabled-storage-engines=name
218+
Limit CREATE TABLE for the storage engines listed
217219
--disconnect-on-expired-password
218220
Give clients that don't signal password expiration
219221
support execution time error(s) instead of connection
@@ -1249,6 +1251,7 @@ delay-key-write ON
12491251
delayed-insert-limit 100
12501252
delayed-insert-timeout 300
12511253
delayed-queue-size 1000
1254+
disabled-storage-engines
12521255
disconnect-on-expired-password TRUE
12531256
disconnect-slave-event-count 0
12541257
div-precision-increment 4

mysql-test/r/mysqld--help-win.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ The following options may be given as the first argument:
213213
client that does INSERT DELAYED will wait until there is
214214
room in the queue again. This variable is deprecated
215215
along with INSERT DELAYED.
216+
--disabled-storage-engines=name
217+
Limit CREATE TABLE for the storage engines listed
216218
--disconnect-on-expired-password
217219
Give clients that don't signal password expiration
218220
support execution time error(s) instead of connection

mysql-test/suite/innodb_gis/r/geometry.result

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ SHOW VARIABLES LIKE '%engine%';
55
Variable_name Value
66
default_storage_engine InnoDB
77
default_tmp_storage_engine InnoDB
8+
disabled_storage_engines
89
internal_tmp_disk_storage_engine TMP_TABLE_ENGINE
910
USE test;
1011
DROP TABLE IF EXISTS t1, gis_point, gis_line, gis_polygon;

mysql-test/suite/perfschema/t/show_sanity.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ insert into test.sanity values
340340
("JUNK: GLOBAL-ONLY", "I_S.SESSION_VARIABLES", "DELAYED_INSERT_TIMEOUT"),
341341
("JUNK: GLOBAL-ONLY", "I_S.SESSION_VARIABLES", "DELAYED_QUEUE_SIZE"),
342342
("JUNK: GLOBAL-ONLY", "I_S.SESSION_VARIABLES", "DELAY_KEY_WRITE"),
343+
("JUNK: GLOBAL-ONLY", "I_S.SESSION_VARIABLES", "DISABLED_STORAGE_ENGINES"),
343344
("JUNK: GLOBAL-ONLY", "I_S.SESSION_VARIABLES", "DISCONNECT_ON_EXPIRED_PASSWORD"),
344345
("JUNK: GLOBAL-ONLY", "I_S.SESSION_VARIABLES", "ENFORCE_GTID_CONSISTENCY"),
345346
("JUNK: GLOBAL-ONLY", "I_S.SESSION_VARIABLES", "EVENT_SCHEDULER"),

mysql-test/suite/sys_vars/r/all_vars.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ There should be *no* long test name listed below:
1313
select variable_name as `There should be *no* variables listed below:` from t2
1414
left join t1 on variable_name=test_name where test_name is null ORDER BY variable_name;
1515
There should be *no* variables listed below:
16+
DISABLED_STORAGE_ENGINES
17+
DISABLED_STORAGE_ENGINES
1618
drop table t1;
1719
drop table t2;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--disabled_storage_engines=heap $EXAMPLE_PLUGIN_OPT
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#
2+
# WL#8594 - Provide an option to reject creation of user tables for specified
3+
# storage engines.
4+
#
5+
6+
# Test SQL statements 'CREATE [TEMPORARY] TABLE', 'ALTER TABLE ... ENGINE'
7+
# and 'CREATE/ALTER TABLESPACE' shall fail with the error "Storage engine
8+
# 'storage engine name' is disabled (Table creation is disallowed.)" for the
9+
# storage engines specified by disabled-storage-engine option.
10+
11+
--source include/have_example_plugin.inc
12+
--source include/not_embedded.inc
13+
14+
--ERROR ER_DISABLED_STORAGE_ENGINE
15+
CREATE TABLE t1(c1 int) ENGINE=HEAP;
16+
17+
CREATE TABLE t1 (c1 int) ENGINE=MYISAM;
18+
INSERT INTO t1 VALUES(1);
19+
20+
CREATE TABLESPACE tb1 ADD DATAFILE 't1.ibd' ENGINE=INNODB;
21+
CREATE TABLE tp1 (c1 int) PARTITION BY KEY (c1) PARTITIONS 1;
22+
23+
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
24+
--shutdown_server
25+
--source include/wait_until_disconnected.inc
26+
27+
# Restart server along with myisam storage engine disabled and check alter
28+
# table on existing myisam table t1 created above is allowed.
29+
--exec echo "restart: --disabled_storage_engines=innodb,myisam,heap,example" >$MYSQLTEST_VARDIR/tmp/mysqld.1.expect
30+
--enable_reconnect
31+
--source include/wait_until_connected_again.inc
32+
33+
SHOW VARIABLES LIKE 'disabled_storage_engines';
34+
SELECT * FROM t1;
35+
ALTER TABLE t1 ENGINE=MyISAM, ADD COLUMN c2 INT;
36+
ALTER TABLE t1 ADD COLUMN c3 INT;
37+
DROP TABLESPACE tb1;
38+
39+
--ERROR ER_DISABLED_STORAGE_ENGINE
40+
CREATE TABLE t2 LIKE t1;
41+
42+
--ERROR ER_DISABLED_STORAGE_ENGINE
43+
CREATE TABLE t2 AS SELECT * FROM t1;
44+
45+
--ERROR ER_DISABLED_STORAGE_ENGINE
46+
ALTER TABLE t1 ENGINE=InnoDB;
47+
48+
--ERROR ER_DISABLED_STORAGE_ENGINE
49+
ALTER TABLE t1 ENGINE=HEAP;
50+
51+
--ERROR ER_DISABLED_STORAGE_ENGINE
52+
CREATE TABLE t2(c1 int) ENGINE=INNODB SELECT c1 FROM t1;
53+
54+
--ERROR ER_DISABLED_STORAGE_ENGINE
55+
CREATE TABLE t2(c1 int) ENGINE=HEAP SELECT c1 FROM t1;
56+
57+
TRUNCATE TABLE t1;
58+
DROP TABLE t1;
59+
60+
--ERROR ER_DISABLED_STORAGE_ENGINE
61+
CREATE TABLESPACE t1 ADD DATAFILE 't1.ibd' ENGINE=INNODB;
62+
63+
--ERROR ER_DISABLED_STORAGE_ENGINE
64+
CREATE TABLESPACE t1 ADD DATAFILE 't1.ibd' ENGINE=HEAP;
65+
66+
--ERROR ER_DISABLED_STORAGE_ENGINE
67+
ALTER TABLESPACE ts ADD DATAFILE 'ts.ibd' ENGINE=INNODB;
68+
69+
--ERROR ER_DISABLED_STORAGE_ENGINE
70+
ALTER TABLESPACE ts ADD DATAFILE 'ts.ibd' ENGINE=HEAP;
71+
72+
--ERROR ER_DISABLED_STORAGE_ENGINE
73+
ALTER TABLESPACE ts ADD DATAFILE 'ts.ibd';
74+
75+
--ERROR ER_DISABLED_STORAGE_ENGINE
76+
CREATE TEMPORARY TABLE t1 (c1 int) ENGINE=INNODB;
77+
78+
--ERROR ER_DISABLED_STORAGE_ENGINE
79+
CREATE TEMPORARY TABLE t1 (c1 int) ENGINE=HEAP;
80+
81+
delimiter |;
82+
CREATE PROCEDURE p1()
83+
BEGIN
84+
CREATE TABLE t1 (c1 int) ENGINE=MYISAM;
85+
END |
86+
87+
delimiter ;|
88+
--ERROR ER_DISABLED_STORAGE_ENGINE
89+
CALL p1();
90+
DROP PROCEDURE p1;
91+
92+
--ERROR ER_DISABLED_STORAGE_ENGINE
93+
CREATE TABLE t1 (c1 int) PARTITION BY KEY (c1) PARTITIONS 1;
94+
95+
INSERT INTO tp1 VALUES(1);
96+
DROP TABLE tp1;
97+
# Check creation of table is disallowed under a dynamic storage plugin.
98+
--replace_regex /\.dll/.so/
99+
eval INSTALL PLUGIN example SONAME '$EXAMPLE_PLUGIN';
100+
101+
--ERROR ER_DISABLED_STORAGE_ENGINE
102+
CREATE TABLE t1(a int) ENGINE=EXAMPLE;
103+
UNINSTALL PLUGIN example;
104+
105+
# Reload the plugin and ensure table creation is disallowed.
106+
--replace_regex /\.dll/.so/
107+
eval INSTALL PLUGIN example SONAME '$EXAMPLE_PLUGIN';
108+
109+
--ERROR ER_DISABLED_STORAGE_ENGINE
110+
CREATE TABLE t1(a int) ENGINE=EXAMPLE;
111+
UNINSTALL PLUGIN example;
112+
113+
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect
114+
--shutdown_server
115+
--source include/wait_until_disconnected.inc
116+
117+
--exec echo "restart: --skip-grant-tables --disabled_storage_engines=innodb,myisam,heap,example" >$MYSQLTEST_VARDIR/tmp/mysqld.1.expect
118+
--enable_reconnect
119+
--source include/wait_until_connected_again.inc
120+
CREATE TABLE t1(a int) ENGINE=MYISAM;
121+
DROP TABLE t1;
122+
123+
--source include/restart_mysqld.inc

0 commit comments

Comments
 (0)