From c484ea86569717f19e125271f6f08699344ac8db Mon Sep 17 00:00:00 2001 From: BohuTANG Date: Wed, 15 Oct 2025 10:33:19 +0000 Subject: [PATCH 1/3] chore: delete unsync files --- .../00-ddl/01-table/80-analyze-table.md | 79 ------------------- .../40-explain-cmds/explain-fragments.md | 36 --------- .../07-aggregate-functions/aggregate-any.md | 54 ------------- 3 files changed, 169 deletions(-) delete mode 100644 docs/cn/sql-reference/10-sql-commands/00-ddl/01-table/80-analyze-table.md delete mode 100644 docs/cn/sql-reference/10-sql-commands/40-explain-cmds/explain-fragments.md delete mode 100644 docs/cn/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-any.md diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/01-table/80-analyze-table.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/01-table/80-analyze-table.md deleted file mode 100644 index c292175926..0000000000 --- a/docs/cn/sql-reference/10-sql-commands/00-ddl/01-table/80-analyze-table.md +++ /dev/null @@ -1,79 +0,0 @@ ---- -title: ANALYZE TABLE -sidebar_position: 7 ---- - -计算表的各种统计信息。此命令在执行后*不*显示结果。要显示结果,请使用函数 [FUSE_STATISTIC](../../../20-sql-functions/16-system-functions/fuse_statistic.md)。 - -Databend 将每个表的统计数据保存为一个以 UUID(32 个字符的小写十六进制字符串)命名的 JSON 文件,并将这些文件存储在对象存储中的路径 `/[root]///`。 - -## 语法 - -```sql -ANALYZE TABLE [ . ] -``` - -- 该命令不是通过比较来识别不同的值,而是通过计算存储段和块的数量。这可能会导致估计结果与实际值之间存在显着差异,例如,多个块包含相同的值。在这种情况下,Databend 建议在运行估计之前,尽可能地压缩存储段和块以合并它们。 -- 执行 update/delete/replace 语句后,快照级别的列统计信息可能会被放大。您可以通过执行 analyze 语句来更正列统计信息。 - -## 示例 - -此示例估计表中每列的不同值的数量,并使用函数 [FUSE_STATISTIC](/sql/sql-functions/system-functions/fuse_statistic) 显示结果: - -```sql -CREATE TABLE sample ( - user_id INT, - name VARCHAR(50), - age INT -); - -INSERT INTO sample (user_id, name, age) VALUES -(1, 'Alice', 30), -(2, 'Bob', 25), -(3, 'Charlie', 35), -(4, 'Diana', 28), -(5, 'Eve', 28); - -SET enable_analyze_histogram = 1; - --- 在使用 ANALYZE TABLE 运行估计之前,FUSE_STATISTIC 不会返回任何结果。 -SELECT * FROM FUSE_STATISTIC('default', 'sample'); - -ANALYZE TABLE sample; - -SELECT * FROM FUSE_STATISTIC('default', 'sample'); - -┌─────────────┬────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ -│ column_name │ distinct_count │ histogram │ -├─────────────┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ -│ age │ 4 │ [bucket id: 0, min: "25", max: "25", ndv: 1.0, count: 1.0], [bucket id: 1, min: "28", max: "28", ndv: 1.0, count: 1.0], [bucket id: 2, min: "28", max: "28", ndv: 1.0, count: 1.0], [bucket id: 3, min: "30", max: "30", ndv: 1.0, count: 1.0], [bucket id: 4, min: "35", max: "35", ndv: 1.0, count: 1.0] │ -│ user_id │ 5 │ [bucket id: 0, min: "1", max: "1", ndv: 1.0, count: 1.0], [bucket id: 1, min: "2", max: "2", ndv: 1.0, count: 1.0], [bucket id: 2, min: "3", max: "3", ndv: 1.0, count: 1.0], [bucket id: 3, min: "4", max: "4", ndv: 1.0, count: 1.0], [bucket id: 4, min: "5", max: "5", ndv: 1.0, count: 1.0] │ -│ name │ 5 │ [bucket id: 0, min: "Alice", max: "Alice", ndv: 1.0, count: 1.0], [bucket id: 1, min: "Bob", max: "Bob", ndv: 1.0, count: 1.0], [bucket id: 2, min: "Charlie", max: "Charlie", ndv: 1.0, count: 1.0], [bucket id: 3, min: "Diana", max: "Diana", ndv: 1.0, count: 1.0], [bucket id: 4, min: "Eve", max: "Eve", ndv: 1.0, count: 1.0] │ -└─────────────┴────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ - -INSERT INTO sample (user_id, name, age) VALUES -(6, 'Frank', 40); - --- FUSE_STATISTIC 返回上次估计的结果。要获得最新的估计值,请再次运行 ANALYZE TABLE。 -SELECT * FROM FUSE_STATISTIC('default', 'sample'); - -┌─────────────┬────────────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ -│ column_name │ distinct_count │ histogram │ -├─────────────┼────────────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ -│ age │ 4 │ [bucket id: 0, min: "25", max: "25", ndv: 1.0, count: 1.0], [bucket id: 1, min: "28", max: "28", ndv: 1.0, count: 1.0], [bucket id: 2, min: "28", max: "28", ndv: 1.0, count: 1.0], [bucket id: 3, min: "30", max: "30", ndv: 1.0, count: 1.0], [bucket id: 4, min: "35", max: "35", ndv: 1.0, count: 1.0] │ -│ user_id │ 5 │ [bucket id: 0, min: "1", max: "1", ndv: 1.0, count: 1.0], [bucket id: 1, min: "2", max: "2", ndv: 1.0, count: 1.0], [bucket id: 2, min: "3", max: "3", ndv: 1.0, count: 1.0], [bucket id: 3, min: "4", max: "4", ndv: 1.0, count: 1.0], [bucket id: 4, min: "5", max: "5", ndv: 1.0, count: 1.0] │ -│ name │ 5 │ [bucket id: 0, min: "Alice", max: "Alice", ndv: 1.0, count: 1.0], [bucket id: 1, min: "Bob", max: "Bob", ndv: 1.0, count: 1.0], [bucket id: 2, min: "Charlie", max: "Charlie", ndv: 1.0, count: 1.0], [bucket id: 3, min: "Diana", max: "Diana", ndv: 1.0, count: 1.0], [bucket id: 4, min: "Eve", max: "Eve", ndv: 1.0, count: 1.0] │ -└─────────────┴────────────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ - -ANALYZE TABLE sample; - -SELECT * FROM FUSE_STATISTIC('default', 'sample'); -``` - -┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ -│ column_name │ distinct_count │ histogram │ -├─────────────┼────────────────┼────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ -│ name │ 6 │ [bucket id: 0, min: "Alice", max: "Alice", ndv: 1.0, count: 1.0], [bucket id: 1, min: "Bob", max: "Bob", ndv: 1.0, count: 1.0], [bucket id: 2, min: "Charlie", max: "Charlie", ndv: 1.0, count: 1.0], [bucket id: 3, min: "Diana", max: "Diana", ndv: 1.0, count: 1.0], [bucket id: 4, min: "Eve", max: "Eve", ndv: 1.0, count: 1.0], [bucket id: 5, min: "Frank", max: "Frank", ndv: 1.0, count: 1.0] │ -│ age │ 5 │ [bucket id: 0, min: "25", max: "25", ndv: 1.0, count: 1.0], [bucket id: 1, min: "28", max: "28", ndv: 1.0, count: 1.0], [bucket id: 2, min: "28", max: "28", ndv: 1.0, count: 1.0], [bucket id: 3, min: "30", max: "30", ndv: 1.0, count: 1.0], [bucket id: 4, min: "35", max: "35", ndv: 1.0, count: 1.0], [bucket id: 5, min: "40", max: "40", ndv: 1.0, count: 1.0] │ -│ user_id │ 6 │ [bucket id: 0, min: "1", max: "1", ndv: 1.0, count: 1.0], [bucket id: 1, min: "2", max: "2", ndv: 1.0, count: 1.0], [bucket id: 2, min: "3", max: "3", ndv: 1.0, count: 1.0], [bucket id: 3, min: "4", max: "4", ndv: 1.0, count: 1.0], [bucket id: 4, min: "5", max: "5", ndv: 1.0, count: 1.0], [bucket id: 5, min: "6", max: "6", ndv: 1.0, count: 1.0] │ -└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ diff --git a/docs/cn/sql-reference/10-sql-commands/40-explain-cmds/explain-fragments.md b/docs/cn/sql-reference/10-sql-commands/40-explain-cmds/explain-fragments.md deleted file mode 100644 index 7e0d20a0ca..0000000000 --- a/docs/cn/sql-reference/10-sql-commands/40-explain-cmds/explain-fragments.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: EXPLAIN FRAGMENTS ---- - -展示 SQL 语句的分布式执行计划。 - -此命令将 SQL 语句的执行计划转换为 plan fragments,您可以在其中查看从 Databend 检索所需数据的过程。 - -## 语法 - -```sql -EXPLAIN FRAGMENTS -``` - -## 示例 - -```sql -EXPLAIN FRAGMENTS select COUNT() from numbers(10) GROUP BY number % 3; - -+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| explain | -+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -| Fragment 0: | -| DataExchange: Shuffle | -| AggregatorPartial: groupBy=[[(number % 3)]], aggr=[[COUNT()]] | -| Expression: (number % 3):UInt8 (Before GroupBy) | -| ReadDataSource: scan schema: [number:UInt64], statistics: [read_rows: 10, read_bytes: 80, partitions_scanned: 1, partitions_total: 1], push_downs: [projections: [0]] | -| | -| Fragment 2: | -| DataExchange: Merge | -| Projection: COUNT():UInt64 | -| AggregatorFinal: groupBy=[[(number % 3)]], aggr=[[COUNT()]] | -| Remote[receive fragment: 0] | -+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ -11 rows in set (0.02 sec) -``` \ No newline at end of file diff --git a/docs/cn/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-any.md b/docs/cn/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-any.md deleted file mode 100644 index b603e6f5c9..0000000000 --- a/docs/cn/sql-reference/20-sql-functions/07-aggregate-functions/aggregate-any.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: ANY ---- - -聚合函数。 - -ANY() 函数选择第一个遇到的(非 NULL)值,除非该列的所有行都是 NULL 值。查询可以以任何顺序执行,甚至每次顺序都不同,因此该函数的结果是不确定的。要获得确定的结果,可以使用 'min' 或 'max' 函数代替 'any'。 - -## 语法 - -```sql -ANY() -``` - -## 参数 - -| 参数 | 描述 | -|-----------|--------------| -| `` | 任何表达式 | - -## 返回类型 - -第一个遇到的(非 NULL)值,类型与值相同。如果所有值都是 NULL,则返回值为 NULL。 - -## 示例 - -**创建表并插入示例数据** -```sql -CREATE TABLE product_data ( - id INT, - product_name VARCHAR NULL, - price FLOAT NULL -); - -INSERT INTO product_data (id, product_name, price) -VALUES (1, 'Laptop', 1000), - (2, NULL, 800), - (3, 'Keyboard', NULL), - (4, 'Mouse', 25), - (5, 'Monitor', 150); -``` - -**查询示例:检索第一个遇到的非 NULL 产品名称** -```sql -SELECT ANY(product_name) AS any_product_name -FROM product_data; -``` - -**结果** -```sql -| any_product_name | -|------------------| -| Laptop | -``` \ No newline at end of file From f73c29acae20b961931b127ea1a83718eea52af1 Mon Sep 17 00:00:00 2001 From: BohuTANG Date: Wed, 15 Oct 2025 10:33:22 +0000 Subject: [PATCH 2/3] [INIT] Start translation to Simplified-Chinese --- .translation-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.translation-init b/.translation-init index 30ba10e4cb..91e10892e0 100644 --- a/.translation-init +++ b/.translation-init @@ -1 +1 @@ -Translation initialization: 2025-10-13T04:21:09.341216 +Translation initialization: 2025-10-15T10:33:22.601610 From 335b45223d596b6cc4dff91265efee76acfffec1 Mon Sep 17 00:00:00 2001 From: BohuTANG Date: Wed, 15 Oct 2025 10:34:00 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8C=90=20Translate=20show-statistics.?= =?UTF-8?q?md=20to=20Simplified-Chinese?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../00-ddl/01-table/show-statistics.md | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 docs/cn/sql-reference/10-sql-commands/00-ddl/01-table/show-statistics.md diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/01-table/show-statistics.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/01-table/show-statistics.md new file mode 100644 index 0000000000..7e9e7cf597 --- /dev/null +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/01-table/show-statistics.md @@ -0,0 +1,88 @@ +--- +title: SHOW STATISTICS +sidebar_position: 15 +--- +import FunctionDescription from '@site/src/components/FunctionDescription'; + + + +显示表及其列的统计信息。统计信息通过提供数据分布、行数和唯一值等信息,帮助查询优化器(Query Optimizer)制定更优的查询执行计划。 + +Databend 在数据插入期间自动生成统计信息。你可以使用此命令查看统计信息,并将其与实际数据进行比对,以发现可能影响查询性能的差异。 + +## 语法 + +```sql +SHOW STATISTICS [ FROM DATABASE | FROM TABLE . ] +``` + +| 参数 | 说明 | +|-----------|-----------------------------------------------------------------------------------------------------------------------------| +| FROM DATABASE | 显示指定数据库中所有表的统计信息。 | +| FROM TABLE | 仅显示指定表的统计信息。 | + +如果未指定参数,该命令将返回当前数据库中所有表的统计信息。 + +## 输出列 + +该命令为每个表中的每一列返回以下列: + +| 列 | 说明 | +|--------|-----------------------------------------------------------------------------------------------------------------------------| +| database | 数据库名称。 | +| table | 表名称。 | +| column_name | 列名称。 | +| stats_row_count | 统计信息中累计的行数。由于统计信息在插入时更新,但在删除时不减少,因此该数值可能 **大于** actual_row_count。 | +| actual_row_count | 当前快照下表中的实际行数。 | +| distinct_count | 唯一值(NDV)的估计数量,通过 HyperLogLog 计算得出。 | +| null_count | 列中 NULL 值的数量。 | +| avg_size | 列中每个值的平均大小(以字节为单位)。 | + +## 示例 + +### 显示当前数据库的统计信息 + +```sql +CREATE DATABASE test_db; +USE test_db; + +CREATE TABLE t1 (id INT, name VARCHAR(50)); +INSERT INTO t1 VALUES (1, 'Alice'), (2, 'Bob'); + +SHOW STATISTICS; +``` + +输出: +``` +database table column_name stats_row_count actual_row_count distinct_count null_count avg_size +test_db t1 id 2 2 2 0 4 +test_db t1 name 2 2 2 0 16 +``` + +### 显示指定表的统计信息 + +```sql +CREATE TABLE t2 (age INT, city VARCHAR(50)); +INSERT INTO t2 VALUES (25, 'New York'), (30, 'London'); + +SHOW STATISTICS FROM TABLE test_db.t2; +``` + +输出: +``` +database table column_name stats_row_count actual_row_count distinct_count null_count avg_size +test_db t2 age 2 2 2 0 4 +test_db t2 city 2 2 2 0 19 +``` + +### 显示数据库中所有表的统计信息 + +```sql +SHOW STATISTICS FROM DATABASE test_db; +``` + +这将显示 `test_db` 数据库中所有表(`t1` 和 `t2`)的统计信息。 + +## 相关命令 + +- [SHOW TABLE STATUS](show-table-status.md): 显示表的状态信息 \ No newline at end of file