Skip to content

Commit

Permalink
MDEV-22343 Remove SYS_TABLESPACES and SYS_DATAFILES
Browse files Browse the repository at this point in the history
The InnoDB internal tables SYS_TABLESPACES and SYS_DATAFILES as well as the
INFORMATION_SCHEMA views INNODB_SYS_TABLESPACES and INNODB_SYS_DATAFILES
were introduced in MySQL 5.6 for no good reason in
mysql/mysql-server/commit/e9255a22ef16d612a8076bc0b34002bc5a784627
when the InnoDB support for the DATA DIRECTORY attribute was introduced.

The file system should be the authoritative source of information on files.
Storing information about file system paths in the file system (symlinks,
or even the .isl files that were unfortunately chosen as the solution) is
sufficient. If information is additionally stored in some hidden tables
inside the InnoDB system tablespace, everything unnecessarily becomes
more complicated, because more copies of data mean more opportunity
for the copies to be out of sync, and because modifying the data in
the system tablespace in the desired way might not be possible at all
without modifying the InnoDB source code. So, the copy in the system
tablespace basically is a redundant, non-authoritative source of
information.

We will stop creating or accessing the system tables SYS_TABLESPACES
and SYS_DATAFILES.

We will also remove the view
INFORMATION_SCHEMA.INNODB_SYS_DATAFILES along with SYS_DATAFILES.

The view
INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES will be repurposed
to directly reflect fil_system.space_list. The column
PAGE_SIZE, which would always contain the value of
the GLOBAL read-only variable innodb_page_size, is
removed. The column ZIP_PAGE_SIZE, which would actually
contain the physical page size of a page, is renamed to
PAGE_SIZE. Finally, a new column FILENAME is added, as a
replacement of SYS_DATAFILES.PATH.

This will also
address MDEV-21801 (files that were created before upgrading
to MySQL 5.6 or MariaDB 10.0 or later were never registered
in SYS_TABLESPACES or SYS_DATAFILES) and
MDEV-21801 (information about the system tablespace is not stored
in SYS_TABLESPACES or SYS_DATAFILES).
  • Loading branch information
