本节描述了 InnoDB 表、索引、表空间及 InnoDB 存储引擎其他方面的限制。This section describes limits for InnoDB
tables, indexes, tablespaces, and other aspects of the
InnoDB storage engine.
一个表最多可以包含 1017 列。虚拟生成列也包含在此限制内。A table can contain a maximum of 1017 columns. Virtual generated columns are included in this limit.
一个表最多可以包含 64 个 二级索引。A table can contain a maximum of 64 secondary indexes.
对于使用
DYNAMIC或COMPRESSED行格式的InnoDB表,索引键前缀长度的限制为 3072 字节。The index key prefix length limit is 3072 bytes forInnoDBtables that useDYNAMICorCOMPRESSEDrow format.对于使用
REDUNDANT或COMPACT行格式的InnoDB表,索引键前缀长度的限制为 767 字节。例如,如果在TEXT或VARCHAR列上使用超过 191 个字符的 列前缀 索引,并且使用utf8mb4字符集且每个字符最多占 4 个字节,就可能会遇到此限制。The index key prefix length limit is 767 bytes forInnoDBtables that use theREDUNDANTorCOMPACTrow format. For example, you might hit this limit with a column prefix index of more than 191 characters on aTEXTorVARCHARcolumn, assuming autf8mb4character set and the maximum of 4 bytes for each character.尝试使用超过限制的索引键前缀长度会返回错误。Attempting to use an index key prefix length that exceeds the limit returns an error.
如果在创建 MySQL 实例时通过指定
innodb_page_size选项将InnoDB页面大小 减小到 8KB 或 4KB,则索引键的最大长度将按比例降低,基于 16KB 页面大小的 3072 字节限制。也就是说,当页面大小为 8KB 时,最大索引键长度为 1536 字节;页面大小为 4KB 时为 768 字节。If you reduce theInnoDBpage size to 8KB or 4KB by specifying theinnodb_page_sizeoption when creating the MySQL instance, the maximum length of the index key is lowered proportionally, based on the limit of 3072 bytes for a 16KB page size. That is, the maximum index key length is 1536 bytes when the page size is 8KB, and 768 bytes when the page size is 4KB.适用于索引键前缀的限制也适用于完整列索引键。The limits that apply to index key prefixes also apply to full-column index keys.
多列索引最多允许 16 列。超过此限制会返回错误。A maximum of 16 columns is permitted for multicolumn indexes. Exceeding the limit returns an error.
ERROR 1070 (42000): Too many key parts specified; max 16 parts allowed
最大行大小(不包括存储在页外的任何可变长度列)对于 4KB、8KB、16KB 和 32KB 的页大小略小于一页的一半。例如,默认
innodb_page_size为 16KB 时,最大行大小约为 8000 字节。然而,对于 64KB 的InnoDB页大小,最大行大小约为 16000 字节。LONGBLOB和LONGTEXT列必须小于 4GB,并且包括BLOB和TEXT列的总行大小必须小于 4GB。The maximum row size, excluding any variable-length columns that are stored off-page, is slightly less than half of a page for 4KB, 8KB, 16KB, and 32KB page sizes. For example, the maximum row size for the defaultinnodb_page_sizeof 16KB is about 8000 bytes. However, for anInnoDBpage size of 64KB, the maximum row size is approximately 16000 bytes.LONGBLOBandLONGTEXTcolumns must be less than 4GB, and the total row size, includingBLOBandTEXTcolumns, must be less than 4GB.如果一行小于半页长,则整行数据都会在页面内本地存储。如果超过半页长,则会选择可变长度的列进行页外存储,直到行在半页内放下,如第 17.11.2 节,“文件空间管理”中所述。If a row is less than half a page long, all of it is stored locally within the page. If it exceeds half a page, variable-length columns are chosen for external off-page storage until the row fits within half a page, as described in Section 17.11.2, “File Space Management”.
尽管
InnoDB内部支持行大小超过 65,535 字节,但 MySQL 本身对所有列的总行大小限制为 65,535 字节。请参阅第 10.4.7 节,“表列数和行大小限制”。AlthoughInnoDBsupports row sizes larger than 65,535 bytes internally, MySQL itself imposes a row-size limit of 65,535 for the combined size of all columns. See Section 10.4.7, “Limits on Table Column Count and Row Size”.最大表或表空间的大小受到服务器文件系统的影响,文件系统可能会施加一个最大文件大小,该大小可能比
InnoDB定义的内部 64 TiB 大小限制还小。例如,Linux 上的 ext4 文件系统的最大文件大小为 16 TiB,因此最大表或表空间的大小变为 16 TiB,而不是 64 TiB。另一个例子是 FAT32 文件系统,其最大文件大小为 4 GB。The maximum table or tablespace size is impacted by the server's file system, which can impose a maximum file size that is smaller than the internal 64 TiB size limit defined byInnoDB. For example, the ext4 file system on Linux has a maximum file size of 16 TiB, so the maximum table or tablespace size becomes 16 TiB instead of 64 TiB. Another example is the FAT32 file system, which has a maximum file size of 4 GB.如果需要更大的系统表空间,请使用多个较小的数据文件来配置,而不是使用一个大型数据文件,或者将表数据分布在每表一个文件和通用表空间数据文件中。If you require a larger system tablespace, configure it using several smaller data files rather than one large data file, or distribute table data across file-per-table and general tablespace data files.
InnoDB日志文件的总最大大小为 512GB。The combined maximum size forInnoDBlog files is 512GB.最小表空间大小略大于 10MB。最大表空间大小取决于
InnoDB页大小。The minimum tablespace size is slightly larger than 10MB. The maximum tablespace size depends on theInnoDBpage size.表 17.26 InnoDB 最大表空间大小Table 17.26 InnoDB Maximum Tablespace Size
InnoDB 页大小InnoDB Page Size 最大表空间大小Maximum Tablespace Size 4KB 16TB 8KB 32TB 16KB 64TB 32KB 128TB 64KB 256TB 最大表空间大小也是表的最大大小。The maximum tablespace size is also the maximum size for a table.
一个
InnoDB实例最多支持 2^32(4294967296)个表空间,其中少量表空间用于撤销和临时表。AnInnoDBinstance supports up to 2^32 (4294967296) tablespaces, with a small number of those tablespaces reserved for undo and temporary tables.共享表空间支持最多 2^32 (4294967296) 张表。Shared tablespaces support up to 2^32 (4294967296) tables.
表空间文件的路径,包括文件名,不能超过 Windows 上的
MAX_PATH限制。在 Windows 10 之前,MAX_PATH限制为 260 个字符。从 Windows 10 版本 1607 起,常用的 Win32 文件和目录函数中已取消MAX_PATH限制,但您必须启用此新行为。The path of a tablespace file, including the file name, cannot exceed theMAX_PATHlimit on Windows. Prior to Windows 10, theMAX_PATHlimit is 260 characters. As of Windows 10, version 1607,MAX_PATHlimitations are removed from common Win32 file and directory functions, but you must enable the new behavior.有关并发读写事务相关的限制,请参见 第 17.6.6 节,“撤销日志”。For limits associated with concurrent read-write transactions, see Section 17.6.6, “Undo Logs”.