文章目录
1 问题背景
前面研究了InnoDB磁盘架构之索引,今天研究下表空间
2 回顾
InnoDB架构如下图所示:
3 表空间
官方文档对表空间的介绍非常详情,此处只挑选平常接触得多或者比较重要的章节来研究。详情见Tablespaces
3.1 系统表空间
原文
The system tablespace is the storage area for the change buffer. It may also contain table and index data if tables are created in the system tablespace rather than file-per-table or general tablespaces. In previous MySQL versions, the system tablespace contained the InnoDB data dictionary. In MySQL 8.0, InnoDB stores metadata in the MySQL data dictionary. See Chapter 14, MySQL Data Dictionary. In previous MySQL releases, the system tablespace also contained the doublewrite buffer storage area. This storage area resides in separate doublewrite files as of MySQL 8.0.20. See Section 15.6.4, “Doublewrite Buffer”.
系统表空间是存储更改缓冲区的区域。如果表是在系统表空间创建的,而不是在每个表文件或通用表文件创建的,那么系统表空间可能包含表数据以及索引数据。在以前的MySQL版本,系统表空间包含InnoDB数据字典。在MySQL8.0版本,InnoDB存储元数据在数据字典。详情见MySQL 数据字典。在以前的MySQL版本,系统表空间还包含双写缓冲区存储区。从MySQL8.0.20开始,此存储区域位于单独的双写文件中。详情见Doublewrite Buffer
原文
The system tablespace can have one or more data files. By default, a single system tablespace data file, named ibdata1, is created in the data directory. The size and number of system tablespace data files is defined by the innodb_data_file_path startup option. For configuration information, see System Tablespace Data File Configuration.
系统表空间可以有一个或多个数据文件。默认地,一个名为ibdata1
的单个系统表空间数据文件是被创建在数据字典。系统表空间的数据文件大小以及数量是由innodb_data_file_path
启动选项定义的。详情见System Tablespace Data File Configuration
3.2 File-Per-Table 表空间
原文
A file-per-table tablespace contains data and indexes for a single InnoDB table, and is stored on the file system in a single data file.
每个表的文件表空间包含单个InnoDB表的数据和索引,并存储在文件系统上的单个数据文件中。
本小节将从以下几个方面去阐述
File-per-table
表空间的特点:
- File-Per-Table 表空间的配置
- File-Per-Table 表空间的数据文件
- File-Per-Table 表空间的优点
- File-Per-Table 表空间的缺点
3.2.1 File-Per-Table 表空间配置
3.2.2 File-Per-Table 表空间数据文件
原文
A file-per-table tablespace is created in an .idb data file in a schema directory under the MySQL data directory. The .ibd file is named for the table (table_name.ibd). For example, the data file for table test.t1 is created in the test directory under the MySQL data directory
一个 file-per-table
表空间被创建并存储在名为表名.idb
文件上。该文件是在MySQL的data目录下的以表名为目录的路径上,如下所示:
mysql> USE test;
mysql> CREATE TABLE t1 (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100)
) ENGINE = InnoDB;
$> cd /path/to/mysql/data/test
$> ls
t1.ibd