From 2bc6b777e83a78f855ac834d6e4ba0f94b270993 Mon Sep 17 00:00:00 2001 From: Aolin Date: Wed, 7 Aug 2024 17:29:10 +0800 Subject: [PATCH 1/2] This is an automated cherry-pick of #18318 Signed-off-by: ti-chi-bot --- .../sql-statement-show-stats-buckets.md | 63 +++++++++++++++++++ system-variables.md | 2 +- 2 files changed, 64 insertions(+), 1 deletion(-) 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 000000000000..80b4b42b6f33 --- /dev/null +++ b/sql-statements/sql-statement-show-stats-buckets.md @@ -0,0 +1,63 @@ +--- +title: SHOW STATS_BUCKETS +summary: TiDB 数据库中 SHOW STATS_BUCKETS 的使用概况。 +--- + +# SHOW STATS_BUCKETS + +`SHOW STATS_BUCKETS` 语句显示[常规统计信息](/statistics.md)中桶的信息。 + +目前,`SHOW STATS_BUCKETS` 语句返回以下列: + +| 列名 | 说明 | +| :-------- | :------------- | +| `Db_name` | 数据库名 | +| `Table_name` | 表名 | +| `Partition_name` | 分区名 | +| `Column_name` | 取决于 `Is_index` 值:`Is_index` 为 `0` 时显示列名,为 `1` 时显示索引名 | +| `Is_index` | 是否是索引列 | +| `Bucket_id` | 桶的 ID | +| `Count` | 该桶和之前桶中所有数值的个数 | +| `Repeats` | 最大值的出现次数 | +| `Lower_bound` | 最小值 | +| `Upper_bound` | 最大值 | +| `Ndv` | 桶中不同值的数量。该字段已废弃,其值由于不准确会始终显示为 `0`。 | + +## 语法图 + +```ebnf+diagram +ShowStatsBucketsStmt ::= + "SHOW" "STATS_BUCKETS" ShowLikeOrWhere? +ShowLikeOrWhere ::= + "LIKE" SimpleExpr +| "WHERE" Expression +``` + +## 示例 + +```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 兼容性 + +该语句是 TiDB 对 MySQL 语法的扩展。 + +## 另请参阅 + +* [`ANALYZE`](/sql-statements/sql-statement-analyze-table.md) +* [常规统计信息](/statistics.md) \ No newline at end of file diff --git a/system-variables.md b/system-variables.md index 6a2e55713939..1caffcfed2d1 100644 --- a/system-variables.md +++ b/system-variables.md @@ -966,7 +966,7 @@ MPP 是 TiFlash 引擎提供的分布式计算框架,允许节点之间的数 ### `tidb_analyze_distsql_scan_concurrency` 从 v7.6.0 版本开始引入 -- 作用域:GLOBAL +- 作用域:SESSION | GLOBAL - 是否持久化到集群:是 - 是否受 Hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value) 控制:否 - 类型:整数型 From 9381ef1df43be66a052dacbd1df0bee36127d97e Mon Sep 17 00:00:00 2001 From: Aolin Date: Wed, 7 Aug 2024 17:50:43 +0800 Subject: [PATCH 2/2] resolve conflicts --- .../sql-statement-show-stats-buckets.md | 63 ------------------- statistics.md | 2 +- 2 files changed, 1 insertion(+), 64 deletions(-) delete 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 deleted file mode 100644 index 80b4b42b6f33..000000000000 --- a/sql-statements/sql-statement-show-stats-buckets.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: SHOW STATS_BUCKETS -summary: TiDB 数据库中 SHOW STATS_BUCKETS 的使用概况。 ---- - -# SHOW STATS_BUCKETS - -`SHOW STATS_BUCKETS` 语句显示[常规统计信息](/statistics.md)中桶的信息。 - -目前,`SHOW STATS_BUCKETS` 语句返回以下列: - -| 列名 | 说明 | -| :-------- | :------------- | -| `Db_name` | 数据库名 | -| `Table_name` | 表名 | -| `Partition_name` | 分区名 | -| `Column_name` | 取决于 `Is_index` 值:`Is_index` 为 `0` 时显示列名,为 `1` 时显示索引名 | -| `Is_index` | 是否是索引列 | -| `Bucket_id` | 桶的 ID | -| `Count` | 该桶和之前桶中所有数值的个数 | -| `Repeats` | 最大值的出现次数 | -| `Lower_bound` | 最小值 | -| `Upper_bound` | 最大值 | -| `Ndv` | 桶中不同值的数量。该字段已废弃,其值由于不准确会始终显示为 `0`。 | - -## 语法图 - -```ebnf+diagram -ShowStatsBucketsStmt ::= - "SHOW" "STATS_BUCKETS" ShowLikeOrWhere? -ShowLikeOrWhere ::= - "LIKE" SimpleExpr -| "WHERE" Expression -``` - -## 示例 - -```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 兼容性 - -该语句是 TiDB 对 MySQL 语法的扩展。 - -## 另请参阅 - -* [`ANALYZE`](/sql-statements/sql-statement-analyze-table.md) -* [常规统计信息](/statistics.md) \ No newline at end of file diff --git a/statistics.md b/statistics.md index ba5d423bca6f..e8a7ea851f6e 100644 --- a/statistics.md +++ b/statistics.md @@ -613,7 +613,7 @@ SHOW STATS_BUCKETS [ShowLikeOrWhere]; | repeats | 最大值出现的次数 | | lower_bound | 最小值 | | upper_bound | 最大值 | -| ndv | 当前桶内不同值的个数。当 `tidb_analyze_version` = 1 时,该值恒为 0,没有实际意义。 | +| Ndv | 桶中不同值的数量。该字段已废弃,其值由于不准确会始终显示为 `0`。 | ### Top-N 信息