STATISTICS 表提供关于表索引的信息。The STATISTICS table provides
information about table indexes.
STATISTICS 中表示表统计信息的列保存的是缓存值。information_schema_stats_expiry 系统变量定义了缓存的表统计信息过期前的时间周期。默认值是 86400 秒(24 小时)。如果没有缓存的统计信息或者统计信息已过期,则在查询表统计信息列时,统计信息将从存储引擎中获取。要随时更新给定表的缓存值,请使用 ANALYZE TABLE。要始终直接从存储引擎获取最新的统计信息,请设置 information_schema_stats_expiry=0。有关更多信息,请参见 第 10.2.3 节,“优化 INFORMATION_SCHEMA 查询”。Columns in STATISTICS that represent
table statistics hold cached values. The
information_schema_stats_expiry
system variable defines the period of time before cached table
statistics expire. The default is 86400 seconds (24 hours). If
there are no cached statistics or statistics have expired,
statistics are retrieved from storage engines when querying table
statistics columns. To update cached values at any time for a
given table, use ANALYZE TABLE. To
always retrieve the latest statistics directly from storage
engines, set
information_schema_stats_expiry=0.
For more information, see
Section 10.2.3, “Optimizing INFORMATION_SCHEMA Queries”.
如果启用了 innodb_read_only 系统变量,ANALYZE
TABLE 可能会失败,因为它无法更新使用 InnoDB 的数据字典中的统计表。对于更新键分布的 ANALYZE
TABLE 操作,即使操作更新了表本身(例如,如果它是 MyISAM 表),也可能会失败。要获得更新的分布统计信息,请设置 information_schema_stats_expiry=0。If the innodb_read_only system
variable is enabled, ANALYZE
TABLE may fail because it cannot update statistics
tables in the data dictionary, which use
InnoDB. For ANALYZE
TABLE operations that update the key distribution,
failure may occur even if the operation updates the table itself
(for example, if it is a MyISAM table). To
obtain the updated distribution statistics, set
information_schema_stats_expiry=0.
STATISTICS 表有以下列:The STATISTICS table has these
columns:
TABLE_CATALOG包含索引的表所属目录的名称。该值始终为
def。The name of the catalog to which the table containing the index belongs. This value is alwaysdef.TABLE_SCHEMA包含索引的表所属模式(数据库)的名称。The name of the schema (database) to which the table containing the index belongs.
TABLE_NAMETABLE_NAME包含索引的表的名称。The name of the table containing the index.
NON_UNIQUE如果索引不允许重复,则为 0;如果允许,则为 1。0 if the index cannot contain duplicates, 1 if it can.
INDEX_SCHEMA索引所属模式(数据库)的名称。The name of the schema (database) to which the index belongs.
INDEX_NAME索引的名称。如果索引是主键,则名称始终为
PRIMARY。The name of the index. If the index is the primary key, the name is alwaysPRIMARY.SEQ_IN_INDEX索引中的列序号,从 1 开始。The column sequence number in the index, starting with 1.
COLUMN_NAMECOLUMN_NAME列名。另请参见
EXPRESSION列的描述。The column name. See also the description for theEXPRESSIONcolumn.COLLATIONCOLLATION列在索引中的排序方式。可以取值
A(升序)、D(降序)或NULL(未排序)。How the column is sorted in the index. This can have valuesA(ascending),D(descending), orNULL(not sorted).CARDINALITY索引中唯一值的估计数量。要更新此数字,请执行
ANALYZE TABLE或(针对MyISAM表) myisamchk -a。An estimate of the number of unique values in the index. To update this number, runANALYZE TABLEor (forMyISAMtables) myisamchk -a.CARDINALITY是基于以整数形式存储的统计信息进行计数的,因此即使对于小表,该值也不一定精确。基数越高,MySQL 在进行连接操作时使用索引的可能性就越大。CARDINALITYis counted based on statistics stored as integers, so the value is not necessarily exact even for small tables. The higher the cardinality, the greater the chance that MySQL uses the index when doing joins.SUB_PART索引前缀。也就是说,如果列只是部分建立索引,则为已索引字符的数量;如果整个列都有索引,则为
NULL。The index prefix. That is, the number of indexed characters if the column is only partly indexed,NULLif the entire column is indexed.Note前缀 限制以字节为单位。然而,索引规范前缀 lengths 用于
CREATE TABLE“,ALTER TABLE”,CREATE INDEX语句被解释为非二元字符串类型的字符数(CHARVARCHAR,TEXT以及二进制字符串的字节数类型 (BINARY,VARBINARYBLOB)。在为使用多字节字符集的非二元字符串列指定前缀长度时,请考虑这一点。Prefix limits are measured in bytes. However, prefix lengths for index specifications inCREATE TABLE,ALTER TABLE, andCREATE INDEXstatements 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.有关索引前缀的更多信息,请参阅 第 10.3.5 节,“列索引” 和 第 15.1.15 节,“CREATE INDEX 语句”。For additional information about index prefixes, see Section 10.3.5, “Column Indexes”, and Section 15.1.15, “CREATE INDEX Statement”.
PACKED指示键是如何打包的。如果没有打包,则为
NULL。Indicates how the key is packed.NULLif it is not.NULLABLE如果该列可能包含
NULL值,则为YES;如果不包含,则为''。ContainsYESif the column may containNULLvalues and''if not.INDEX_TYPE使用的索引方法(
BTREE、FULLTEXT、HASH、RTREE)。The index method used (BTREE,FULLTEXT,HASH,RTREE).COMMENTCOMMENT关于索引的信息,如果未在其自身列中描述,例如索引被禁用时显示
disabled。Information about the index not described in its own column, such asdisabledif the index is disabled.INDEX_COMMENT为索引创建时提供的
COMMENT属性的任何评论。Any comment provided for the index with aCOMMENTattribute when the index was created.IS_VISIBLE索引是否对优化器可见。参见第 10.3.12 节,“不可见索引”。Whether the index is visible to the optimizer. See Section 10.3.12, “Invisible Indexes”.
EXPRESSIONEXPRESSIONMySQL 支持函数键部分(请参阅 函数键部分),这会影响
COLUMN_NAME和EXPRESSION列:MySQL supports functional key parts (see Functional Key Parts), which affects both theCOLUMN_NAMEandEXPRESSIONcolumns:对于非函数键部分,
COLUMN_NAME表示键部分索引的列,EXPRESSION为NULL。For a nonfunctional key part,COLUMN_NAMEindicates the column indexed by the key part andEXPRESSIONisNULL.对于函数键部分,
COLUMN_NAME列为NULL,EXPRESSION表示键部分的表达式。For a functional key part,COLUMN_NAMEcolumn isNULLandEXPRESSIONindicates the expression for the key part.
注意事项Notes
没有用于索引的标准
INFORMATION_SCHEMA表。MySQL 的列列表类似于 SQL Server 2000 为sp_statistics返回的结果,只是QUALIFIER和OWNER分别被替换为CATALOG和SCHEMA。There is no standardINFORMATION_SCHEMAtable for indexes. The MySQL column list is similar to what SQL Server 2000 returns forsp_statistics, except thatQUALIFIERandOWNERare replaced withCATALOGandSCHEMA, respectively.
有关表索引的信息也可以通过 SHOW INDEX 语句获取。参见 第 15.7.7.23 节,“SHOW INDEX 语句”。以下语句是等效的:Information about table indexes is also available from the
SHOW INDEX statement. See
Section 15.7.7.23, “SHOW INDEX Statement”. The following statements are
equivalent:
SELECT * FROM INFORMATION_SCHEMA.STATISTICS WHERE table_name = 'tbl_name' AND table_schema = 'db_name' SHOW INDEX FROMtbl_nameFROMdb_name
关于生成的不可见主键列的信息默认在此表中可见。您可以通过设置 show_gipk_in_create_table_and_information_schema
= OFF 来使这些信息隐藏。有关更多信息,请参见 第 15.1.20.11 节,“生成的不可见主键”。Information about generated invisible primary key columns is
visible in this table by default. You can cause such information
to be hidden by setting
show_gipk_in_create_table_and_information_schema
= OFF. For more information, see
Section 15.1.20.11, “Generated Invisible Primary Keys”.