Skip to content

Commit 96eef56

Browse files
ssorumgarddahlerlend
authored andcommitted
WL#6391: Post-push fix.
Make sure we catch creation of tables like 'mysql.innodb_index_stats'. Must add explicit check for the sql comcode, since the meta data lock is not set to 'exclusive' at the point where this is checked during parsing.
1 parent 4eb5a79 commit 96eef56

File tree

4 files changed

+68
-10
lines changed

4 files changed

+68
-10
lines changed

mysql-test/r/dd_table_access.result

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ CREATE TABLE mysql.version (i INTEGER);
4646
ERROR HY000: Access to system table 'mysql.version' is rejected.
4747
CREATE TABLE new_tab LIKE mysql.version;
4848
ERROR HY000: Access to system table 'mysql.version' is rejected.
49+
CREATE TABLE new_tab SELECT * FROM mysql.version;
50+
ERROR HY000: Access to system table 'mysql.version' is rejected.
4951
ALTER TABLE mysql.version ADD COLUMN (new_col INTEGER);
5052
ERROR HY000: Access to system table 'mysql.version' is rejected.
5153
TRUNCATE TABLE mysql.version;
@@ -125,6 +127,8 @@ CREATE TABLE version (i INTEGER);
125127
ERROR HY000: Access to system table 'mysql.version' is rejected.
126128
CREATE TABLE new_tab LIKE version;
127129
ERROR HY000: Access to system table 'mysql.version' is rejected.
130+
CREATE TABLE new_tab SELECT * FROM version;
131+
ERROR HY000: Access to system table 'mysql.version' is rejected.
128132
ALTER TABLE version ADD COLUMN (new_col INTEGER);
129133
ERROR HY000: Access to system table 'mysql.version' is rejected.
130134
TRUNCATE TABLE version;
@@ -204,6 +208,8 @@ CREATE TABLE mysql.indexes (i INTEGER);
204208
ERROR HY000: Access to system table 'mysql.indexes' is rejected.
205209
CREATE TABLE new_tab LIKE mysql.indexes;
206210
ERROR HY000: Access to system table 'mysql.indexes' is rejected.
211+
CREATE TABLE new_tab SELECT * FROM mysql.indexes;
212+
ERROR HY000: Access to system table 'mysql.indexes' is rejected.
207213
ALTER TABLE mysql.indexes ADD COLUMN (new_col INTEGER);
208214
ERROR HY000: Access to system table 'mysql.indexes' is rejected.
209215
TRUNCATE TABLE mysql.indexes;
@@ -283,6 +289,8 @@ CREATE TABLE indexes (i INTEGER);
283289
ERROR HY000: Access to system table 'mysql.indexes' is rejected.
284290
CREATE TABLE new_tab LIKE indexes;
285291
ERROR HY000: Access to system table 'mysql.indexes' is rejected.
292+
CREATE TABLE new_tab SELECT * FROM indexes;
293+
ERROR HY000: Access to system table 'mysql.indexes' is rejected.
286294
ALTER TABLE indexes ADD COLUMN (new_col INTEGER);
287295
ERROR HY000: Access to system table 'mysql.indexes' is rejected.
288296
TRUNCATE TABLE indexes;
@@ -342,9 +350,27 @@ UPDATE mysql.innodb_index_stats SET stat_description='Updated';
342350
SELECT stat_description FROM mysql.innodb_index_stats LIMIT 1;
343351
stat_description
344352
Updated
345-
# Check that we may not DROP mysql.innodb_index_stats.
353+
# Check that we may not DROP or CREATE mysql.innodb_index_stats.
346354
DROP TABLE mysql.innodb_index_stats;
347355
ERROR HY000: Access to system table 'mysql.innodb_index_stats' is rejected.
356+
CREATE TABLE mysql.innodb_index_stats(i INTEGER);
357+
ERROR HY000: Access to system table 'mysql.innodb_index_stats' is rejected.
358+
# Check that we may CREATE FROM mysql.innodb_index_stats.
359+
CREATE TABLE t1 SELECT * FROM mysql.innodb_index_stats;
360+
DROP TABLE t1;
361+
# Check that we may CREATE LIKE mysql.innodb_index_stats.
362+
CREATE TABLE t1 LIKE mysql.innodb_index_stats;
363+
DROP TABLE t1;
364+
# Check access from stored programs.
365+
CREATE PROCEDURE ddse_access() CREATE TABLE mysql.innodb_index_stats(i INTEGER);
366+
ERROR HY000: Access to system table 'mysql.innodb_index_stats' is rejected.
367+
CREATE PROCEDURE ddse_access() DROP TABLE mysql.innodb_index_stats(i INTEGER);
368+
ERROR HY000: Access to system table 'mysql.innodb_index_stats' is rejected.
369+
# Check access from prepared statements.
370+
PREPARE ps FROM 'CREATE TABLE mysql.innodb_index_stats(i INTEGER)';;
371+
ERROR HY000: Access to system table 'mysql.innodb_index_stats' is rejected.
372+
PREPARE ps FROM 'DROP TABLE mysql.innodb_index_stats';;
373+
ERROR HY000: Access to system table 'mysql.innodb_index_stats' is rejected.
348374
# But ALTER and CHECK is allowed.
349375
ALTER TABLE mysql.innodb_index_stats COMMENT 'Altered';
350376
SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='innodb_index_stats';

