Skip to content

Commit f579acf

Browse files
committed
Merge remote-tracking branch 'origin/main' into fix-with-clause-and-improve-sql-docs
2 parents 3ffbfda + 57d1643 commit f579acf

File tree

8 files changed

+294
-90
lines changed

8 files changed

+294
-90
lines changed

.translation-init

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
Translation initialization: 2025-08-27T10:20:13.083836
2-
1+
Translation initialization: 2025-08-29T07:40:58.697374
Lines changed: 56 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,62 @@
11
---
2-
title: DDL (数据定义语言) 命令
2+
title: DDL(Data Definition Language)命令
33
---
44

5-
这些主题提供了 Databend 中 DDL (数据定义语言) 命令的参考信息。
5+
这些主题提供了 Databend 中 DDL(Data Definition Language)命令的参考信息。
66

77
## 数据库和表管理
88

9-
- [数据库](00-database/index.md)
10-
- [](01-table/index.md)
11-
- [视图](05-view/index.md)
12-
- [字典](17-dictionary/index.md)
13-
14-
## 数据库性能和索引
15-
16-
- [聚簇键](06-clusterkey/index.md)
17-
- [聚合索引](07-aggregating-index/index.md)
18-
- [倒排索引](07-inverted-index/index.md)
19-
- [Ngram 索引](07-ngram-index/index.md)
20-
- [虚拟列](07-virtual-column/index.md)
21-
22-
## 用户、角色和安全管理
23-
24-
- [用户](02-user/index.md)
25-
- [网络策略](12-network-policy/index.md)
26-
- [掩码策略](12-mask-policy/index.md)
27-
- [密码策略](12-password-policy/index.md)
28-
29-
## 数据暂存和处理
30-
31-
- [Stage](03-stage/index.md)
32-
- [](04-stream/index.md)
33-
- [序列](04-sequence/index.md)
34-
- [任务](04-task/index.md)
35-
- [连接](13-connection/index.md)
36-
- [文件格式](13-file-format/index.md)
37-
38-
## 事务和变量管理
39-
40-
- [事务](14-transaction/index.md)
41-
- [变量](15-variable/index.md)
42-
43-
## 函数和外部集成
44-
45-
- [UDF (用户自定义函数)](10-udf/index.md)
46-
- [外部函数](11-external-function/index.md)
47-
- [存储过程](18-procedure/index.md)
48-
- [通知](16-notification/index.md)
49-
50-
## 计算资源管理
51-
52-
- [计算集群](19-warehouse/index.md)
9+
| 组件 | 描述 |
10+
|-----------|-------------|
11+
| **[数据库](00-database/index.md)** | 创建、修改和删除数据库 |
12+
| **[](01-table/index.md)** | 创建、修改和管理表 |
13+
| **[视图 (View)](05-view/index.md)** | 基于查询创建和管理虚拟表 |
14+
| **[字典 (Dictionary)](17-dictionary/index.md)** | 创建用于数据丰富的键值查找表 |
15+
16+
## 性能和索引
17+
18+
| 组件 | 描述 |
19+
|-----------|-------------|
20+
| **[聚簇键 (Cluster Key)](06-clusterkey/index.md)** | 为查询优化定义数据聚簇 |
21+
| **[聚合索引 (Aggregating Index)](07-aggregating-index/index.md)** | 预计算聚合以加快查询速度 |
22+
| **[倒排索引 (Inverted Index)](07-inverted-index/index.md)** | 用于文本列的全文搜索索引 |
23+
| **[Ngram 索引 (Ngram Index)](07-ngram-index/index.md)** | 用于 LIKE 模式的子字符串搜索索引 |
24+
| **[虚拟列 (Virtual Column)](07-virtual-column/index.md)** | 将 JSON 字段提取并索引为虚拟列 |
25+
26+
## 安全和访问控制
27+
28+
| 组件 | 描述 |
29+
|-----------|-------------|
30+
| **[用户](02-user/index.md)** | 创建和管理数据库用户 |
31+
| **[网络策略 (Network Policy)](12-network-policy/index.md)** | 控制对数据库的网络访问 |
32+
| **[掩码策略 (Mask Policy)](12-mask-policy/index.md)** | 为敏感信息应用数据掩码 |
33+
| **[密码策略 (Password Policy)](12-password-policy/index.md)** | 强制执行密码要求和轮换 |
34+
35+
## 数据集成和处理
36+
37+
| 组件 | 描述 |
38+
|-----------|-------------|
39+
| **[暂存区 (Stage)](03-stage/index.md)** | 为数据加载定义存储位置 |
40+
| **[流 (Stream)](04-stream/index.md)** | 捕获和处理数据变更 |
41+
| **[任务 (Task)](04-task/index.md)** | 调度和自动化 SQL 操作 |
42+
| **[序列 (Sequence)](04-sequence/index.md)** | 生成唯一的序列号 |
43+
| **[连接 (Connection)](13-connection/index.md)** | 配置外部数据源连接 |
44+
| **[文件格式 (File Format)](13-file-format/index.md)** | 为数据导入/导出定义格式 |
45+
46+
## 函数和存储过程
47+
48+
| 组件 | 描述 |
49+
|-----------|-------------|
50+
| **[UDF](10-udf/index.md)** | 使用 Python 或 JavaScript 创建自定义函数 |
51+
| **[外部函数 (External Function)](11-external-function/index.md)** | 将外部 API 集成为 SQL 函数 |
52+
| **[存储过程 (Procedure)](18-procedure/index.md)** | 为复杂逻辑创建存储过程 |
53+
| **[通知 (Notification)](16-notification/index.md)** | 设置事件通知和 Webhook |
54+
55+
## 资源管理
56+
57+
| 组件 | 描述 |
58+
|-----------|-------------|
59+
| **[计算集群 (Warehouse)](19-warehouse/index.md)** | 管理用于查询执行的计算资源 |
60+
| **[工作负载组 (Workload Group)](20-workload-group/index.md)** | 控制资源分配和优先级 |
61+
| **[事务 (Transaction)](14-transaction/index.md)** | 管理数据库事务 |
62+
| **[变量 (Variable)](15-variable/index.md)** | 设置和使用会话/全局变量 |
Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
---
2-
title: DML (数据操作语言) 命令
2+
title: DML数据操作语言命令
33
---
4-
import IndexOverviewList from '@site/src/components/IndexOverviewList';
54