dr-m committed Nov 11, 2020
1 parent 9bc874a commit 5407117
Show file tree
Hide file tree
Showing 45 changed files with 275 additions and 1,690 deletions.
18 changes: 8 additions & 10 deletions mysql-test/suite/innodb/include/show_i_s_tablespaces.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
--disable_query_log
--replace_regex /#P#/#p#/ /#SP#/#sp#/
--replace_result ./ MYSQLD_DATADIR/ $MYSQLD_DATADIR/ MYSQLD_DATADIR/ $MYSQLD_DATADIR MYSQLD_DATADIR/ $MYSQL_TMP_DIR MYSQL_TMP_DIR $INNODB_PAGE_SIZE DEFAULT
SELECT s.name 'Space_Name',
s.page_size 'Page_Size',
s.zip_page_size 'Zip_Size',
d.path 'Path'
FROM information_schema.innodb_sys_tablespaces s,
information_schema.innodb_sys_datafiles d
WHERE s.space = d.space
AND s.name NOT LIKE 'mysql/%'
AND s.name NOT LIKE '%/#sql-ib%'
ORDER BY s.space;
SELECT name 'Space_Name',
@@GLOBAL.innodb_page_size 'Page_Size',
page_size 'Zip_Size',
filename 'Path'
FROM information_schema.innodb_sys_tablespaces
WHERE name != 'innodb_system'
AND name NOT LIKE 'mysql/%' AND name NOT LIKE '%/#sql-ib%'
ORDER BY space;
--enable_query_log
9 changes: 0 additions & 9 deletions mysql-test/suite/innodb/r/information_schema_grants.result
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ create sql security invoker view i_mutexes as select * from information_schema.i
create sql security definer view d_mutexes as select * from information_schema.innodb_mutexes;
create sql security invoker view i_sys_columns as select * from information_schema.innodb_sys_columns;
create sql security definer view d_sys_columns as select * from information_schema.innodb_sys_columns;
create sql security invoker view i_sys_datafiles as select * from information_schema.innodb_sys_datafiles;
create sql security definer view d_sys_datafiles as select * from information_schema.innodb_sys_datafiles;
create sql security invoker view i_sys_fields as select * from information_schema.innodb_sys_fields;
create sql security definer view d_sys_fields as select * from information_schema.innodb_sys_fields;
create sql security invoker view i_sys_foreign as select * from information_schema.innodb_sys_foreign;
Expand Down Expand Up @@ -205,13 +203,6 @@ ERROR 42000: Access denied; you need (at least one of) the PROCESS privilege(s)
select count(*) > -1 from d_sys_columns;
count(*) > -1
1
select count(*) > -1 from information_schema.innodb_sys_datafiles;
ERROR 42000: Access denied; you need (at least one of) the PROCESS privilege(s) for this operation
select count(*) > -1 from i_sys_datafiles;
ERROR 42000: Access denied; you need (at least one of) the PROCESS privilege(s) for this operation
select count(*) > -1 from d_sys_datafiles;
count(*) > -1
1
select count(*) > -1 from information_schema.innodb_sys_fields;
ERROR 42000: Access denied; you need (at least one of) the PROCESS privilege(s) for this operation
select count(*) > -1 from i_sys_fields;
Expand Down
10 changes: 0 additions & 10 deletions mysql-test/suite/innodb/r/innodb-index-online-fk.result
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,8 @@ test/child a1
test/child a2
SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
NAME
SYS_DATAFILES
SYS_FOREIGN
SYS_FOREIGN_COLS
SYS_TABLESPACES
SYS_VIRTUAL
mysql/innodb_index_stats
mysql/innodb_table_stats
Expand Down Expand Up @@ -312,10 +310,8 @@ test/child a1
test/child a2
SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
NAME
SYS_DATAFILES
SYS_FOREIGN
SYS_FOREIGN_COLS
SYS_TABLESPACES
SYS_VIRTUAL
mysql/innodb_index_stats
mysql/innodb_table_stats
Expand All @@ -340,10 +336,8 @@ test/child a2
test/child a3
SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
NAME
SYS_DATAFILES
SYS_FOREIGN
SYS_FOREIGN_COLS
SYS_TABLESPACES
SYS_VIRTUAL
mysql/innodb_index_stats
mysql/innodb_table_stats
Expand Down Expand Up @@ -379,10 +373,8 @@ test/child a1
test/child a2
SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
NAME
SYS_DATAFILES
SYS_FOREIGN
SYS_FOREIGN_COLS
SYS_TABLESPACES
SYS_VIRTUAL
mysql/innodb_index_stats
mysql/innodb_table_stats
Expand Down Expand Up @@ -416,10 +408,8 @@ test/child a2
test/child a3
SELECT NAME FROM information_schema.INNODB_SYS_TABLES;
NAME
SYS_DATAFILES
SYS_FOREIGN
SYS_FOREIGN_COLS
SYS_TABLESPACES
SYS_VIRTUAL
mysql/innodb_index_stats
mysql/innodb_table_stats
Expand Down
51 changes: 19 additions & 32 deletions mysql-test/suite/innodb/r/innodb-system-table-view.result
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ WHERE table_id NOT IN (@table_stats_id, @index_stats_id) ORDER BY table_id;
TABLE_ID NAME FLAG N_COLS SPACE ROW_FORMAT ZIP_PAGE_SIZE SPACE_TYPE
11 SYS_FOREIGN 0 7 0 Redundant 0 System
12 SYS_FOREIGN_COLS 0 7 0 Redundant 0 System
13 SYS_TABLESPACES 0 6 0 Redundant 0 System
14 SYS_DATAFILES 0 5 0 Redundant 0 System
15 SYS_VIRTUAL 0 6 0 Redundant 0 System
18 mysql/transaction_registry 33 8 3 Dynamic 0 Single
13 SYS_VIRTUAL 0 6 0 Redundant 0 System
16 mysql/transaction_registry 33 8 3 Dynamic 0 Single
SELECT table_id,pos,mtype,prtype,len,name
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS
WHERE table_id NOT IN (@table_stats_id, @index_stats_id)
Expand All @@ -26,28 +24,21 @@ table_id pos mtype prtype len name
12 1 6 0 4 POS
12 2 1 524292 0 FOR_COL_NAME
12 3 1 524292 0 REF_COL_NAME
13 0 6 0 4 SPACE
13 1 1 524292 0 NAME
13 2 6 0 4 FLAGS
14 0 6 0 4 SPACE
14 1 1 524292 0 PATH
15 0 6 0 8 TABLE_ID
15 1 6 0 4 POS
15 2 6 0 4 BASE_POS
18 0 6 1800 8 transaction_id
18 1 6 1800 8 commit_id
18 2 3 526087 7 begin_timestamp
18 3 3 526087 7 commit_timestamp
18 4 6 1022 1 isolation_level
13 0 6 0 8 TABLE_ID
13 1 6 0 4 POS
13 2 6 0 4 BASE_POS
16 0 6 1800 8 transaction_id
16 1 6 1800 8 commit_id
16 2 3 526087 7 begin_timestamp
16 3 3 526087 7 commit_timestamp
16 4 6 1022 1 isolation_level
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_INDEXES
WHERE table_id NOT IN (@table_stats_id, @index_stats_id) ORDER BY index_id;
INDEX_ID NAME TABLE_ID TYPE N_FIELDS PAGE_NO SPACE MERGE_THRESHOLD
# ID_IND # 3 1 # # 50
# FOR_IND # 0 1 # # 50
# REF_IND # 0 1 # # 50
# ID_IND # 3 2 # # 50
# SYS_TABLESPACES_SPACE # 3 1 # # 50
# SYS_DATAFILES_SPACE # 3 1 # # 50
# BASE_IDX # 3 3 # # 50
# PRIMARY # 3 1 # # 50
# commit_id # 2 1 # # 50
Expand All @@ -62,16 +53,14 @@ index_id pos name
13 0 REF_NAME
14 0 ID
14 1 POS
15 0 SPACE
16 0 SPACE
17 0 TABLE_ID
17 1 POS
17 2 BASE_POS
20 0 transaction_id
21 0 commit_id
22 0 begin_timestamp
23 0 commit_timestamp
23 1 transaction_id
15 0 TABLE_ID
15 1 POS
15 2 BASE_POS
18 0 transaction_id
19 0 commit_id
20 0 begin_timestamp
21 0 commit_timestamp
21 1 transaction_id
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
ID FOR_NAME REF_NAME N_COLS TYPE
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
Expand All @@ -95,7 +84,7 @@ test/t_dynamic DEFAULT DEFAULT MYSQLD_DATADIR/test/t_dynamic.ibd
DROP TABLE t_redundant, t_compact, t_compressed, t_dynamic;
SELECT count(*) FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESTATS;
count(*)
8
6
CREATE TABLE parent (id INT NOT NULL,
PRIMARY KEY (id)) ENGINE=INNODB;
CREATE TABLE child (id INT, parent_id INT,
Expand All @@ -119,10 +108,8 @@ test/parent 1 1
SELECT NAME, FLAG, N_COLS FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES
WHERE name NOT LIKE 'sys/%';
NAME FLAG N_COLS
SYS_DATAFILES 0 5
SYS_FOREIGN 0 7
SYS_FOREIGN_COLS 0 7
SYS_TABLESPACES 0 6
SYS_VIRTUAL 0 6
mysql/innodb_index_stats 33 11
mysql/innodb_table_stats 33 9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ select * from information_schema.innodb_buffer_page_lru;
POOL_ID LRU_POSITION SPACE PAGE_NUMBER PAGE_TYPE FLUSH_TYPE FIX_COUNT IS_HASHED NEWEST_MODIFICATION OLDEST_MODIFICATION ACCESS_TIME TABLE_NAME INDEX_NAME NUMBER_RECORDS DATA_SIZE COMPRESSED_SIZE COMPRESSED IO_FIX IS_OLD FREE_PAGE_CLOCK
Warnings:
Warning 1012 InnoDB: SELECTing from INFORMATION_SCHEMA.innodb_buffer_page_lru but the InnoDB storage engine is not installed
select * from information_schema.innodb_buffer_stats;
select * from information_schema.innodb_sys_tables;
TABLE_ID NAME FLAG N_COLS SPACE ROW_FORMAT ZIP_PAGE_SIZE SPACE_TYPE
Warnings:
Expand Down Expand Up @@ -366,14 +365,9 @@ ID FOR_COL_NAME REF_COL_NAME POS
Warnings:
Warning 1012 InnoDB: SELECTing from INFORMATION_SCHEMA.innodb_sys_foreign_cols but the InnoDB storage engine is not installed
select * from information_schema.innodb_sys_tablespaces;
SPACE NAME FLAG ROW_FORMAT PAGE_SIZE ZIP_PAGE_SIZE FS_BLOCK_SIZE FILE_SIZE ALLOCATED_SIZE
SPACE NAME FLAG ROW_FORMAT PAGE_SIZE FILENAME FS_BLOCK_SIZE FILE_SIZE ALLOCATED_SIZE
Warnings:
Warning 1012 InnoDB: SELECTing from INFORMATION_SCHEMA.innodb_sys_tablespaces but the InnoDB storage engine is not installed
select * from information_schema.innodb_sys_datafiles;
SPACE PATH
Warnings:
Warning 1012 InnoDB: SELECTing from INFORMATION_SCHEMA.innodb_sys_datafiles but the InnoDB storage engine is not installed
select * from information_schema.innodb_changed_pages;
select * from information_schema.innodb_tablespaces_encryption;
SPACE NAME ENCRYPTION_SCHEME KEYSERVER_REQUESTS MIN_KEY_VERSION CURRENT_KEY_VERSION KEY_ROTATION_PAGE_NUMBER KEY_ROTATION_MAX_PAGE_NUMBER CURRENT_KEY_ID ROTATING_OR_FLUSHING
Warnings:
Expand Down
8 changes: 4 additions & 4 deletions mysql-test/suite/innodb/r/rename_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ CREATE DATABASE test_jfg;
CREATE DATABASE test_jfg2;
CREATE TABLE test_jfg.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
RENAME TABLE test_jfg.test TO test_jfg2.test;
SELECT REPLACE(path,'\\','/') path
FROM INFORMATION_SCHEMA.INNODB_SYS_DATAFILES WHERE PATH LIKE '%test%';
SELECT REPLACE(filename,'\\','/') path
FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE filename LIKE '%test%';
path
./test_jfg2/test.ibd
DROP DATABASE test_jfg;
Expand All @@ -13,8 +13,8 @@ CREATE DATABASE abc_def;
CREATE DATABASE abc_def2;
CREATE TABLE abc_def.test (a int unsigned PRIMARY KEY) ENGINE=InnoDB;
RENAME TABLE abc_def.test TO abc_def2.test1;
SELECT REPLACE(path,'\\','/') path
FROM INFORMATION_SCHEMA.INNODB_SYS_DATAFILES WHERE PATH LIKE '%test%';
SELECT REPLACE(filename,'\\','/') path
FROM INFORMATION_SCHEMA.INNODB_SYS_TABLESPACES WHERE filename LIKE '%test%';
path
./abc_def2/test1.ibd
DROP DATABASE abc_def;
Expand Down
74 changes: 26 additions & 48 deletions mysql-test/suite/innodb/r/table_flags,32k,debug.rdiff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- suite/innodb/r/table_flags.result
+++ suite/innodb/r/table_flags,32k,debug.reject
@@ -5,96 +5,98 @@
@@ -6,6 +6,8 @@
SET innodb_strict_mode=OFF;
CREATE TABLE tz(a INT PRIMARY KEY)ENGINE=InnoDB ROW_FORMAT=COMPRESSED
KEY_BLOCK_SIZE=1;
Expand All @@ -9,23 +9,13 @@
SET innodb_strict_mode=ON;
CREATE TABLE tp(a INT PRIMARY KEY)ENGINE=InnoDB ROW_FORMAT=DYNAMIC
PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9;
@@ -11,71 +11,71 @@
PAGE_COMPRESSED=1 PAGE_COMPRESSION_LEVEL=9;
SYS_TABLES clustered index root page (8):
N_RECS=10; LEVEL=0; INDEX_ID=0x0000000000000001
-header=0x01000003016e (NAME=0x696e66696d756d00)
-header=0x00002815008d (NAME='SYS_DATAFILES',
+header=0x0100000301bf (NAME=0x696e66696d756d00)
+header=0x0000301500de (NAME='SYS_DATAFILES',
DB_TRX_ID=0x000000000000,
DB_ROLL_PTR=0x80000000000000,
- ID=0x000000000000000e,
+ ID=0x000000000000000f,
N_COLS=0x00000002,
TYPE=0x00000001,
MIX_ID=0x0000000000000000,
MIX_LEN=0x00000040,
CLUSTER_NAME=NULL(0 bytes),
SPACE=0x00000000)
N_RECS=8; LEVEL=0; INDEX_ID=0x0000000000000001
-header=0x01000003008d (NAME=0x696e66696d756d00)
-header=0x0000101500d5 (NAME='SYS_FOREIGN',
+header=0x0100000300de (NAME=0x696e66696d756d00)
+header=0x000018150126 (NAME='SYS_FOREIGN',
DB_TRX_ID=0x000000000000,
DB_ROLL_PTR=0x80000000000000,
Expand All @@ -49,8 +39,8 @@
MIX_LEN=0x00000040,
CLUSTER_NAME=NULL(0 bytes),
SPACE=0x00000000)
-header=0x0400201501b8 (NAME='SYS_TABLESPACES',
+header=0x040028150209 (NAME='SYS_TABLESPACES',
-header=0x0000201501ae (NAME='SYS_VIRTUAL',
+header=0x0000281501bb (NAME='SYS_VIRTUAL',
DB_TRX_ID=0x000000000000,
DB_ROLL_PTR=0x80000000000000,
- ID=0x000000000000000d,
Expand All @@ -61,69 +51,57 @@
MIX_LEN=0x00000040,
CLUSTER_NAME=NULL(0 bytes),
SPACE=0x00000000)
-header=0x000030150244 (NAME='SYS_VIRTUAL',
+header=0x000038150251 (NAME='SYS_VIRTUAL',
-header=0x0400301501f2 (NAME='test/tc',
+header=0x0400301501ff (NAME='test/tc',
DB_TRX_ID=0x000000000000,
DB_ROLL_PTR=0x80000000000000,
- ID=0x000000000000000f,
+ ID=0x0000000000000010,
N_COLS=0x00000003,
TYPE=0x00000001,
MIX_ID=0x0000000000000000,
MIX_LEN=0x00000040,
CLUSTER_NAME=NULL(0 bytes),
SPACE=0x00000000)
-header=0x000040150288 (NAME='test/tc',
+header=0x000040150295 (NAME='test/tc',
DB_TRX_ID=0x000000000000,
DB_ROLL_PTR=0x80000000000000,
- ID=0x0000000000000011,
+ ID=0x0000000000000012,
N_COLS=0x80000001,
TYPE=0x00000001,
MIX_ID=0x0000000000000000,
MIX_LEN=0x00000050,
CLUSTER_NAME=NULL(0 bytes),
SPACE=0x00000002)
-header=0x000048150310 (NAME='test/td',
+header=0x00004815031d (NAME='test/td',
-header=0x00003815027a (NAME='test/td',
+header=0x000038150287 (NAME='test/td',
DB_TRX_ID=0x000000000000,
DB_ROLL_PTR=0x80000000000000,
- ID=0x0000000000000012,
+ ID=0x0000000000000013,
- ID=0x0000000000000010,
+ ID=0x0000000000000011,
N_COLS=0x80000001,
TYPE=0x00000021,
MIX_ID=0x0000000000000000,
MIX_LEN=0x00000050,
CLUSTER_NAME=NULL(0 bytes),
SPACE=0x00000003)
-header=0x000058150200 (NAME='test/tp',
+header=0x00005815008d (NAME='test/tp',
-header=0x00004815016a (NAME='test/tp',
+header=0x00004815008d (NAME='test/tp',
DB_TRX_ID=0x000000000000,
DB_ROLL_PTR=0x80000000000000,
- ID=0x0000000000000014,
+ ID=0x0000000000000015,
- ID=0x0000000000000012,
+ ID=0x0000000000000013,
N_COLS=0x80000001,
TYPE=0x000009a1,
MIX_ID=0x0000000000000000,
MIX_LEN=0x00000050,
CLUSTER_NAME=NULL(0 bytes),
SPACE=0x00000005)
-header=0x0000381502cc (NAME='test/tr',
+header=0x0000101502d9 (NAME='test/tr',
-header=0x000028150236 (NAME='test/tr',
+header=0x000010150243 (NAME='test/tr',
DB_TRX_ID=0x000000000000,
DB_ROLL_PTR=0x80000000000000,
- ID=0x0000000000000010,
+ ID=0x0000000000000011,
- ID=0x000000000000000e,
+ ID=0x000000000000000f,
N_COLS=0x00000001,
TYPE=0x00000001,
MIX_ID=0x0000000000000000,
@@ -104,9 +106,9 @@
header=0x000050150074 (NAME='test/tz',
@@ -85,9 +85,9 @@
header=0x000040150074 (NAME='test/tz',
DB_TRX_ID=0x000000000000,
DB_ROLL_PTR=0x80000000000000,
- ID=0x0000000000000013,
+ ID=0x0000000000000014,
- ID=0x0000000000000011,
+ ID=0x0000000000000012,
N_COLS=0x80000001,
- TYPE=0x00000023,
+ TYPE=0x00000021,
Expand Down
Loading

0 comments on commit 5407117

Please sign in to comment.