mysql-test/t/dd_table_access.test

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,31 @@ if (!$TABLE)
4343
UPDATE mysql.innodb_index_stats SET stat_description='Updated';
4444
SELECT stat_description FROM mysql.innodb_index_stats LIMIT 1;
4545

46-
--echo # Check that we may not DROP mysql.innodb_index_stats.
46+
--echo # Check that we may not DROP or CREATE mysql.innodb_index_stats.
4747
--error ER_NO_SYSTEM_TABLE_ACCESS
4848
DROP TABLE mysql.innodb_index_stats;
49+
--error ER_NO_SYSTEM_TABLE_ACCESS
50+
CREATE TABLE mysql.innodb_index_stats(i INTEGER);
51+
52+
--echo # Check that we may CREATE FROM mysql.innodb_index_stats.
53+
CREATE TABLE t1 SELECT * FROM mysql.innodb_index_stats;
54+
DROP TABLE t1;
55+
56+
--echo # Check that we may CREATE LIKE mysql.innodb_index_stats.
57+
CREATE TABLE t1 LIKE mysql.innodb_index_stats;
58+
DROP TABLE t1;
59+
60+
--echo # Check access from stored programs.
61+
--error ER_NO_SYSTEM_TABLE_ACCESS
62+
CREATE PROCEDURE ddse_access() CREATE TABLE mysql.innodb_index_stats(i INTEGER);
63+
--error ER_NO_SYSTEM_TABLE_ACCESS
64+
CREATE PROCEDURE ddse_access() DROP TABLE mysql.innodb_index_stats(i INTEGER);
65+
66+
--echo # Check access from prepared statements.
67+
--error ER_NO_SYSTEM_TABLE_ACCESS
68+
--eval PREPARE ps FROM 'CREATE TABLE mysql.innodb_index_stats(i INTEGER)';
69+
--error ER_NO_SYSTEM_TABLE_ACCESS
70+
--eval PREPARE ps FROM 'DROP TABLE mysql.innodb_index_stats';
4971

5072
--echo # But ALTER and CHECK is allowed.
5173
ALTER TABLE mysql.innodb_index_stats COMMENT 'Altered';
@@ -89,6 +111,8 @@ if (!$TABLE)
89111
--error ER_NO_SYSTEM_TABLE_ACCESS
90112
--eval CREATE TABLE new_tab LIKE $TABLE
91113
--error ER_NO_SYSTEM_TABLE_ACCESS
114+
--eval CREATE TABLE new_tab SELECT * FROM $TABLE
115+
--error ER_NO_SYSTEM_TABLE_ACCESS
92116
--eval ALTER TABLE $TABLE ADD COLUMN (new_col INTEGER)
93117
--error ER_NO_SYSTEM_TABLE_ACCESS
94118
--eval TRUNCATE TABLE $TABLE