6-
本页提供 Databend 中 DML (数据操作语言) 命令的参考信息。
5+
本页面提供 Databend 中 DML数据操作语言命令的参考信息。
76

8-
<IndexOverviewList />
7+
## 数据修改
8+
9+
| 命令 | 描述 |
10+
|---------|-------------|
11+
| **[INSERT](dml-insert)** | 向表中添加新行 |
12+
| **[INSERT MULTI](dml-insert-multi)** | 在一个语句中向多个表插入数据 |
13+
| **[UPDATE](dml-update)** | 修改表中的现有行 |
14+
| **[DELETE](dml-delete-from)** | 从表中删除行 |
15+
| **[REPLACE](dml-replace)** | 插入新行或更新现有行 |
16+
| **[MERGE](dml-merge)** | 根据条件执行 upsert(更新插入)操作 |
17+
18+
## 数据加载与导出
19+
20+
| 命令 | 描述 |
21+
|---------|-------------|
22+
| **[COPY INTO Table](dml-copy-into-table)** | 将数据从文件加载到表中 |
23+
| **[COPY INTO Location](dml-copy-into-location)** | 将表数据导出到文件 |
Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,59 @@
11
---
22
title: 查询语法
33
---
4-
import IndexOverviewList from '@site/src/components/IndexOverviewList';
54

6-
本页提供 Databend 中查询语法的参考信息
5+
本页面提供 Databend 查询语法的参考信息。每个组件都可以单独使用,也可以组合起来构建强大的查询
76

