Documentation Home
MySQL 8.0 Reference Manual
Related Documentation Download this Manual
PDF (US Ltr) - 43.3Mb
PDF (A4) - 43.4Mb
Man Pages (TGZ) - 297.3Kb
Man Pages (Zip) - 402.5Kb
Info (Gzip) - 4.3Mb
Info (Zip) - 4.3Mb
Excerpts from this Manual

MySQL 8.0 Reference Manual  / ...  / INFORMATION_SCHEMA Tables  / INFORMATION_SCHEMA General Tables  /  The INFORMATION_SCHEMA STATISTICS Table

28.3.34 The INFORMATION_SCHEMA STATISTICS Table

TheSTATISTICS table provides information about table indexes.

Columns inSTATISTICS that represent table statistics hold cached values. Theinformation_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, useANALYZE TABLE. To always retrieve the latest statistics directly from storage engines, setinformation_schema_stats_expiry=0. For more information, seeSection 10.2.3, “Optimizing INFORMATION_SCHEMA Queries”.

Note

If theinnodb_read_only system variable is enabled,ANALYZE TABLE may fail because it cannot update statistics tables in the data dictionary, which useInnoDB. ForANALYZE TABLE operations that update the key distribution, failure may occur even if the operation updates the table itself (for example, if it is aMyISAM table). To obtain the updated distribution statistics, setinformation_schema_stats_expiry=0.

TheSTATISTICS table has these columns:

  • TABLE_CATALOG

    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_NAME

    The name of the table containing the index.

  • NON_UNIQUE

    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

    The name of the index. If the index is the primary key, the name is alwaysPRIMARY.

  • SEQ_IN_INDEX

    The column sequence number in the index, starting with 1.

  • COLUMN_NAME

    The column name. See also the description for theEXPRESSION column.

  • COLLATION

    How the column is sorted in the index. This can have valuesA (ascending),D (descending), orNULL (not sorted).

  • CARDINALITY

    An estimate of the number of unique values in the index. To update this number, runANALYZE TABLE or (forMyISAM tables)myisamchk -a.

    CARDINALITY is 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

    The index prefix. That is, the number of indexed characters if the column is only partly indexed,NULL if the entire column is indexed.

    Note

    Prefixlimits are measured in bytes. However, prefixlengths for index specifications inCREATE 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.

    For additional information about index prefixes, seeSection 10.3.5, “Column Indexes”, andSection 15.1.15, “CREATE INDEX Statement”.

  • PACKED

    Indicates how the key is packed.NULL if it is not.

  • NULLABLE

    ContainsYES if the column may containNULL values and'' if not.

  • INDEX_TYPE

    The index method used (BTREE,FULLTEXT,HASH,RTREE).

  • COMMENT

    Information about the index not described in its own column, such asdisabled if the index is disabled.

  • INDEX_COMMENT

    Any comment provided for the index with aCOMMENT attribute when the index was created.

  • IS_VISIBLE

    Whether the index is visible to the optimizer. SeeSection 10.3.12, “Invisible Indexes”.

  • EXPRESSION

    MySQL 8.0.13 and higher supports functional key parts (seeFunctional Key Parts), which affects both theCOLUMN_NAME andEXPRESSION columns:

    • For a nonfunctional key part,COLUMN_NAME indicates the column indexed by the key part andEXPRESSION isNULL.

    • For a functional key part,COLUMN_NAME column isNULL andEXPRESSION indicates the expression for the key part.

Notes

  • There is no standardINFORMATION_SCHEMA table for indexes. The MySQL column list is similar to what SQL Server 2000 returns forsp_statistics, except thatQUALIFIER andOWNER are replaced withCATALOG andSCHEMA, respectively.

Information about table indexes is also available from theSHOW INDEX statement. SeeSection 15.7.7.22, “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_name  FROMdb_name

In MySQL 8.0.30 and later, information about generated invisible primary key columns is visible in this table by default. You can cause such information to be hidden by settingshow_gipk_in_create_table_and_information_schema = OFF. For more information, seeSection 15.1.20.11, “Generated Invisible Primary Keys”.