mysql-test/t/mysqldump.test

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,9 +1425,9 @@ insert into u1 values (4);
14251425
create view v1 (c1) as select * from t1;
14261426

14271427
# Backup should not fail for Bug#21527. Flush priviliges test begins.
1428-
# TODO: Allow dump/restore of innodb_index_stats/innodb_table_stats
1429-
# See Bug#22655287
1430-
--exec $MYSQL_DUMP --skip-comments --add-drop-table --flush-privileges --ignore-table=mysql.general_log --ignore-table=mysql.slow_log --ignore-table=mysql.innodb_index_stats --ignore-table=mysql.innodb_table_stats --databases mysqldump_myDB mysql > $MYSQLTEST_VARDIR/tmp/bug21527.sql
1428+
# TODO (Bug#22655287): mysqldump should skip the innodb_*_stats tables.
1429+
# Restoring the dump will cause errors (see below).
1430+
--exec $MYSQL_DUMP --skip-comments --add-drop-table --flush-privileges --ignore-table=mysql.general_log --ignore-table=mysql.slow_log --databases mysqldump_myDB mysql > $MYSQLTEST_VARDIR/tmp/bug21527.sql
14311431

14321432
# Clean up
14331433
connection root;
@@ -1445,7 +1445,11 @@ flush privileges;
14451445
--echo # Restore. Flush Privileges test ends.
14461446
--echo #
14471447

1448-
--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug21527.sql
1448+
# TODO (Bug#22655287): mysqldump should skip the innodb_*_stats tables.
1449+
# Restoring the dump will cause errors. Using '--force' will ignore
1450+
# errors and allow the dump to be restored. Fixing Bug#22655287 should
1451+
# allow the command below to succeed without '--force'.
1452+
--exec $MYSQL --force < $MYSQLTEST_VARDIR/tmp/bug21527.sql
14491453

14501454
# Do as a user
14511455
connection user1;

sql/sql_parse.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5701,18 +5701,22 @@ TABLE_LIST *SELECT_LEX::add_table_to_list(THD *thd,
57015701
// for the DDSE tables, since this is expected by the upgrade
57025702
// client. We must also allow DDL access for the initialize thread,
57035703
// since this thread is creating the I_S views.
5704+
// Note that at this point, the mdl request for CREATE TABLE is still
5705+
// MDL_SHARED, so we must explicitly check for SQLCOM_CREATE_TABLE.
57045706
const dd::Dictionary *dictionary= dd::get_dictionary();
57055707
if (dictionary && !dictionary->is_dd_table_access_allowed(
57065708
thd->is_dd_system_thread() || thd->is_initialize_system_thread(),
5707-
ptr->mdl_request.is_ddl_or_lock_tables_lock_request() &&
5708-
lex->sql_command != SQLCOM_CHECK &&
5709-
lex->sql_command != SQLCOM_ALTER_TABLE,
5709+
(ptr->mdl_request.is_ddl_or_lock_tables_lock_request() ||
5710+
(lex->sql_command == SQLCOM_CREATE_TABLE &&
5711+
ptr == lex->query_tables)) &&
5712+
lex->sql_command != SQLCOM_CHECK &&
5713+
lex->sql_command != SQLCOM_ALTER_TABLE,
57105714
ptr->db, ptr->db_length, ptr->table_name))
57115715
{
57125716
// TODO: Allow access to 'st_spatial_reference_systems' until
57135717
// dedicated DDL statements for adding reference systems are
57145718
// implemented.
5715-
// We must allow creation of the system views even for non-system
5719+
// We must allow creation of the system views even for non-system
57165720
// threads since this is expected by the mysql_upgrade utility.
57175721
if (!(lex->sql_command == SQLCOM_CREATE_VIEW &&
57185722
dd::get_dictionary()->is_system_view_name(

0 commit comments

Comments
 (0)