STATISTICS

The STATISTICS table provides information about table indexes.

  1. USE information_schema;
  2. DESC statistics;
  1. +---------------+---------------+------+------+---------+-------+
  2. | Field | Type | Null | Key | Default | Extra |
  3. +---------------+---------------+------+------+---------+-------+
  4. | TABLE_CATALOG | varchar(512) | YES | | NULL | |
  5. | TABLE_SCHEMA | varchar(64) | YES | | NULL | |
  6. | TABLE_NAME | varchar(64) | YES | | NULL | |
  7. | NON_UNIQUE | varchar(1) | YES | | NULL | |
  8. | INDEX_SCHEMA | varchar(64) | YES | | NULL | |
  9. | INDEX_NAME | varchar(64) | YES | | NULL | |
  10. | SEQ_IN_INDEX | bigint(2) | YES | | NULL | |
  11. | COLUMN_NAME | varchar(21) | YES | | NULL | |
  12. | COLLATION | varchar(1) | YES | | NULL | |
  13. | CARDINALITY | bigint(21) | YES | | NULL | |
  14. | SUB_PART | bigint(3) | YES | | NULL | |
  15. | PACKED | varchar(10) | YES | | NULL | |
  16. | NULLABLE | varchar(3) | YES | | NULL | |
  17. | INDEX_TYPE | varchar(16) | YES | | NULL | |
  18. | COMMENT | varchar(16) | YES | | NULL | |
  19. | INDEX_COMMENT | varchar(1024) | YES | | NULL | |
  20. | IS_VISIBLE | varchar(3) | YES | | NULL | |
  21. | Expression | varchar(64) | YES | | NULL | |
  22. +---------------+---------------+------+------+---------+-------+
  23. 18 rows in set (0.00 sec)

Fields in the STATISTICS table are described as follows:

  • TABLE_CATALOG: The name of the catalog to which the table containing the index belongs. This value is always def.
  • TABLE_SCHEMA: The name of the database to which the table containing the index belongs.
  • TABLE_NAME: The name of the table containing the index.
  • NON_UNIQUE: If the index must not contain duplicate values, the value is 0; if duplicate values are allowed in the index, the value is 1.
  • INDEX_SCHEMA: The name of the database to which the index belongs.
  • INDEX_NAME: The name of the index. If the index is the primary key, then the value is always PRIMARY.
  • SEQ_IN_INDEX: The column number in the index, starting from 1.
  • COLUMN_NAME: The column name. See the description of the Expression column.
  • COLLATION: The sorting method of the columns in the index. The value can be A (ascending order), D (descending order) or NULL (unsorted).
  • CARDINALITY: TiDB does not use this field. The field value is always 0.
  • SUB_PART: The prefix of the index. If only part of the prefix of the column is indexed, the value is the number of indexed characters; if the entire column is indexed, the value is NULL.
  • PACKED: TiDB does not use this field. This value is always NULL.
  • NULLABLE: If the column might contain a NULL value, the value is YES; if not, the value is ''.
  • INDEX_TYPE: The type of the index.
  • COMMENT: Other information related to the index.
  • INDEX_COMMENT: Any comment with comment attribute provided for the index when creating the index.
  • IS_VISIBLE: Whether the optimizer can use this index.
  • Expression For the index key of the non-expression part, this value is NULL; for the index key of the expression part, this value is the expression itself. Refer to Expression Index.

The following statements are equivalent:

  1. SELECT * FROM INFORMATION_SCHEMA.STATISTICS
  2. WHERE table_name = 'tbl_name'
  3. AND table_schema = 'db_name'
  4. SHOW INDEX
  5. FROM tbl_name
  6. FROM db_name