8-
<IndexOverviewList />
7+
## 核心查询组件
8+
9+
| 组件 | 描述 |
10+
|-----------|-------------|
11+
| **[SELECT](query-select)** | 从表中检索数据——所有查询的基础 |
12+
| **[FROM / JOIN](query-join)** | 指定数据源并组合多个表 |
13+
| **[WHERE](query-select#where-clause)** | 根据条件过滤行 |
14+
| **[GROUP BY](query-group-by)** | 对行进行分组并执行聚合(SUM、COUNT、AVG 等) |
15+
| **[HAVING](query-group-by#having-clause)** | 过滤分组后的结果 |
16+
| **[ORDER BY](query-select#order-by-clause)** | 对查询结果排序 |
17+
| **[LIMIT / TOP](top)** | 限制返回的行数 |
18+
19+
## 高级功能
20+
21+
| 组件 | 描述 |
22+
|-----------|-------------|
23+
| **[WITH (CTE)](with-clause)** | 定义可复用的查询块,用于复杂逻辑 |
24+
| **[PIVOT](query-pivot)** | 将行转换为列(宽格式) |
25+
| **[UNPIVOT](query-unpivot)** | 将列转换为行(长格式) |
26+
| **[QUALIFY](qualify)** | 在窗口函数计算后过滤行 |
27+
| **[VALUES](values)** | 创建内联临时数据集 |
28+
29+
## 时间回溯与流式处理
30+
31+
| 组件 | 描述 |
32+
|-----------|-------------|
33+
| **[AT](query-at)** | 查询特定时间点的数据 |
34+
| **[CHANGES](changes)** | 跟踪插入、更新和删除 |
35+
| **[WITH CONSUME](with-consume)** | 通过偏移量管理处理流式数据 |
36+
| **[WITH STREAM HINTS](with-stream-hints)** | 优化流处理行为 |
37+
38+
## 查询执行
39+
40+
| 组件 | 描述 |
41+
|-----------|-------------|
42+
| **[Settings](settings)** | 配置查询优化和执行参数 |
43+
44+
## 查询结构
45+
46+
一个典型的 Databend 查询遵循以下结构:
47+
48+
```sql
49+
[WITH cte_expressions]
50+
SELECT [TOP n] columns
51+
FROM table
52+
[JOIN other_tables]
53+
[WHERE conditions]
54+
[GROUP BY columns]
55+
[HAVING group_conditions]
56+
[QUALIFY window_conditions]
57+
[ORDER BY columns]
58+
[LIMIT n]
59+
```

docs/cn/sql-reference/10-sql-commands/20-query-syntax/with-clause.md

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,102 @@
22
title: WITH 子句
33
---
44

5-
Databend 使用 WITH 子句来定义公用表表达式(Common Table Expressions, CTE)。
5+
WITH 子句是一个可选子句,位于 SELECT 语句主体之前,用于定义一个或多个可在语句后续部分引用的公用表表达式(CTE,Common Table Expression)。
6+
7+
## 语法
8+
9+
### 基本 CTE
10+
11+
```sql
12+
[ WITH
13+
cte_name1 [ ( cte_column_list ) ] AS ( SELECT ... )
14+
[ , cte_name2 [ ( cte_column_list ) ] AS ( SELECT ... ) ]
15+
[ , cte_nameN [ ( cte_column_list ) ] AS ( SELECT ... ) ]
16+
]
17+
SELECT ...
18+
```
19+
20+
### 递归 CTE
21+
22+
```sql
23+
[ WITH [ RECURSIVE ]
24+
cte_name1 ( cte_column_list ) AS ( anchorClause UNION ALL recursiveClause )
25+
[ , cte_name2 ( cte_column_list ) AS ( anchorClause UNION ALL recursiveClause ) ]
26+
[ , cte_nameN ( cte_column_list ) AS ( anchorClause UNION ALL recursiveClause ) ]
27+
]
28+
SELECT ...
29+
```
30+
31+
其中:
32+
- `anchorClause`: `SELECT anchor_column_list FROM ...`
33+
- `recursiveClause`: `SELECT recursive_column_list FROM ... [ JOIN ... ]`
34+
35+
## 参数
36+
37+
| 参数 | 描述 |
38+
|-----------|-------------|
39+
| `cte_name` | CTE 名称必须遵循标准标识符规则 |
40+
| `cte_column_list` | CTE 中的列名 |
41+
| `anchor_column_list` | 递归 CTE 中锚点子句使用的列 |
42+
| `recursive_column_list` | 递归 CTE 中递归子句使用的列 |
43+
44+
## 示例
45+
46+
### 基本 CTE
47+
48+
```sql
49+
WITH high_value_customers AS (
50+
SELECT customer_id, customer_name, total_spent
51+
FROM customers
52+
WHERE total_spent > 10000
53+
)
54+
SELECT c.customer_name, o.order_date, o.order_amount
55+
FROM high_value_customers c
56+
JOIN orders o ON c.customer_id = o.customer_id
57+
ORDER BY o.order_date DESC;
58+
```
59+
60+
### 多个 CTE
61+
62+
```sql
63+
WITH
64+
regional_sales AS (
65+
SELECT region, SUM(sales_amount) as total_sales
66+
FROM sales_data
67+
GROUP BY region
68+
),
69+
top_regions AS (
70+
SELECT region, total_sales
71+
FROM regional_sales
72+
WHERE total_sales > 1000000
73+
)
74+
SELECT r.region, r.total_sales
75+
FROM top_regions r
76+
ORDER BY r.total_sales DESC;
77+
```
78+
79+
### 递归 CTE
80+
81+
```sql
82+
WITH RECURSIVE countdown AS (
83+
-- 锚点子句:起始点
84+
SELECT 10 as num
85+
86+
UNION ALL
87+
88+
-- 递归子句:重复执行直到满足条件
89+
SELECT num - 1
90+
FROM countdown
91+
WHERE num > 1 -- 停止条件
92+
)
93+
SELECT num FROM countdown
94+
ORDER BY num DESC;
95+
```
96+
97+
## 使用须知
98+
99+
- CTE 是临时的命名结果集,仅在查询期间存在
100+
- 在同一个 WITH 子句中,CTE 名称必须是唯一的
101+
- 一个 CTE 可以引用在同一个 WITH 子句中先前定义的 CTE
102+
- 递归 CTE 需要一个锚点子句和一个递归子句,并通过 UNION ALL 连接
103+
- 使用递归 CTE 时,需要使用 RECURSIVE 关键字
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
---
2-
title: 查询运算符
2+
title: 查询算子
33
---
4-
import IndexOverviewList from '@site/src/components/IndexOverviewList';
54

6-
本页提供 Databend 中查询运算符的参考信息
5+
本页面提供 Databend 中查询算子 (Query Operators) 的参考信息
76

8-
<IndexOverviewList />
7+
## 算子类型
8+
9+
| 算子类型 | 描述 |
10+
|--------------|-------------|
11+
| **[算术](arithmetic)** | 数学运算(+、-、*、/、%、DIV) |
12+
| **[比较](comparison)** | 值比较(=、!=、<、>、<=、>=、BETWEEN、IN) |
13+
| **[逻辑](logical)** | 布尔逻辑(AND、OR、NOT、XOR) |
14+
| **[JSON](json)** | JSON 数据操作(::、->、->>、@>、<@) |
15+
| **[集合](set)** | 组合查询结果(UNION、INTERSECT、EXCEPT) |
16+
| **[子查询](subquery)** | 嵌套查询(EXISTS、IN、ANY、ALL、SOME) |
Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,46 @@
11
---
22
title: 管理命令
33
---
4-
import IndexOverviewList from '@site/src/components/IndexOverviewList';
54

6-
本页提供 Databend 中系统管理命令的参考信息。
5+
本页面提供 Databend 中系统管理命令的参考信息。
76

8-
<IndexOverviewList />
7+
## 系统监控
8+
9+
| 命令 | 说明 |
10+
|---------|-------------|
11+
| **[SHOW PROCESSLIST](07-show-processlist.md)** | 显示活动查询和连接 |
12+
| **[SHOW METRICS](08-show-metrics.md)** | 查看系统性能指标 |
13+
| **[KILL](01-kill.md)** | 终止正在运行的查询或连接 |
14+
| **[RUST BACKTRACE](rust-backtrace.md)** | 调试 Rust 堆栈跟踪 |
15+
16+
## 配置管理
17+
18+
| 命令 | 说明 |
19+
|---------|-------------|
20+
| **[SET](02-set-global.md)** | 设置全局配置参数 |
21+
| **[UNSET](02-unset.md)** | 移除配置设置 |
22+
| **[SET VARIABLE](03-set-var.md)** | 管理用户定义变量 |
23+
| **[SHOW SETTINGS](03-show-settings.md)** | 显示当前系统设置 |
24+
25+
## 函数管理
26+
27+
| 命令 | 说明 |
28+
|---------|-------------|
29+
| **[SHOW FUNCTIONS](04-show-functions.md)** | 列出内置函数 |
30+
| **[SHOW USER FUNCTIONS](05-show-user-functions.md)** | 列出用户定义函数 |
31+
| **[SHOW TABLE FUNCTIONS](06-show-table-functions.md)** | 列出表值函数(Table-Valued Function) |
32+
33+
## 存储维护
34+
35+
| 命令 | 说明 |
36+
|---------|-------------|
37+
| **[VACUUM TABLE](09-vacuum-table.md)** | 回收表的存储空间 |
38+
| **[VACUUM DROP TABLE](09-vacuum-drop-table.md)** | 清理已删除表的数据 |
39+
| **[VACUUM TEMP FILES](09-vacuum-temp-files.md)** | 移除临时文件 |
40+
| **[SHOW INDEXES](show-indexes.md)** | 显示表索引(Index) |
41+
42+
## 动态执行
43+
44+
| 命令 | 说明 |
45+
|---------|-------------|
46+
| **[EXECUTE IMMEDIATE](execute-immediate.md)** | 执行动态构造的 SQL 语句 |

0 commit comments

Comments
 (0)