您的位置:首页 > 其它

14.9 InnoDB Row Storage and Row Formats

2016-07-29 16:47 447 查看
MYSQL5.6官方文档

14.9 InnoDB Row Storage and Row Formats

PDF下载地址:http://download.csdn.net/detail/paololiu/9589937

中文只是我个人阅读时的理解,歧义的地方请以英文内容为准。

14.9 InnoDB Row Storage and Row Formats

14.9.1 Overview of InnoDB Row Storage

14.9.2 Specifying the Row Format for a Table

14.9.3 DYNAMIC and COMPRESSED Row Formats

14.9.4 COMPACT and REDUNDANT Row Formats

This section discusses how InnoDB features such as table compression, off-page storage of long variable-length column values, and large index key prefixes (innodb_large_prefix) are controlled by the ROW_FORMAT clause of the CREATE TABLE statement. It also discusses considerations for choosing the right row format, and compatibility of row formats between MySQL releases.

这一部分讲述了InnoDB如何通过CREATE TABLE中的ROW_FORMAT来控制InnoDB的某些特性的,例如表压缩,长变长列值的off-page存储,以及大索引key的前缀 (innodb_large_prefix) 。这部分还讲述了选择正确行格式的注意事项,以及行格式的兼容性问题。

14.9.1 Overview of InnoDB Row Storage

The storage for rows and associated columns affects performance for queries and DML operations. As more rows fit into a single disk page, queries and index lookups can work faster, less cache memory is required in the InnoDB buffer pool, and less I/O is required to write out updated values for the numeric and short string columns.

行数据以及相关的列的存储会影响查询和DML操作的性能。一个数据页能放更多的行数据库,那么查询以及索引的检索速度也就更快,InnoDB buffer pool所需的内存也就更少,数值型以及短字符串列的写操作所需要的I/O也更少。

The data in each InnoDB table is divided into pages. The pages that make up each table are arranged in a tree data structure called a B-tree index. Table data and secondary indexes both use this type of structure. The B-tree index that represents an entire table is known as the clustered index, which is organized according to the primary key columns. The nodes of the index data structure contain the values of all the columns in that row (for the clustered index) or the index columns and the primary key columns (for secondary indexes).

每个InnoDB表的数据会被分割到数个数据页里面。每个表的数据页都排列在一个树形的数据结构上称为B-tree索引。表的数据以及secondary index都会使用这个类型的结构。B-tree索引所代表的整个表被称之为clustered index。这种索引是根据主键列进行组织的。索引数据的节点结构包含了一行记录所有列的值(对于clustered index),或者是索引列和主键列的值(对于secondary index)。

Variable-length columns are an exception to this rule. Columns such as BLOB and VARCHAR that are too long to fit on a B-tree page are stored on separately allocated disk pages called overflow pages. We call such columns off-page columns. The values of these columns are stored in singly-linked lists of overflow pages, and each such column has its own list of one or more overflow pages. In some cases, all or a prefix of the long column value is stored in the B-tree, to avoid wasting storage and eliminating the need to read a separate page.

可变长的列使用的是另一种方式。例如BLOG和VARCHAR列会太长而无法放入到一个B-tree页里,所以会分别存储到不同的数据页里,这种数据页称之为overflow page。我们称这种列为off-page列。这些列的值会被存储子overflow page的单项链表里,每列都会有它自己的overflow page链表。在某些情况下,比较长的列的值的所有部分或者前缀部分会被存储在B-tree里,以此来避免磁盘空间的浪费,以及避免一个需求要读多个页。

The following sections describe how to configure the row format of InnoDB tables to control how variable-length columns values are stored. Row format configuration also determines the availability of the table compression feature and the large index key prefix feature (innodb_large_prefix).

下面的章节讲述了如何配置InnoDB表的行格式来控制可变长列的值怎么进行存储。行格式的配置同样还决定了表压缩以及大索引前缀key(innodb_large_prefix)的可用性。

14.9.2 Specifying the Row Format for a Table

You specify the row format for a table with the ROW_FORMAT clause of the CREATE TABLE and ALTER TABLE statements. For example:

