Skip to content

Commit a58bf5e

Browse files
committed
WL#6391: Hide DD tables.
This worklog prohibits access to the internal tables of the transactional data dictionary (DD). The worklog implements the following main changes: 1. Remove unused data structures and plugin usage. In particular, please note that the 'system_database()' handlerton function has been removed. 2. Prohibit access for usage of DD tables from: - SQL statements. - Foreign key constraints. - Stored programs. - Replication (also cross version). Access is accepted if the thread executing the statement is a DD system thread. For external threads, i.e., representing an external client, access is accepted if the table is a DDSE table (e.g. the 'innodb_*_stats' tables), and the statement is DML. 3. Add a debug flag 'skip_dd_table_access_check' to allow DD table access in debug builds. Rewrite tests to set this flag when needing access to the DD tables. Please note that great care must be taken when this flag is used. If using DML to update the contents of the DD tables directly, without any corresponding updates in the storage engine or DD cache, invariants that the server expectes to hold will be broken, and a malfunctioning server is to be expected. The same goes for DDL; with a change in the definitions of the DD tables, it is to be expected that the server will not work as intended. 4. Rewrite tests that currently access DD tables to set the debug flag above. Separate out specific parts of tests to only be run on debug builds, if the test previously could run on non-debug builds as well. 5. Take into account that the access check mechanism may be invoked from the unit tests; check that the Dictionary instance exists before calling it. TODO: Dependencies on other worklogs: 1. Remove exception regarding queries against the st_spatial_refrerence_systems table (WL#9059). 2. Prohibit access to altering or dropping the system tablespace (WL#7141).
1 parent 361527a commit a58bf5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1472
-679
lines changed

mysql-test/include/dd_schema_definition.inc renamed to mysql-test/include/dd_schema_definition_debug.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
# definitions of the DD tables need to be updated to match
88
# the old test results."
99

10+
--source include/have_debug.inc
11+
1012
use mysql;
1113

14+
SET SESSION debug= '+d,skip_dd_table_access_check';
15+
1216
# The DD database id
1317
let $dd_schema_id= `SELECT id FROM schemata
1418
WHERE name= 'mysql'`;
@@ -75,3 +79,5 @@ eval SELECT * FROM indexes
7579
eval SELECT * FROM index_column_usage
7680
WHERE index_id IN ($dd_index_ids)
7781
ORDER BY index_id, column_id;
82+
83+
SET SESSION debug= '-d,skip_dd_table_access_check';

mysql-test/r/audit_plugin_2.result

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,11 @@ SET @@null_audit_event_order_check = 'MYSQL_AUDIT_COMMAND_START;command_id="<exp
16251625
'MYSQL_AUDIT_PARSE_POSTPARSE;;;'
16261626
'MYSQL_AUDIT_GENERAL_LOG;;;'
16271627
'MYSQL_AUDIT_QUERY_START;sql_command_id="0";;'
1628+
'MYSQL_AUDIT_GENERAL_ERROR;;;'
1629+
'MYSQL_AUDIT_GENERAL_ERROR;;;'
1630+
'MYSQL_AUDIT_GENERAL_ERROR;;;'
1631+
'MYSQL_AUDIT_GENERAL_ERROR;;;'
1632+
'MYSQL_AUDIT_GENERAL_ERROR;;;'
16281633
'MYSQL_AUDIT_QUERY_STATUS_END;sql_command_id="0";;'
16291634
'MYSQL_AUDIT_GENERAL_RESULT;;;'
16301635
'MYSQL_AUDIT_GENERAL_STATUS;;;'

mysql-test/r/dd_bootstrap.result

Lines changed: 30 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,49 @@
1-
# Preparation: Shut server down.
2-
#
3-
# 1. Try restart after setting an invalid version.
4-
# ------------------------------------------------
5-
# 1.1 Create bootstrap file.
6-
# 1.2 First start the server with --initialize, and update the version.
7-
# 1.3 Restart the server against DDIR - should fail.
8-
# 1.4 Look for warning.
9-
# Dictionary version warning found 1 times.
10-
# 1.5 Delete bootstrap file, log file and datadir.
111
#
12-
# 2. Try restart after dropping the version table.
13-
# ------------------------------------------------
14-
# 2.1 Create bootstrap file.
15-
# 2.2 First start the server with --initialize, and drop the version table: Should fail.
16-
# 2.3 Look for error.
17-
# Drop table error found 1 times.
18-
# 2.4 Restart the server against DDIR - should fail.
19-
# 2.5 Look for error.
20-
# Data Dictionary initialization error found 1 times.
21-
# 2.6 Delete bootstrap file, log file and datadir.
2+
# This file contains bootstrap test cases that do not
3+
# need to be run with a debug build. See also the
4+
# test file 'dd_bootstrap_debug.test' for debug
5+
# test cases.
226
#
23-
# 3. Try restart after dropping the tables table.
24-
# -----------------------------------------------
25-
# 3.1 Create bootstrap file.
26-
# 3.2 First start the server with --initialize, and drop the tables table: Should fail.
27-
# 3.3 Look for error.
28-
# Drop table error found 1 times.
29-
# 3.4 Restart the server against DDIR - should fail.
30-
# 3.5 Look for error.
31-
# Data Dictionary initialization error found 1 times.
32-
# 3.6 Delete bootstrap file, log file and datadir.
7+
# Preparation: Shut server down.
338
#
34-
# 4. Try restart after dropping the time_zone_transition_type table.
9+
# 1. Try restart after dropping the time_zone_transition_type table.
3510
# ------------------------------------------------------------------
36-
# 4.1 Create bootstrap file.
37-
# 4.2 First start the server with --initialize, and drop the time_zone_transition_type table.
38-
# 4.3 Restart the server against DDIR - should succeed.
39-
# 4.4 Shut server down.
40-
# 4.5 Look for warning.
11+
# 1.1 Create bootstrap file.
12+
# 1.2 First start the server with --initialize, and drop the time_zone_transition_type table.
13+
# 1.3 Restart the server against DDIR - should succeed.
14+
# 1.4 Shut server down.
15+
# 1.5 Look for warning.
4116
# Time zone table warning found 1 times.
42-
# 4.6 Delete bootstrap file, log file and datadir.
17+
# 1.6 Delete bootstrap file, log file and datadir.
4318
#
44-
# 5. Try restart after deleting the version tablespace.
19+
# 2. Try restart after deleting the version tablespace.
4520
# -----------------------------------------------------
46-
# 5.1 First start the server with --initialize.
47-
# 5.2 Delete the physical tablespace file for mysql.version.
48-
# 5.3 Restart the server against DDIR - should fail.
49-
# 5.4 Look for error.
21+
# 2.1 First start the server with --initialize.
22+
# 2.2 Delete the physical tablespace file for mysql.version.
23+
# 2.3 Restart the server against DDIR - should fail.
24+
# 2.4 Look for error.
5025
# Tablespace error found 1 times.
51-
# 5.5 Delete log file and datadir.
52-
#
53-
# 6. Try restart after altering the schemata table.
54-
# -------------------------------------------------
55-
# 6.1 Create bootstrap file.
56-
# 6.2 First start the server with --initialize, and alter the schemata table.
57-
# 6.3 Restart the server against DDIR.
58-
# 6.4 Connect as root.
59-
# 6.5 Verify that the modified table is present.
60-
SELECT comment FROM mysql.tables WHERE name='schemata';
61-
comment
62-
Altered table
63-
# 6.6 Shut server down.
64-
# 6.7 Close the test connection.
65-
# 6.8 Delete bootstrap file, log file and datadir.
26+
# 2.5 Delete log file and datadir.
6627
#
67-
# 7. Try restart on a non-existing datadir.
28+
# 3. Try restart on a non-existing datadir.
6829
# -----------------------------------------
69-
# 7.1 Restart the server against non-existing DDIR - should fail.
70-
# 7.2 Look for error.
30+
# 3.1 Restart the server against non-existing DDIR - should fail.
31+
# 3.2 Look for error.
7132
# Datadir error found 1 times.
72-
# 7.3 Delete log file and datadir.
33+
# 3.3 Delete log file and datadir.
7334
#
74-
# 8. Try restart on an empty datadir (non-existing mysql dir).
35+
# 4. Try restart on an empty datadir (non-existing mysql dir).
7536
# ------------------------------------------------------------
76-
# 8.1 Restart the server against existing but empty DDIR - should fail.
77-
# 8.2 Look for error.
37+
# 4.1 Restart the server against existing but empty DDIR - should fail.
38+
# 4.2 Look for error.
7839
# InnoDB file open error found 1 times.
79-
# 8.3 Delete log file and datadir.
40+
# 4.3 Delete log file and datadir.
8041
#
81-
# 9. Try restart on an empty mysql dir.
42+
# 5. Try restart on an empty mysql dir.
8243
# -------------------------------------
83-
# 9.1 Restart the server against existing but empty mysql dir - should fail.
84-
# 9.2 Look for error.
44+
# 5.1 Restart the server against existing but empty mysql dir - should fail.
45+
# 5.2 Look for error.
8546
# InnoDB file open error found 1 times.
86-
# 9.3 Delete log file and datadir.
47+
# 5.3 Delete log file and datadir.
8748
#
8849
# Cleanup: Restarting the server against default datadir.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
# This file contains bootstrap test cases that
3+
# need to be run with a debug build. See also the
4+
# test file 'dd_bootstrap.test' for test cases
5+
# that can be run with a non-debug server build.
6+
#
7+
# Preparation: Shut server down.
8+
#
9+
# 1. Try restart after setting an invalid version.
10+
# ------------------------------------------------
11+
# 1.1 Create bootstrap file.
12+
# 1.2 First start the server with --initialize, and update the version.
13+
# 1.3 Restart the server against DDIR - should fail.
14+
# 1.4 Look for warning.
15+
# Dictionary version warning found 1 times.
16+
# 1.5 Delete bootstrap file, log file and datadir.
17+
#
18+
# 2. Try restart after dropping the version table.
19+
# ------------------------------------------------
20+
# 2.1 Create bootstrap file.
21+
# 2.2 First start the server with --initialize, and drop the version table: Should fail.
22+
# 2.3 Look for error.
23+
# Drop table error found 1 times.
24+
# 2.4 Restart the server against DDIR - should fail.
25+
# 2.5 Look for error.
26+
# Data Dictionary initialization error found 1 times.
27+
# 2.6 Delete bootstrap file, log file and datadir.
28+
#
29+
# 3. Try restart after dropping the tables table.
30+
# -----------------------------------------------
31+
# 3.1 Create bootstrap file.
32+
# 3.2 First start the server with --initialize, and drop the tables table: Should fail.
33+
# 3.3 Look for error.
34+
# Drop table error found 1 times.
35+
# 3.4 Restart the server against DDIR - should fail.
36+
# 3.5 Look for error.
37+
# Data Dictionary initialization error found 1 times.
38+
# 3.6 Delete bootstrap file, log file and datadir.
39+
#
40+
# 4. Try restart after altering the schemata table.
41+
# -------------------------------------------------
42+
# 4.1 Create bootstrap file.
43+
# 4.2 First start the server with --initialize, and alter the schemata table.
44+
# 4.3 Restart the server against DDIR.
45+
# 4.4 Connect as root.
46+
# 4.5 Verify that the modified table is present.
47+
SET SESSION debug= '+d,skip_dd_table_access_check';
48+
SELECT comment FROM mysql.tables WHERE name='schemata';
49+
comment
50+
Altered table
51+
SET SESSION debug= '-d,skip_dd_table_access_check';
52+
# 4.6 Shut server down.
53+
# 4.7 Close the test connection.
54+
# 4.8 Delete bootstrap file, log file and datadir.
55+
#
56+
# Cleanup: Restarting the server against default datadir.

mysql-test/r/dd_debug.result

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ SET DEBUG= '-d, fail_while_dropping_dd_object';
8080
# will be addressed in WL#7743.
8181
DROP SCHEMA s1;
8282
ERROR HY000: Can't drop database 's1'; database doesn't exist
83+
SET SESSION debug= '+d,skip_dd_table_access_check';
8384
SELECT COUNT(*) FROM mysql.schemata WHERE name LIKE 's1';
8485
COUNT(*)
8586
1
@@ -88,6 +89,7 @@ DROP SCHEMA s1;
8889
SELECT COUNT(*) FROM mysql.schemata WHERE name LIKE 's1';
8990
COUNT(*)
9091
0
92+
SET SESSION debug= '-d,skip_dd_table_access_check';
9193
###################################################################
9294
#
9395
# 2. Tables
@@ -184,6 +186,7 @@ SET DEBUG= '-d, fail_while_dropping_dd_object';
184186
# ts1 in mysql.tablespaces.
185187
DROP TABLESPACE ts1;
186188
ERROR HY000: Failed to drop TABLESPACE ts1
189+
SET SESSION debug= '+d,skip_dd_table_access_check';
187190
SELECT COUNT(*) FROM mysql.tablespaces WHERE name LIKE 'ts1';
188191
COUNT(*)
189192
1
@@ -195,4 +198,5 @@ DROP TABLESPACE ts1;
195198
SELECT COUNT(*) FROM mysql.tablespaces WHERE name LIKE 'ts1';
196199
COUNT(*)
197200
0
201+
SET SESSION debug= '-d,skip_dd_table_access_check';
198202
###################################################################

mysql-test/r/dd_is_concurrency.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
SET GLOBAL debug= '+d,skip_dd_table_access_check';
12
use test;
23
CREATE VIEW not_system_view AS
34
SELECT name as table_name, mysql_version_id FROM mysql.tables;
@@ -129,3 +130,4 @@ connection con1;
129130
disconnect con1;
130131
connection default;
131132
DROP VIEW not_system_view;
133+
SET GLOBAL debug= '-d,skip_dd_table_access_check';

mysql-test/r/dd_schema_definition_ci.result renamed to mysql-test/r/dd_schema_definition_debug_ci.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use mysql;
2+
SET SESSION debug= '+d,skip_dd_table_access_check';
23
#
34
# Subset of definitions from tables, not including
45
# timestamps, partitioning, view definitions and
@@ -446,3 +447,4 @@ index_id ordinal_position column_id length order hidden
446447
81 1 281 8 ASC 0
447448
82 1 282 192 ASC 0
448449
83 1 283 8 ASC 0
450+
SET SESSION debug= '-d,skip_dd_table_access_check';

mysql-test/r/dd_schema_definition_cs.result renamed to mysql-test/r/dd_schema_definition_debug_cs.result

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use mysql;
2+
SET SESSION debug= '+d,skip_dd_table_access_check';
23
#
34
# Subset of definitions from tables, not including
45
# timestamps, partitioning, view definitions and
@@ -446,3 +447,4 @@ index_id ordinal_position column_id length order hidden
446447
81 1 281 8 ASC 0
447448
82 1 282 192 ASC 0
448449
83 1 283 8 ASC 0
450+
SET SESSION debug= '-d,skip_dd_table_access_check';

0 commit comments

Comments
 (0)