InnoDB的限制
我们经常遇到MySQL的问题,很多是一些限制产生的,现在我们整理一下关于InnoDB的限制,这里直接翻译了MySQL 5.6的官方文档。
14.22 InnoDB Limits
This section describes limits for InnoDB
tables, indexes, tablespaces, and other aspects of the InnoDB
storage engine.
此段落描述了 InnoDB 表,索引,表空间 和 InnoDB 存储引擎其他方面的限制。
-
A table can contain a maximum of 1017 columns (raised in MySQL 5.6.9 from the earlier limit of 1000). 一张表可以包含最多 1017 个字段 (在 5.6.9 版本中从早先的 1000 个的限制进行了提升。)
-
A table can contain a maximum of 64 secondary indexes. 一张表可以包含最多 64 个二级索引 (也就是聚簇索引之外的 非聚簇索引)。
-
By default, the index key prefix length limit is 767 bytes. See Section 13.1.13, “CREATE INDEX Statement”. For example, you might hit this limit with a column prefix index of more than 255 characters on a
TEXT
orVARCHAR
column, assuming autf8mb3
character set and the maximum of 3 bytes for each character. When theinnodb_large_prefix
configuration option is enabled, the index key prefix length limit is raised to 3072 bytes forInnoDB
tables that use theDYNAMIC
orCOMPRESSED
row format. 默认地,索引的 键 前缀长度限制是 767 字节 (参看 13.1.13 创建索引声明:下一项)。例如,你给一个多于 255字符的 TEXT 或 VARCHAR 字段 带上字段前缀索引,将会触发这个限制,假设是一个utf8mb3 字符集,且每个字符最多3字节 (3 * 256 = 768)。 当 innodb_large_prefix 配置项被开启时,索引键的前缀长度限制会被提升到 3072 字节。 -
Column Prefix Key Parts 字段前缀索引部分
For string columns, indexes can be created that use only the leading part of column values, using
syntax to specify an index prefix length: 对于字符串字段,可以创造索引,这个索引仅用到字段值的开头部分,用 字段名(长度) 语法来声明一个索引前缀长度。col_name
(length
)-
Prefixes can be specified for
CHAR
,VARCHAR
,BINARY
, andVARBINARY
key parts. 可以为 CHAR, VARCHAR, BINARY 以及 VARBINARY 键部分 声明前缀。 -
Prefixes must be specified for
BLOB
andTEXT
key parts. Additionally,BLOB
andTEXT
columns can be indexed only forInnoDB
,MyISAM
, andBLACKHOLE
tables. 必须为 BLOB 和 TEXT 键部分 必须声明前缀。另外,BLOB 和 TEXT 字段只能在 以InnoDB, MyISAM 和 BLACKHOLE 为存储引擎的表中进行索引。 -
Prefix limits are measured in bytes. However, prefix lengths for index specifications in
CREATE TABLE
,ALTER TABLE
, andCREATE INDEX
statements are interpreted as number of characters for nonbinary string types (CHAR
,VARCHAR
,TEXT
) and number of bytes for binary string types (BINARY
,VARBINARY
,BLOB
). Take this into account when specifying a prefix length for a nonbinary string column that uses a multibyte character set. 前缀限制是按字节进行测量的。然而,在 CREATE TABLE, ALTER TABLE, CREATE INDEX 语句中的 前缀长度 索引声明,对于 非二进制字符串类型 (nonbinary string types) (CHAR, VARCHAR, TEXT) 会被理解成为 字符数量,对于 二进制字符串类型(binary string types) (BINARY, VARBINARY, BLOB) 会被理解成为 字节数量。当使用多字节字符集时,为一个非二进制字符串类字段声明前缀长度时,要把这点考虑进去。Prefix support and lengths of prefixes (where supported) are storage engine dependent. For example, a prefix can be up to 767 bytes long for
InnoDB
tables or 3072 bytes if theinnodb_large_prefix
option is enabled. ForMyISAM
tables, the prefix length limit is 1000 bytes. TheNDB
storage engine does not support prefixes (see Section 18.1.7.6, “Unsupported or Missing Features in NDB Cluster”). 前缀支持 以及 前缀长度(当支持时) 是依赖于存储引擎的。例如,一个前缀在 InnoDB 引擎中可以上至 767 字节,或者 3072 字节 当 innodb_large_prefix 选项开启时。对于 MyISAM 表,前缀长度限制是 1000 字节。NDB 存储引擎不支持前缀。
The statement shown here creates an index using the first 10 characters of the
name
column (assuming thatname
has a nonbinary string type):
这里展示的语句,创建了一个 用 name字段的 前10个字符 创建了一个索引 (假定 name 是一个非二进制字符串类字段)CREATE INDEX part_of_name ON customer (name(10));
If names in the column usually differ in the first 10 characters, lookups performed using this index should not be much slower than using an index created from the entire
name
column. Also, using column prefixes for indexes can make the index file much smaller, which could save a lot of disk space and might also speed upINSERT
operations.
如果 在这个name字段中的名字通过在前10个字符不相同,则用刚刚创建的这个索引的性能,应该不会比用name字段全部名称创建的索引慢太多。同时,使用字段的前缀去创建索引可以让索引文件小很多,这将节省很多磁盘空间,而且有可能让 INSERT 操作更快一些。Attempting to use an index key prefix length that exceeds the limit returns an error. To avoid such errors in replication configurations, avoid enabling
innodb_large_prefix
on the source if it cannot also be enabled on replicas.
尝试创建一个超过限制的 索引键前缀长度将会返回一个错误。为了避免在复制配置时产生这类错误,如果在备份上也不能开启 innodb_large_prefix选项,那么在源头上就应该避免开启 innodb_large_prefix。
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes
-
-
If you reduce the
InnoDB
page size to 8KB or 4KB by specifying theinnodb_page_size
option 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.
根据 3072字节对应16KB页大小,如果在创建MySQL实例时,你通过声明 innodb_page_sise 选项 把 InnoDB 页大小 (page size) 减少到 8KB 或者 4KB,那么 索引键的最大长度也会按比例地降低。也就是说,在 8KB时 最大的索引键长度是 1536字节,而4KB是768字节。The limits that apply to index key prefixes also apply to full-column index keys. 适用于索引键前缀的限制通用适用于全字段索引键(如单个完整字段键或多个字段的联合索引键)。
-
A maximum of 16 columns is permitted for multicolumn indexes. Exceeding the limit returns an error.
对于多字段索引,最多运行16个字段。超出此限制会返回错误。ERROR 1070 (42000): Too many key parts specified; max 16 parts allowed
-
The maximum row size, excluding any variable-length columns that are stored off-page, is slightly less than half of a page. That is, the maximum row size is about 8000 bytes for the default page size of 16KB. If you reduce the page size by specifying the
innodb_page_size
option when creating the MySQL instance, the maximum row size is 4000 bytes for 8KB pages, or 2000 bytes for 4KB pages.LONGBLOB
andLONGTEXT
columns must be less than 4GB, and the total row size, includingBLOB
andTEXT
columns must be less than 4GB.
最大的行大小,包括所有被离页(off-page)存储的长度可变的字段,会稍微少于一个半页。也就是说,对于默认的16KB的页大小,最大的行大小大概是8000字节。如果在创建MySQL实例时,通过声明 innodb_page_size 选项来减少 页大小,那么8KB的页最大行大小为4000字节,或者4KB的2000字节。LONGBLOB 和 LONGTEXT 字段必须小于 4GB,包括 BLOB 和 TEXT字段的总的行大小页必须小于4GB。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 14.12.2, “File Space Management”.
如果一行小于一个半页长,它的全部将在本页内存储。如果超过了一个半页,(多出来的)可变的长度字段将被选择到外部离页存储,直到这行能存进一个半页里,如 14.12.1 文件空间管理 所述。 -
Although
InnoDB
supports 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 8.4.7, “Limits on Table Column Count and Row Size”.
尽管 InnoDB 支持行大小内部大于 65,535 字节,MySQL它本身 对 所有字段的组合大小 强加了一个 65,535的行大小限制,参看 8.4.7 表字段计数和行大小。 -
On some older operating systems, files must be less than 2GB. This is not an
InnoDB
limitation. If you require a large system tablespace, configure it using several smaller data files rather than one large data file, or distribute table data across file-per-table data files.
在一些老的操作系统中,文件必须小于2GB。这不是 InnoDB的限制。如果你需要一个大的系统表空间,把它设置成几个小一点的数据文件,而不是一个大的数据文件,或者 将表数据 拆分到 几个 单表文件 数据文件中。 -
The combined maximum size for
InnoDB
log files is 512GB. InnoDB 日志文件的 组合最大尺寸是 512GB。 -
The minimum tablespace size is slightly larger than 10MB. The maximum tablespace size depends on the
InnoDB
page size.
最小的表空间大小比10MB稍微大一些。最大的表空间大小 取决于 InnoDB 页大小。Table 14.20 InnoDB Maximum Tablespace Size
InnoDB Page Size
InnoDB 页大小Maximum Tablespace Size
最大的表空间大小4KB 16TB 8KB 32TB 16KB 64TB The maximum tablespace size is also the maximum size for a table. 最大的表空间尺寸也就是一个表的最大尺寸。
-
Tablespace files cannot exceed 4GB on Windows 32-bit systems (Bug #80149). 再Win32系统中,表空间文件不能超过4GB。
-
The path of a tablespace file, including the file name, cannot exceed the
MAX_PATH
limit on Windows. Prior to Windows 10, theMAX_PATH
limit is 260 characters. As of Windows 10, version 1607,MAX_PATH
limitations are removed from common Win32 file and directory functions, but you must enable the new behavior. 表空间文件的路径,包括文件名,不能超出 Windows系统规定的 MAX_PATH变量。在 Win10 之前,MAX_PATH限制是260个字符。对于Win10-1607版本,MAX_PATH限制从通常的Win32文件和目录方法中移除了,但是你必须使新的操作行为可用。 -
For limits associated with concurrent read-write transactions, see Section 14.6.7, “Undo Logs”.
对于 并发读-写 事务的相关限制,参照:14.6.7 回滚日志

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Flowable 数据库表结构说明、Flowable 数据字典说明
一、Flowable数据库表命名规则 ACT_RE_* : ’RE’表示repository(存储)。RepositoryService接口操作的表。带此前缀的表包含的是静态信息,如,流程定义,流程的资源(图片,规则等)。 ACT_RU_* : ’RU’表示runtime。这是运行时的表存储着流程变量,用户任务,变量,职责(job)等运行时的数据。flowable只存储实例执行期间的运行时数据,当流程实例结束时,将删除这些记录。这就保证了这些运行时的表小且快。 ACT_ID_* : ’ID’表示identity(组织机构)。这些表包含标识的信息,如用户,用户组,等等。 ACT_HI_* : ’HI’表示history。就是这些表包含着历史的相关数据,如结束的流程实例,变量,任务,等等。 ACT_GE_* : 普通数据,各种情况都使用的数据。 二、数据库表结构(34张表,不同版本数量可能会有出入) 一般数据(2) ACT_GE_BYTEARRAY 通用的流程定义和流程资源 ACT_GE_PROPERTY 系统相关属性 流程历史记录(8) ACT_HI_ACT...
- 下一篇
面试无忧:源码+实践,讲到MySQL调优的底层算法实现
不知道大家有没有参与过系统重构或者代码调优的工作,有幸,最近我接触了一个公司N久前的一个项目的重构工作,目的就是为了提升一下响应速度,然后我们小组拿到这个项目的源代码之后,大呼:WC,这NM谁写的代码啊,太不讲究了吧,这SQL都写了些什么玩意啊,其实在这些年的工作中,这样的问题已经不是第一次遇见了,老是被提需求说性能有问题,拿到代码之后发现问题很简单,90%都是SQL的问题,当时赶进度,能查询出来结果就可以,稍微一优化SQL性能就能提升很多,虽然现在有很多SQL审核平台,但是,在面试的过程中,需要你回答的更加深入一些,那这里,我就结合代码给你讲解到算法的层次,在遇到优化,不在惧怕任何挑战 公众号:Java架构师联盟,每日更新技术好文 SQL优化基础概念 说到SQL优化,大家首先想到的就是创建索引,但创建索引需要了解相关基础概念。 1. 索引 我们知道,MySQL中的索引通常采用B-Tree结构,那么首先就要清楚B-Tree和B+Tree 结构的区别 在InnoDB中索引是B+Tree结构的,在该结构中叶子节点包含了非叶子节点的所有数据,并且叶子节点之间会通过指针连接。 之所以采用B+...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- Docker安装Oracle12C,快速搭建Oracle学习环境
- SpringBoot2全家桶,快速入门学习开发网站教程
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- CentOS关闭SELinux安全模块
- Eclipse初始化配置,告别卡顿、闪退、编译时间过长
- CentOS6,CentOS7官方镜像安装Oracle11G
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Docker使用Oracle官方镜像安装(12C,18C,19C)