你可以在CREATE TABLE and ALTER TABLE的时候使用ROW_FORMAT来指定行格式:

CREATE TABLE t1 (f1 int unsigned) ROW_FORMAT=DYNAMIC ENGINE=INNODB;

InnoDB ROW_FORMAT options include COMPACT, REDUNDANT, DYNAMIC, and COMPRESSED. For InnoDB tables, rows are stored in COMPACT format (ROW_FORMAT=COMPACT) by default. Refer to the CREATE TABLE documentation for additional information about the ROW_FORMAT table option.

InnoDB的ROW_FORMAT参数包括COMPACT, REDUNDANT, DYNAMIC, and COMPRESSED,其中COMPACT格式(ROW_FORMAT=COMPACT)是默认的。关于ROW_FORMAT的额外信息可以查看CREATE TABLE语句的相关语法。

The physical row structure of an InnoDB table is dependant on the row format. See Section 14.2.5.7, “Physical Row Structure” for more information.

InnoDB表的物理行结构取决于行的格式,更多信息可以查看Section 14.2.5.7, “Physical Row Structure”。

14.9.3 DYNAMIC and COMPRESSED Row Formats

This section discusses the DYNAMIC and COMPRESSED row formats for InnoDB tables. To create tables that use these row formats, innodb_file_format must be set to Barracuda, and innodb_file_per_table must be enabled. (The Barracuda file format also allows the COMPACT and REDUNDANT row formats.)

这部分讲述了InnoDB表的DYNAMIC and COMPRESSED行格式。要创建使用这些行格式的表,innodb_file_format必须要被设置成Barracuda,innodb_file_per_table也必须要是被开启的。(Barracuda 文件格式同时允许COMPACT and REDUNDANT的行格式。)

When a table is created with ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED, long column values are stored fully off-page, and the clustered index record contains only a 20-byte pointer to the overflow page.

当一个表以ROW_FORMAT=DYNAMIC or ROW_FORMAT=COMPRESSED创建了,比较长的列的值会完全存储在off-page里,并且clustered index记录只包含20-byte的指针来指向overflow page。

Whether any columns are stored off-page depends on the page size and the total size of the row. When the row is too long, InnoDB chooses the longest columns for off-page storage until the clustered index record fits on the B-tree page. TEXT and BLOB columns that are less than or equal to 40 bytes are always stored in-line.

存储在off-page里的任何列都依赖于数据页的大小以及整个行的大小。当行的长度太长的时候,InnoDB就会选择最长的列金溪县那个off-page存储,直到clustered index记录能放入到B-tree页里。TEXT and BLOB列小于或等于40 bytes的时候那就会存储在一起。

The DYNAMIC row format maintains the efficiency of storing the entire row in the index node if it fits (as do the COMPACT and REDUNDANT formats), but this new format avoids the problem of filling B-tree nodes with a large number of data bytes of long columns. The DYNAMIC format is based on the idea that if a portion of a long data value is stored off-page, it is usually most efficient to store all of the value off-page. With DYNAMIC format, shorter columns are likely to remain in the B-tree node, minimizing the number of overflow pages needed for any given row.

如果一行记录能够完全放入到索引的节点里,那么DYNAMIC 行格式嫩巩固保证较高的效率(同样适用于 COMPACT and REDUNDANT格式),但是这种新的格式能够避免把一个很长的列大量数据都放入到B-tree节点里。DYNAMIC 格式是基于这样的一个观点的:把一个很长的值的一部分存储在off-page里通常要比在off-page里存储值的全部内容更有效率。通过DYNAMIC格式,比较短的列基本上都能保留在B-tree节点里,这样也就减少了overflow page的数量。

The COMPRESSED row format uses similar internal details for off-page storage as the DYNAMIC row format, with additional storage and performance considerations from the table and index data being compressed and using smaller page sizes. With the COMPRESSED row format, the option KEY_BLOCK_SIZE controls how much column data is stored in the clustered index, and how much is placed on overflow pages. For full details about the COMPRESSED row format, see Section 14.7, “InnoDB Table Compression”.

