|
| 1 | +--- |
| 2 | +title: SHOW STATS_BUCKETS |
| 3 | +summary: An overview of the usage of SHOW STATS_BUCKETS for TiDB database. |
| 4 | +--- |
| 5 | + |
| 6 | +# SHOW STATS_BUCKETS |
| 7 | + |
| 8 | +The `SHOW STATS_BUCKETS` statement shows the bucket information in [statistics](/statistics.md). |
| 9 | + |
| 10 | +Currently, the `SHOW STATS_BUCKETS` statement returns the following columns: |
| 11 | + |
| 12 | +| Column name | Description | |
| 13 | +| :-------- | :------------- | |
| 14 | +| `Db_name` | The database name | |
| 15 | +| `Table_name` | The table name | |
| 16 | +| `Partition_name` | The partition name | |
| 17 | +| `Column_name` | The column name (when `is_index` is `0`) or the index name (when `is_index` is `1`) | |
| 18 | +| `Is_index` | Whether it is an index column or not | |
| 19 | +| `Bucket_id` | The ID of a bucket | |
| 20 | +| `Count` | The number of all the values that falls on the bucket and the previous buckets | |
| 21 | +| `Repeats` | The occurrence number of the maximum value | |
| 22 | +| `Lower_bound` | The minimum value | |
| 23 | +| `Upper_bound` | The maximum value | |
| 24 | +| `Ndv` | The number of distinct values in the bucket. This field is deprecated and always shows `0` due to its inaccurate value. | |
| 25 | + |
| 26 | +## Synopsis |
| 27 | + |
| 28 | +```ebnf+diagram |
| 29 | +ShowStatsBucketsStmt ::= |
| 30 | + "SHOW" "STATS_BUCKETS" ShowLikeOrWhere? |
| 31 | +
|
| 32 | +ShowLikeOrWhere ::= |
| 33 | + "LIKE" SimpleExpr |
| 34 | +| "WHERE" Expression |
| 35 | +``` |
| 36 | + |
| 37 | +## Examples |
| 38 | + |
| 39 | +```sql |
| 40 | +SHOW STATS_BUCKETS WHERE Table_name='t'; |
| 41 | +``` |
| 42 | + |
| 43 | +``` |
| 44 | ++---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+ |
| 45 | +| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count | Repeats | Lower_Bound | Upper_Bound | Ndv | |
| 46 | ++---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+ |
| 47 | +| test | t | | a | 0 | 0 | 1 | 1 | 2023-12-27 00:00:00 | 2023-12-27 00:00:00 | 0 | |
| 48 | +| test | t | | a | 0 | 1 | 2 | 1 | 2023-12-28 00:00:00 | 2023-12-28 00:00:00 | 0 | |
| 49 | +| test | t | | ia | 1 | 0 | 1 | 1 | (NULL, 2) | (NULL, 2) | 0 | |
| 50 | +| test | t | | ia | 1 | 1 | 2 | 1 | (NULL, 4) | (NULL, 4) | 0 | |
| 51 | +| test | t | | ia | 1 | 2 | 3 | 1 | (2023-12-27 00:00:00, 1) | (2023-12-27 00:00:00, 1) | 0 | |
| 52 | +| test | t | | ia | 1 | 3 | 4 | 1 | (2023-12-28 00:00:00, 3) | (2023-12-28 00:00:00, 3) | 0 | |
| 53 | ++---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+ |
| 54 | +6 rows in set (0.00 sec) |
| 55 | +``` |
| 56 | + |
| 57 | +## MySQL compatibility |
| 58 | + |
| 59 | +This statement is a TiDB extension to MySQL syntax. |
| 60 | + |
| 61 | +## See also |
| 62 | + |
| 63 | +* [`ANALYZE`](/sql-statements/sql-statement-analyze-table.md) |
| 64 | +* [Introduction to Statistics](/statistics.md) |
0 commit comments