diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/_category_.json b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/_category_.json index fbc88e4dfd..c30bbaac1c 100644 --- a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/_category_.json +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/_category_.json @@ -1,3 +1,4 @@ { - "label": "计算集群" -} \ No newline at end of file + "label": "计算集群", + "position": 19 +} diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/alter-warehouse.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/alter-warehouse.md new file mode 100644 index 0000000000..9a6cf2c8be --- /dev/null +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/alter-warehouse.md @@ -0,0 +1,77 @@ +--- +title: ALTER WAREHOUSE +sidebar_position: 4 +--- + +import FunctionDescription from '@site/src/components/FunctionDescription'; + + + +暂停、恢复或修改计算集群配置。 + +## 语法 + +```sql +-- 暂停或恢复 +ALTER WAREHOUSE { SUSPEND | RESUME } + +-- 修改配置 +ALTER WAREHOUSE + SET [ WITH ] warehouse_size = + [ WITH ] auto_suspend = + [ WITH ] auto_resume = + [ WITH ] max_cluster_count = + [ WITH ] min_cluster_count = + [ WITH ] comment = '' +``` + +| 参数 | 说明 | +|------|------| +| `SUSPEND` | 立即暂停计算集群。 | +| `RESUME` | 立即恢复计算集群。 | +| `SET` | 修改一个或多个选项,未指定的选项保持不变。 | + +## 选项 + +`SET` 子句支持与 [CREATE WAREHOUSE](create-warehouse.md) 相同的选项: + +| 选项 | 类型 / 取值 | 说明 | +|------|-------------|------| +| `WAREHOUSE_SIZE` | `XSmall`、`Small`、`Medium`、`Large`、`XLarge`、`2XLarge`–`6XLarge` | 修改规格。 | +| `AUTO_SUSPEND` | `NULL`、`0` 或 ≥300 秒 | 空闲自动暂停时间。`NULL` 表示禁用。 | +| `AUTO_RESUME` | 布尔值 | 是否自动恢复。 | +| `MAX_CLUSTER_COUNT` | `NULL` 或非负整数 | 最大集群数。 | +| `MIN_CLUSTER_COUNT` | `NULL` 或非负整数 | 最小集群数。 | +| `COMMENT` | 字符串 | 备注信息。 | + +- 数值选项设为 `NULL` 会重置为 `0`。 +- `SET` 后不带任何选项会报错。 + +## 示例 + +暂停计算集群: + +```sql +ALTER WAREHOUSE my_wh SUSPEND; +``` + +恢复计算集群: + +```sql +ALTER WAREHOUSE my_wh RESUME; +``` + +修改配置: + +```sql +ALTER WAREHOUSE my_wh + SET warehouse_size = Large + auto_resume = TRUE + comment = '生产环境'; +``` + +禁用自动暂停: + +```sql +ALTER WAREHOUSE my_wh SET auto_suspend = NULL; +``` diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/create-warehouse.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/create-warehouse.md index d37879fbba..4cdc788f09 100644 --- a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/create-warehouse.md +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/create-warehouse.md @@ -1,29 +1,65 @@ --- title: CREATE WAREHOUSE +sidebar_position: 1 --- import FunctionDescription from '@site/src/components/FunctionDescription'; -创建一个具有指定大小的计算集群。 +创建计算集群。 ## 语法 ```sql -CREATE WAREHOUSE '' - WITH WAREHOUSE_SIZE = '' +CREATE WAREHOUSE [ IF NOT EXISTS ] + [ WITH ] warehouse_size = + [ WITH ] auto_suspend = + [ WITH ] initially_suspended = + [ WITH ] auto_resume = + [ WITH ] max_cluster_count = + [ WITH ] min_cluster_count = + [ WITH ] comment = '' ``` -说明: +| 参数 | 说明 | +|------|------| +| `IF NOT EXISTS` | 可选。若计算集群已存在则不执行任何操作。 | +| warehouse_name | 长度 3–63 个字符,仅支持 `A-Z`、`a-z`、`0-9` 和 `-`。 | -- `` 只能包含英文字母、数字和 `-`。建议统一使用单引号包裹。 -- `` 不区分大小写,可选值为:`XSMALL`、`SMALL`、`MEDIUM`、`LARGE`、`XLARGE`、`XXLARGE`、`XXXLARGE`。建议统一使用单引号包裹。 +## 选项 + +| 选项 | 类型 / 取值 | 默认值 | 说明 | +|------|-------------|--------|------| +| `WAREHOUSE_SIZE` | `XSmall`、`Small`、`Medium`、`Large`、`XLarge`、`2XLarge`–`6XLarge`(不区分大小写) | `Small` | 计算集群规格。 | +| `AUTO_SUSPEND` | `NULL`、`0` 或 ≥300 秒 | `600` 秒 | 空闲自动暂停时间。`0` 或 `NULL` 表示不自动暂停;小于 300 秒会报错。 | +| `INITIALLY_SUSPENDED` | 布尔值 | `FALSE` | 设为 `TRUE` 时,创建后保持暂停状态,需手动恢复。 | +| `AUTO_RESUME` | 布尔值 | `TRUE` | 是否在收到查询时自动恢复。 | +| `MAX_CLUSTER_COUNT` | `NULL` 或非负整数 | `0` | 自动扩缩容的最大集群数。`0` 表示禁用。 | +| `MIN_CLUSTER_COUNT` | `NULL` 或非负整数 | `0` | 自动扩缩容的最小集群数,应 ≤ `MAX_CLUSTER_COUNT`。 | +| `COMMENT` | 字符串 | 空 | 备注信息,可通过 `SHOW WAREHOUSES` 查看。 | + +- 选项可任意顺序,重复时以最后一个为准。 +- `AUTO_SUSPEND`、`MAX_CLUSTER_COUNT`、`MIN_CLUSTER_COUNT` 设为 `NULL` 会重置为 `0`。 ## 示例 -此示例创建一个 `XSMALL` 规格的计算集群: +创建带自动扩缩容的 XLarge 计算集群: + +```sql +CREATE WAREHOUSE IF NOT EXISTS etl_wh + WITH warehouse_size = XLarge + auto_suspend = 600 + initially_suspended = TRUE + auto_resume = FALSE + max_cluster_count = 4 + min_cluster_count = 2 + comment = 'ETL 专用集群'; +``` + +创建 Small 规格的计算集群: ```sql -CREATE WAREHOUSE 'testwarehouse' WITH WAREHOUSE_SIZE = 'XSMALL'; +CREATE WAREHOUSE my_warehouse + WITH warehouse_size = Small; ``` diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/drop-warehouse.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/drop-warehouse.md index 1f17d0c67c..3034dc5bb0 100644 --- a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/drop-warehouse.md +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/drop-warehouse.md @@ -1,24 +1,35 @@ --- title: DROP WAREHOUSE +sidebar_position: 5 --- + import FunctionDescription from '@site/src/components/FunctionDescription'; -删除指定的计算集群并释放与其关联的资源。 +删除计算集群并释放相关资源。 ## 语法 ```sql -DROP WAREHOUSE '' +DROP WAREHOUSE [ IF EXISTS ] ``` -建议统一使用单引号包裹 ``。 +| 参数 | 说明 | +|------|------| +| `IF EXISTS` | 可选。若计算集群不存在则不报错。 | +| warehouse_name | 要删除的计算集群名称。 | ## 示例 -此示例删除 `testwarehouse` 计算集群: +删除计算集群: + +```sql +DROP WAREHOUSE my_warehouse; +``` + +仅在存在时删除: ```sql -DROP WAREHOUSE 'testwarehouse'; +DROP WAREHOUSE IF EXISTS my_warehouse; ``` diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/index.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/index.md index dc5e5ed55c..84a8f171fe 100644 --- a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/index.md +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/index.md @@ -1,23 +1,30 @@ --- title: 计算集群(Warehouse) +sidebar_position: 0 --- -计算集群相关的 SQL 命令。 +Databend Cloud 计算集群相关的 SQL 命令。 -## 计算集群管理 +## 基本规则 -| 命令 | 描述 | -|---------|-------------| -| [CREATE WAREHOUSE](create-warehouse.md) | 创建新的计算集群用于计算资源 | -| [DROP WAREHOUSE](drop-warehouse.md) | 删除计算集群 | -| [USE WAREHOUSE](use-warehouse.md) | 为当前会话设置计算集群 | +- **命名规范**:长度 3–63 个字符,仅支持 `A-Z`、`a-z`、`0-9` 和 `-`。 +- **标识符**:不含空格或特殊字符时可省略引号,否则需用单引号包裹。 +- **数值参数**:支持整数或 `NULL`。设为 `NULL` 会重置为默认值(如 `AUTO_SUSPEND = NULL` 等同于 `0`)。 +- **布尔参数**:仅接受 `TRUE` / `FALSE`。 +- **`WITH` 关键字**:可放在整个选项列表前,也可放在每个选项前。选项间用空格分隔。 -## 计算集群信息 +## 计算集群管理 | 命令 | 描述 | -|---------|-------------| -| [SHOW WAREHOUSES](show-warehouses.md) | 列出所有计算集群 | +|------|------| +| [CREATE WAREHOUSE](create-warehouse.md) | 创建计算集群 | +| [USE WAREHOUSE](use-warehouse.md) | 切换当前会话的计算集群 | +| [SHOW WAREHOUSES](show-warehouses.md) | 查看计算集群列表 | +| [ALTER WAREHOUSE](alter-warehouse.md) | 暂停、恢复或修改计算集群配置 | +| [DROP WAREHOUSE](drop-warehouse.md) | 删除计算集群 | +| [REPLACE WAREHOUSE](replace-warehouse.md) | 重建计算集群 | +| [QUERY_HISTORY](query-history.md) | 查询执行历史记录 | :::note -计算集群代表用于执行查询的计算资源。 +计算集群是 Databend Cloud 中用于执行查询的计算资源。 ::: diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/query-history.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/query-history.md new file mode 100644 index 0000000000..dd0ec61193 --- /dev/null +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/query-history.md @@ -0,0 +1,62 @@ +--- +title: QUERY_HISTORY +sidebar_position: 7 +--- + +import FunctionDescription from '@site/src/components/FunctionDescription'; + + + +查询执行历史记录,用于分析和监控。 + +## 语法 + +```sql +QUERY_HISTORY + [ BY WAREHOUSE ] + [ FROM '' ] + [ TO '' ] + [ LIMIT ] +``` + +| 参数 | 说明 | +|------|------| +| `BY WAREHOUSE` | 可选。按计算集群过滤,名称不能为空。 | +| `FROM` | 可选。起始时间,格式 `YYYY-MM-DD HH:MM:SS`。默认为 `TO` 前 1 小时。 | +| `TO` | 可选。结束时间,格式 `YYYY-MM-DD HH:MM:SS`。默认为当前时间。 | +| `LIMIT` | 可选。返回记录数上限,默认 `10`,必须为正整数。 | + +## 输出列 + +返回结果包含以下列: + +| 列名 | 说明 | +|------|------| +| `query_id` | 查询唯一标识 | +| `query_text` | SQL 语句 | +| `scan_bytes` | 扫描数据量 | +| ... | 其他查询指标 | + +## 示例 + +查询指定集群的历史记录: + +```sql +QUERY_HISTORY + BY WAREHOUSE etl_wh + FROM '2023-08-20 00:00:00' + TO '2023-08-20 06:00:00' + LIMIT 200; +``` + +查询最近 10 条记录: + +```sql +QUERY_HISTORY; +``` + +指定返回数量: + +```sql +QUERY_HISTORY LIMIT 50; +``` diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/replace-warehouse.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/replace-warehouse.md new file mode 100644 index 0000000000..98c4d02648 --- /dev/null +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/replace-warehouse.md @@ -0,0 +1,43 @@ +--- +title: REPLACE WAREHOUSE +sidebar_position: 6 +--- + +import FunctionDescription from '@site/src/components/FunctionDescription'; + + + +重建计算集群。语义与 [CREATE WAREHOUSE](create-warehouse.md) 相同,适用于覆盖已有配置的场景。 + +## 语法 + +```sql +REPLACE WAREHOUSE + [ WITH ] warehouse_size = + [ WITH ] auto_suspend = + [ WITH ] initially_suspended = + [ WITH ] auto_resume = + [ WITH ] max_cluster_count = + [ WITH ] min_cluster_count = + [ WITH ] comment = '' +``` + +| 参数 | 说明 | +|------|------| +| warehouse_name | 长度 3–63 个字符,仅支持 `A-Z`、`a-z`、`0-9` 和 `-`。 | + +## 选项 + +参见 [CREATE WAREHOUSE](create-warehouse.md#选项)。 + +## 示例 + +使用新配置重建计算集群: + +```sql +REPLACE WAREHOUSE etl_wh + WITH warehouse_size = Large + auto_suspend = 300 + auto_resume = TRUE + comment = '更新后的 ETL 集群'; +``` diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/show-warehouses.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/show-warehouses.md index 43886b4ad3..43a58585bf 100644 --- a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/show-warehouses.md +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/show-warehouses.md @@ -1,22 +1,48 @@ --- title: SHOW WAREHOUSES +sidebar_position: 3 --- + import FunctionDescription from '@site/src/components/FunctionDescription'; 列出当前租户下的所有计算集群。 -结果包含 `name`、`state`、`size`、`version`、`auto_suspend`、`cache_size`、`spill_size`、`created_on` 等列。 - ## 语法 ```sql -SHOW WAREHOUSES +SHOW WAREHOUSES [ LIKE '' ] ``` +| 参数 | 说明 | +|------|------| +| `LIKE ''` | 可选。按名称过滤,支持 `%`(匹配任意字符序列)和 `_`(匹配单个字符)。 | + +## 输出列 + +| 列名 | 说明 | +|------|------| +| `name` | 计算集群名称 | +| `state` | 当前状态(如 Running、Suspended) | +| `size` | 规格大小 | +| `auto_suspend` | 自动暂停时间(秒) | +| `auto_resume` | 是否自动恢复 | +| `min_cluster_count` | 最小集群数 | +| `max_cluster_count` | 最大集群数 | +| `comment` | 备注 | +| `created_on` | 创建时间 | + ## 示例 +查看所有计算集群: + ```sql SHOW WAREHOUSES; ``` + +按名称过滤: + +```sql +SHOW WAREHOUSES LIKE '%prod%'; +``` diff --git a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/use-warehouse.md b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/use-warehouse.md index 70dba1651f..abd4fb19e9 100644 --- a/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/use-warehouse.md +++ b/docs/cn/sql-reference/10-sql-commands/00-ddl/19-warehouse/use-warehouse.md @@ -1,24 +1,28 @@ --- title: USE WAREHOUSE +sidebar_position: 2 --- + import FunctionDescription from '@site/src/components/FunctionDescription'; -设置用于执行查询的活动计算集群。 +切换当前会话使用的计算集群,后续查询将在该集群上执行。 ## 语法 ```sql -USE WAREHOUSE '' +USE WAREHOUSE ``` -建议统一使用单引号包裹 ``。 +| 参数 | 说明 | +|------|------| +| warehouse_name | 计算集群名称。命令会验证该集群是否存在且可访问。 | ## 示例 -此示例将 `testwarehouse` 设置为当前使用的计算集群: +将当前会话切换到 `my_warehouse`: ```sql -USE WAREHOUSE 'testwarehouse'; +USE WAREHOUSE my_warehouse; ``` diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/_category_.json b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/_category_.json new file mode 100644 index 0000000000..f85ae78bb9 --- /dev/null +++ b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/_category_.json @@ -0,0 +1,4 @@ +{ + "label": "Warehouse", + "position": 19 +} diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/alter-warehouse.md b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/alter-warehouse.md new file mode 100644 index 0000000000..50fe79c0f5 --- /dev/null +++ b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/alter-warehouse.md @@ -0,0 +1,77 @@ +--- +title: ALTER WAREHOUSE +sidebar_position: 4 +--- + +import FunctionDescription from '@site/src/components/FunctionDescription'; + + + +Suspends, resumes, or modifies settings of an existing warehouse. + +## Syntax + +```sql +-- Suspend or resume a warehouse +ALTER WAREHOUSE { SUSPEND | RESUME } + +-- Modify warehouse settings +ALTER WAREHOUSE + SET [ WITH ] warehouse_size = + [ WITH ] auto_suspend = + [ WITH ] auto_resume = + [ WITH ] max_cluster_count = + [ WITH ] min_cluster_count = + [ WITH ] comment = '' +``` + +| Parameter | Description | +|-----------|-------------| +| `SUSPEND` | Immediately suspends the warehouse. | +| `RESUME` | Immediately resumes the warehouse. | +| `SET` | Modifies one or more warehouse options. Unspecified fields remain unchanged. | + +## Options + +The `SET` clause accepts the same options as [CREATE WAREHOUSE](create-warehouse.md): + +| Option | Type / Values | Description | +|--------|---------------|-------------| +| `WAREHOUSE_SIZE` | `XSmall`, `Small`, `Medium`, `Large`, `XLarge`, `2XLarge`–`6XLarge` | Changes compute size. | +| `AUTO_SUSPEND` | `NULL`, `0`, or ≥300 seconds | Idle timeout before automatic suspend. `NULL` disables auto-suspend. | +| `AUTO_RESUME` | Boolean | Controls whether incoming queries wake the warehouse automatically. | +| `MAX_CLUSTER_COUNT` | `NULL` or non-negative integer | Upper bound for auto-scaling clusters. | +| `MIN_CLUSTER_COUNT` | `NULL` or non-negative integer | Lower bound for auto-scaling clusters. | +| `COMMENT` | String | Free-form text description. | + +- `NULL` is valid for numeric options to reset them to `0`. +- Supplying `SET` with no options raises an error. + +## Examples + +Suspend a warehouse: + +```sql +ALTER WAREHOUSE my_wh SUSPEND; +``` + +Resume a warehouse: + +```sql +ALTER WAREHOUSE my_wh RESUME; +``` + +Modify warehouse settings: + +```sql +ALTER WAREHOUSE my_wh + SET warehouse_size = Large + auto_resume = TRUE + comment = 'Serving tier'; +``` + +Disable auto-suspend: + +```sql +ALTER WAREHOUSE my_wh SET auto_suspend = NULL; +``` diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/create-warehouse.md b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/create-warehouse.md index fcb3762de4..cb84a58b57 100644 --- a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/create-warehouse.md +++ b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/create-warehouse.md @@ -1,29 +1,65 @@ --- title: CREATE WAREHOUSE +sidebar_position: 1 --- import FunctionDescription from '@site/src/components/FunctionDescription'; -Creates a warehouse. +Creates a new warehouse for compute resources. ## Syntax ```sql -CREATE WAREHOUSE '' - WITH WAREHOUSE_SIZE = '' +CREATE WAREHOUSE [ IF NOT EXISTS ] + [ WITH ] warehouse_size = + [ WITH ] auto_suspend = + [ WITH ] initially_suspended = + [ WITH ] auto_resume = + [ WITH ] max_cluster_count = + [ WITH ] min_cluster_count = + [ WITH ] comment = '' ``` -Where: +| Parameter | Description | +|-----------|-------------| +| `IF NOT EXISTS` | Optional. If specified, the command succeeds without changes if the warehouse already exists. | +| warehouse_name | 3–63 characters, containing only `A-Z`, `a-z`, `0-9`, and `-`. | -- `` must contain only English letters, digits, and `-`. We recommend always using single quotes. -- `` is case-insensitive and can be one of: `XSMALL`, `SMALL`, `MEDIUM`, `LARGE`, `XLARGE`, `XXLARGE`, `XXXLARGE`. We recommend using single quotes. +## Options + +| Option | Type / Values | Default | Description | +|--------|---------------|---------|-------------| +| `WAREHOUSE_SIZE` | `XSmall`, `Small`, `Medium`, `Large`, `XLarge`, `2XLarge`–`6XLarge` (case-insensitive) | `Small` | Controls compute size. | +| `AUTO_SUSPEND` | `NULL`, `0`, or ≥300 seconds | `600` seconds | Idle timeout before automatic suspend. `0`/`NULL` means never suspend; values below 300 are rejected. | +| `INITIALLY_SUSPENDED` | Boolean | `FALSE` | If `TRUE`, the warehouse remains suspended after creation until explicitly resumed. | +| `AUTO_RESUME` | Boolean | `TRUE` | Controls whether incoming queries wake the warehouse automatically. | +| `MAX_CLUSTER_COUNT` | `NULL` or non-negative integer | `0` | Upper bound for auto-scaling clusters. `0` disables auto-scale. | +| `MIN_CLUSTER_COUNT` | `NULL` or non-negative integer | `0` | Lower bound for auto-scaling clusters; should be ≤ `MAX_CLUSTER_COUNT`. | +| `COMMENT` | String | Empty | Free-form text surfaced by `SHOW WAREHOUSES`. | + +- Options may appear in any order and may repeat (the later value wins). +- `AUTO_SUSPEND`, `MAX_CLUSTER_COUNT`, and `MIN_CLUSTER_COUNT` accept `= NULL` to reset to `0`. ## Examples -This example creates an `XSMALL` warehouse: +This example creates an XLarge warehouse with auto-scaling and custom settings: + +```sql +CREATE WAREHOUSE IF NOT EXISTS etl_wh + WITH warehouse_size = XLarge + auto_suspend = 600 + initially_suspended = TRUE + auto_resume = FALSE + max_cluster_count = 4 + min_cluster_count = 2 + comment = 'Nightly ETL warehouse'; +``` + +This example creates a basic Small warehouse: ```sql -CREATE WAREHOUSE 'testwarehouse' WITH WAREHOUSE_SIZE = 'XSMALL'; +CREATE WAREHOUSE my_warehouse + WITH warehouse_size = Small; ``` diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/drop-warehouse.md b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/drop-warehouse.md index 86b4089157..d765eb6ce2 100644 --- a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/drop-warehouse.md +++ b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/drop-warehouse.md @@ -1,24 +1,35 @@ --- title: DROP WAREHOUSE +sidebar_position: 5 --- + import FunctionDescription from '@site/src/components/FunctionDescription'; -Removes the specified warehouse and frees up the resources associated with it. +Removes a warehouse and frees up the resources associated with it. ## Syntax ```sql -DROP WAREHOUSE '' +DROP WAREHOUSE [ IF EXISTS ] ``` -We recommend always using single quotes for ``. +| Parameter | Description | +|-----------|-------------| +| `IF EXISTS` | Optional. If specified, the command succeeds silently when the warehouse does not exist. Without it, the command fails if the warehouse is absent. | +| warehouse_name | The name of the warehouse to remove. | ## Examples -This example removes the `testwarehouse` warehouse: +Drop a warehouse: + +```sql +DROP WAREHOUSE my_warehouse; +``` + +Drop a warehouse only if it exists: ```sql -DROP WAREHOUSE 'testwarehouse'; +DROP WAREHOUSE IF EXISTS my_warehouse; ``` diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/index.md b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/index.md index 8060b78705..ed5c98ec15 100644 --- a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/index.md +++ b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/index.md @@ -1,23 +1,30 @@ --- title: Warehouse +sidebar_position: 0 --- -Warehouse-related SQL commands. +Warehouse-related SQL commands for Databend Cloud. -## Warehouse Management +## General Rules -| Command | Description | -|---------|-------------| -| [CREATE WAREHOUSE](create-warehouse.md) | Creates a new warehouse for compute resources | -| [DROP WAREHOUSE](drop-warehouse.md) | Removes a warehouse | -| [USE WAREHOUSE](use-warehouse.md) | Sets the current warehouse for the session | +- **Warehouse naming**: 3–63 characters, `A-Z`, `a-z`, `0-9`, and `-` only. +- **Identifiers**: Bare identifiers may omit quotes when they contain no spaces or special characters; otherwise enclose with single quotes. +- **Numeric parameters**: Accept integers or `NULL`. Supplying `NULL` resets the value to default (e.g., `AUTO_SUSPEND = NULL` equals `0`). +- **Boolean parameters**: Only `TRUE`/`FALSE` are accepted. +- **`WITH` keyword**: May appear before the entire option list or ahead of each option. Options are whitespace-separated. -## Warehouse Information +## Warehouse Management | Command | Description | |---------|-------------| -| [SHOW WAREHOUSES](show-warehouses.md) | Lists all warehouses | +| [CREATE WAREHOUSE](create-warehouse.md) | Creates a new warehouse | +| [USE WAREHOUSE](use-warehouse.md) | Sets the current warehouse for the session | +| [SHOW WAREHOUSES](show-warehouses.md) | Lists all warehouses with optional filtering | +| [ALTER WAREHOUSE](alter-warehouse.md) | Suspends, resumes, or modifies warehouse settings | +| [DROP WAREHOUSE](drop-warehouse.md) | Removes a warehouse | +| [REPLACE WAREHOUSE](replace-warehouse.md) | Recreates a warehouse with new configuration | +| [QUERY_HISTORY](query-history.md) | Inspects query logs for a warehouse | :::note -A warehouse represents compute resources used to run queries. +A warehouse represents compute resources used to run queries in Databend Cloud. ::: diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/query-history.md b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/query-history.md new file mode 100644 index 0000000000..462a4f98d4 --- /dev/null +++ b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/query-history.md @@ -0,0 +1,62 @@ +--- +title: QUERY_HISTORY +sidebar_position: 7 +--- + +import FunctionDescription from '@site/src/components/FunctionDescription'; + + + +Retrieves query execution logs for analysis and monitoring purposes. + +## Syntax + +```sql +QUERY_HISTORY + [ BY WAREHOUSE ] + [ FROM '' ] + [ TO '' ] + [ LIMIT ] +``` + +| Parameter | Description | +|-----------|-------------| +| `BY WAREHOUSE` | Optional. Filters logs to a specific warehouse. Empty names raise an error. | +| `FROM` | Optional. Start timestamp for the query range. Format: `YYYY-MM-DD HH:MM:SS`. Defaults to 1 hour before `TO`. | +| `TO` | Optional. End timestamp for the query range. Format: `YYYY-MM-DD HH:MM:SS`. Defaults to current time. | +| `LIMIT` | Optional. Maximum number of records to return. Defaults to `10`. Must be a positive integer. | + +## Output Columns + +The result includes columns such as: + +| Column | Description | +|--------|-------------| +| `query_id` | Unique identifier for the query | +| `query_text` | The SQL statement executed | +| `scan_bytes` | Amount of data scanned | +| ... | Additional query metrics and metadata | + +## Examples + +Get recent query history for a specific warehouse: + +```sql +QUERY_HISTORY + BY WAREHOUSE etl_wh + FROM '2023-08-20 00:00:00' + TO '2023-08-20 06:00:00' + LIMIT 200; +``` + +Get the last 10 queries across all warehouses: + +```sql +QUERY_HISTORY; +``` + +Get query history with a custom limit: + +```sql +QUERY_HISTORY LIMIT 50; +``` diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/replace-warehouse.md b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/replace-warehouse.md new file mode 100644 index 0000000000..1cfb145be7 --- /dev/null +++ b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/replace-warehouse.md @@ -0,0 +1,43 @@ +--- +title: REPLACE WAREHOUSE +sidebar_position: 6 +--- + +import FunctionDescription from '@site/src/components/FunctionDescription'; + + + +Recreates a warehouse with the specified configuration. This command shares the same semantics as [CREATE WAREHOUSE](create-warehouse.md) and is useful for overwriting existing warehouse configurations. + +## Syntax + +```sql +REPLACE WAREHOUSE + [ WITH ] warehouse_size = + [ WITH ] auto_suspend = + [ WITH ] initially_suspended = + [ WITH ] auto_resume = + [ WITH ] max_cluster_count = + [ WITH ] min_cluster_count = + [ WITH ] comment = '' +``` + +| Parameter | Description | +|-----------|-------------| +| warehouse_name | 3–63 characters, containing only `A-Z`, `a-z`, `0-9`, and `-`. | + +## Options + +See [CREATE WAREHOUSE](create-warehouse.md#options) for the complete list of available options. + +## Examples + +Replace an existing warehouse with new settings: + +```sql +REPLACE WAREHOUSE etl_wh + WITH warehouse_size = Large + auto_suspend = 300 + auto_resume = TRUE + comment = 'Updated ETL warehouse'; +``` diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/show-warehouses.md b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/show-warehouses.md index 7d53ae8eda..97c471aabc 100644 --- a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/show-warehouses.md +++ b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/show-warehouses.md @@ -1,22 +1,48 @@ --- title: SHOW WAREHOUSES +sidebar_position: 3 --- + import FunctionDescription from '@site/src/components/FunctionDescription'; -Lists all warehouses in the current tenant. - -The result includes columns like `name`, `state`, `size`, `version`, `auto_suspend`, `cache_size`, `spill_size`, and `created_on`. +Lists all warehouses visible to the current tenant. ## Syntax ```sql -SHOW WAREHOUSES +SHOW WAREHOUSES [ LIKE '' ] ``` +| Parameter | Description | +|-----------|-------------| +| `LIKE ''` | Optional. Filters warehouse names using SQL `LIKE` semantics (`%` matches any sequence, `_` matches any single character). | + +## Output Columns + +| Column | Description | +|--------|-------------| +| `name` | Warehouse name | +| `state` | Current state (e.g., Running, Suspended) | +| `size` | Warehouse size | +| `auto_suspend` | Auto-suspend timeout in seconds | +| `auto_resume` | Whether auto-resume is enabled | +| `min_cluster_count` | Minimum cluster count for auto-scaling | +| `max_cluster_count` | Maximum cluster count for auto-scaling | +| `comment` | User-defined comment | +| `created_on` | Creation timestamp | + ## Examples +List all warehouses: + ```sql SHOW WAREHOUSES; ``` + +List warehouses matching a pattern: + +```sql +SHOW WAREHOUSES LIKE '%prod%'; +``` diff --git a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/use-warehouse.md b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/use-warehouse.md index becb37accb..3ff62e7ad8 100644 --- a/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/use-warehouse.md +++ b/docs/en/sql-reference/10-sql-commands/00-ddl/19-warehouse/use-warehouse.md @@ -1,24 +1,28 @@ --- title: USE WAREHOUSE +sidebar_position: 2 --- + import FunctionDescription from '@site/src/components/FunctionDescription'; -Sets the active warehouse for executing queries. +Binds the current session to a specific warehouse. Subsequent queries in the session will use this warehouse for execution. ## Syntax ```sql -USE WAREHOUSE '' +USE WAREHOUSE ``` -We recommend always using single quotes for ``. +| Parameter | Description | +|-----------|-------------| +| warehouse_name | The name of the warehouse to use. The command validates that the warehouse exists and is accessible. | ## Examples -This example sets `testwarehouse` as the active warehouse: +Set a warehouse as active for the current session: ```sql -USE WAREHOUSE 'testwarehouse'; +USE WAREHOUSE my_warehouse; ```