SHOW STATS_TOPN

The SHOW STATS_TOPN statement shows the Top-N information in statistics.

Currently, the SHOW STATS_TOPN statement returns the following columns:

Column nameDescription
Db_nameThe database name
Table_nameThe table name
Partition_nameThe partition name
Column_nameThe column name (when is_index is 0) or the index name (when is_index is 1)
Is_indexWhether it is an index column or not
ValueThe value of this column
CountHow many times the value appears

Synopsis

ShowStatsTopnStmt

SHOW STATS_TOPN - 图1

ShowLikeOrWhere

SHOW STATS_TOPN - 图2

  1. ShowStatsTopnStmt ::=
  2. "SHOW" "STATS_TOPN" ShowLikeOrWhere?
  3. ShowLikeOrWhere ::=
  4. "LIKE" SimpleExpr
  5. | "WHERE" Expression

Example

  1. SHOW STATS_TOPN WHERE Table_name='t';
  1. +---------+------------+----------------+-------------+----------+--------------------------+-------+
  2. | Db_name | Table_name | Partition_name | Column_name | Is_index | Value | Count |
  3. +---------+------------+----------------+-------------+----------+--------------------------+-------+
  4. | test | t | | a | 0 | 2023-12-27 00:00:00 | 1 |
  5. | test | t | | a | 0 | 2023-12-28 00:00:00 | 1 |
  6. | test | t | | ia | 1 | (NULL, 2) | 1 |
  7. | test | t | | ia | 1 | (NULL, 4) | 1 |
  8. | test | t | | ia | 1 | (2023-12-27 00:00:00, 1) | 1 |
  9. | test | t | | ia | 1 | (2023-12-28 00:00:00, 3) | 1 |
  10. +---------+------------+----------------+-------------+----------+--------------------------+-------+
  11. 6 rows in set (0.00 sec)

MySQL compatibility

This statement is a TiDB extension to MySQL syntax.

See also