COMPRESSED 格式在处理off-page上和DYNAMIC 类似,但是基于性能上的考虑会对表和索引的数据进行压缩并使用更小的数据页。通过COMPRESSED 行格式,KEY_BLOCK_SIZE参数能够控制有多少列的数据能够存储在clustered index上,有多少会被放到overflow page里。关于COMPRESSED 行格式更多的细节可以查看Section 14.7, “InnoDB Table Compression”。

Both DYNAMIC and COMPRESSED row formats support index key prefixes up to 3072 bytes. This feature is controlled by the innodb_large_prefix configuration option, which is disabled by default. See the innodb_large_prefix option description for more information.

DYNAMIC and COMPRESSED行格式都支持最大3072 bytes的索引前缀key。这个特性是由innodb_large_prefix配置参数控制的,默认是关闭的。更多信息可以查看innodb_large_prefix参数的描述。

ROW_FORMAT=DYNAMIC and ROW_FORMAT=COMPRESSED are variations of ROW_FORMAT=COMPACT and therefore handle CHAR storage in the same way as ROW_FORMAT=COMPACT. For more information, see Section 14.2.5.7, “Physical Row Structure”.

ROW_FORMAT=DYNAMIC and ROW_FORMAT=COMPRESSED是由ROW_FORMAT=COMPACT转变而来的,因此它们处理CHAR的存储和ROW_FORMAT=COMPACT是一样的。更多相关信息可见Section 14.2.5.7, “Physical Row Structure”。

14.9.4 COMPACT and REDUNDANT Row Formats

Early versions of InnoDB used an unnamed file format (now called Antelope) for database files. With that file format, tables are defined with ROW_FORMAT=COMPACT or ROW_FORMAT=REDUNDANT. InnoDB stores up to the first 768 bytes of variable-length columns (such as BLOB and VARCHAR) in the index record within the B-tree node, with the remainder stored on the overflow pages.

早期版本的InnoDB使用的数据库文件是未命名的文件格式(现在叫Antelope)。使用这种的文件格式,表可以被定义成ROW_FORMAT=COMPACT or ROW_FORMAT=REDUNDANT。这种情况InnoDB可以在B-tree节点的索引记录里最大存储可变长列(such as BLOB and VARCHAR)的前768 bytes,余下的则会被存储到overflow page里。

To preserve compatibility with those prior versions, tables created with the newest InnoDB default to the COMPACT row format. See Section 14.9.3, “DYNAMIC and COMPRESSED Row Formats” for information about the newer DYNAMIC and COMPRESSED row formats.

为了保证和以前版本的兼容,表会以最新默认的COMPACT行格式进行创建。Section 14.9.3, “DYNAMIC and COMPRESSED Row Formats”可以查看更新的DYNAMIC and COMPRESSED行格式的相关信息。

With the Antelope file format, if the value of a column is 768 bytes or less, no overflow page is needed, and some savings in I/O may result, since the value is in the B-tree node. This works well for relatively short BLOBs, but may cause B-tree nodes to fill with data rather than key values, reducing their efficiency. Tables with many BLOB columns could cause B-tree nodes to become too full of data, and contain too few rows, making the entire index less efficient than if the rows were shorter or if the column values were stored off-page.

对于Antelope文件格式,如果列的值等于或小于768 bytes,那么就不需要overflow page了,还能节省I/O,因为列的值都被 存储在B-tree的节点里了。这对于相对比较小的BLOB列是高效的,但是这样B-tree要存放的是数据而不是索引key值,这样就降低了它的工作效率。多个BLOB列会让B-tree放满了行的数据,而减少了放置行的数量。这样相对于使用比较短的列或者把列存储在off-page里来说,也就降低了索引使用的整体效率。

For information about the physical row structure of tables that use the REDUNDANT or COMPACT row format, see Section 14.2.5.7, “Physical Row Structure”.

关于使用REDUNDANT or COMPACT时数据行的物理结构的相关信息可以查看 Section 14.2.5.7, “Physical Row Structure”。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: