From a160d82c8fe7b02e167a3c475cfa2bfd1f4a277c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E6=89=8B=E6=8E=89=E5=8C=85=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E5=B8=88?= Date: Wed, 7 Aug 2024 16:11:10 +0800 Subject: [PATCH] This is an automated cherry-pick of #18499 Signed-off-by: ti-chi-bot --- .../sql-statement-show-stats-buckets.md | 64 +++++++++++++++++++ system-variables.md | 6 +- 2 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 sql-statements/sql-statement-show-stats-buckets.md diff --git a/sql-statements/sql-statement-show-stats-buckets.md b/sql-statements/sql-statement-show-stats-buckets.md new file mode 100644 index 0000000000000..f1df822e205d3 --- /dev/null +++ b/sql-statements/sql-statement-show-stats-buckets.md @@ -0,0 +1,64 @@ +--- +title: SHOW STATS_BUCKETS +summary: An overview of the usage of SHOW STATS_BUCKETS for TiDB database. +--- + +# SHOW STATS_BUCKETS + +The `SHOW STATS_BUCKETS` statement shows the bucket information in [statistics](/statistics.md). + +Currently, the `SHOW STATS_BUCKETS` statement returns the following columns: + +| Column name | Description | +| :-------- | :------------- | +| `Db_name` | The database name | +| `Table_name` | The table name | +| `Partition_name` | The partition name | +| `Column_name` | The column name (when `is_index` is `0`) or the index name (when `is_index` is `1`) | +| `Is_index` | Whether it is an index column or not | +| `Bucket_id` | The ID of a bucket | +| `Count` | The number of all the values that falls on the bucket and the previous buckets | +| `Repeats` | The occurrence number of the maximum value | +| `Lower_bound` | The minimum value | +| `Upper_bound` | The maximum value | +| `Ndv` | The number of distinct values in the bucket. This field is deprecated and always shows `0` due to its inaccurate value. | + +## Synopsis + +```ebnf+diagram +ShowStatsBucketsStmt ::= + "SHOW" "STATS_BUCKETS" ShowLikeOrWhere? + +ShowLikeOrWhere ::= + "LIKE" SimpleExpr +| "WHERE" Expression +``` + +## Examples + +```sql +SHOW STATS_BUCKETS WHERE Table_name='t'; +``` + +``` ++---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+ +| Db_name | Table_name | Partition_name | Column_name | Is_index | Bucket_id | Count | Repeats | Lower_Bound | Upper_Bound | Ndv | ++---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+ +| test | t | | a | 0 | 0 | 1 | 1 | 2023-12-27 00:00:00 | 2023-12-27 00:00:00 | 0 | +| test | t | | a | 0 | 1 | 2 | 1 | 2023-12-28 00:00:00 | 2023-12-28 00:00:00 | 0 | +| test | t | | ia | 1 | 0 | 1 | 1 | (NULL, 2) | (NULL, 2) | 0 | +| test | t | | ia | 1 | 1 | 2 | 1 | (NULL, 4) | (NULL, 4) | 0 | +| test | t | | ia | 1 | 2 | 3 | 1 | (2023-12-27 00:00:00, 1) | (2023-12-27 00:00:00, 1) | 0 | +| test | t | | ia | 1 | 3 | 4 | 1 | (2023-12-28 00:00:00, 3) | (2023-12-28 00:00:00, 3) | 0 | ++---------+------------+----------------+-------------+----------+-----------+-------+---------+--------------------------+--------------------------+------+ +6 rows in set (0.00 sec) +``` + +## MySQL compatibility + +This statement is a TiDB extension to MySQL syntax. + +## See also + +* [`ANALYZE`](/sql-statements/sql-statement-analyze-table.md) +* [Introduction to Statistics](/statistics.md) diff --git a/system-variables.md b/system-variables.md index 3958bd558fefa..35bbcbb94b326 100644 --- a/system-variables.md +++ b/system-variables.md @@ -1113,7 +1113,7 @@ MPP is a distributed computing framework provided by the TiFlash engine, which a ### tidb_analyze_distsql_scan_concurrency New in v7.6.0 -- Scope: GLOBAL +- Scope: SESSION | GLOBAL - Persists to cluster: Yes - Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No - Type: Integer @@ -1359,7 +1359,7 @@ mysql> SELECT job_info FROM mysql.analyze_jobs ORDER BY end_time DESC LIMIT 1; ### tidb_build_sampling_stats_concurrency New in v7.5.0 -- Scope: GLOBAL +- Scope: SESSION | GLOBAL - Persists to cluster: Yes - Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No - Type: Integer @@ -4274,7 +4274,7 @@ mysql> desc select count(distinct a) from test.t; +-----------------------------------+---------+-----------+-----------------------+---------------------------------+ ``` -- The second example uses `0`, which assumes that 0% of rows will be scanned before the qualified rows are found. +- The second example uses `0`, which assumes that 0% of rows will be scanned before the qualified rows are found. ```sql > SET SESSION tidb_opt_ordering_index_selectivity_ratio = 0;