From 4303f7e1105216f3b00d1298c09906c22214465e Mon Sep 17 00:00:00 2001 From: CookiePieWw Date: Thu, 21 Nov 2024 12:10:52 +0800 Subject: [PATCH 1/5] docs: alter database ttl --- docs/reference/sql/alter.md | 28 ++++++++++++++++++- .../current/reference/sql/alter.md | 28 ++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/docs/reference/sql/alter.md b/docs/reference/sql/alter.md index 8c348a38df..bd3845e943 100644 --- a/docs/reference/sql/alter.md +++ b/docs/reference/sql/alter.md @@ -1,13 +1,20 @@ # ALTER -`ALTER` can be used to modify any table settings or data within the table: +`ALTER` can be used to modify any database and table settings or data within the table: +* Modify database options * Add/Drop/Modify a column * Rename a table +* Modify table options ## Syntax ```sql +ALTER DATABASE db + [SET = [, ...] + | UNSET [, ...] + ] + ALTER TABLE [db.]table [ADD COLUMN name type [options] | DROP COLUMN name @@ -22,6 +29,25 @@ ALTER TABLE [db.]table ## Examples +### Modify database options + +`ALTER DATABASE` statements can be used to change the options of databases. + +Currently following options are supported: +- `ttl`: the default retention time of data in database. + +Change the default retention time of data in the database to 1 day: + +```sql +ALTER DATABASE db SET 'ttl'='1d'; +``` + +Remove the default retention time of data in the database: + +```sql +ALTER DATABASE db UNSET 'ttl'; +``` + ### Add column Adds a new column to the table: diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md index 6f6fa93f8f..c2e66e7d88 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md @@ -1,13 +1,20 @@ # ALTER -`ALTER` 可以用来修改表的设置或者表中的数据: +`ALTER` 可以用来修改数据库和表的设置或者表中的数据: +* 修改数据库选项 * 添加/删除/修改列 * 重命名表 +* 修改表选项 ## Syntax ```sql +ALTER DATABASE db + [SET = [, ...] + | UNSET [, ...] + ] + ALTER TABLE [db.]table [ADD COLUMN name type [options] | DROP COLUMN name @@ -21,6 +28,25 @@ ALTER TABLE [db.]table ## 示例 +### 修改数据库选项 + +`ALTER DATABASE` 语句可以用来修改数据库的选项。 + +当前支持修改以下数据库选项: +- `ttl`: 数据库中数据的默认保留时间。 + +修改数据库中数据的默认保留时间为 1 天: + +```sql +ALTER DATABASE db SET 'ttl'='1d'; +``` + +取消数据库中数据的默认保留时间: + +```sql +ALTER DATABASE db UNSET 'ttl'; +``` + ### 增加列 在表中增加新列: From 27da23f6e5d30e6b57a43cb30c360b8f98554df8 Mon Sep 17 00:00:00 2001 From: CookiePieWw Date: Thu, 21 Nov 2024 12:14:35 +0800 Subject: [PATCH 2/5] docs: refine --- docs/reference/sql/alter.md | 2 +- .../current/reference/sql/alter.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/reference/sql/alter.md b/docs/reference/sql/alter.md index bd3845e943..e22e72a4f1 100644 --- a/docs/reference/sql/alter.md +++ b/docs/reference/sql/alter.md @@ -1,6 +1,6 @@ # ALTER -`ALTER` can be used to modify any database and table settings or data within the table: +`ALTER` can be used to modify any database and table settings or metadata of the table, including: * Modify database options * Add/Drop/Modify a column diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md index c2e66e7d88..f9a3c3f825 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md @@ -1,6 +1,6 @@ # ALTER -`ALTER` 可以用来修改数据库和表的设置或者表中的数据: +`ALTER` 可以用来修改数据库和表的设置,或者修改表的元数据,包括: * 修改数据库选项 * 添加/删除/修改列 @@ -41,7 +41,7 @@ ALTER TABLE [db.]table ALTER DATABASE db SET 'ttl'='1d'; ``` -取消数据库中数据的默认保留时间: +取消数据库中数据的默认保留时间设置: ```sql ALTER DATABASE db UNSET 'ttl'; From c1882a429e1650c1aeff282c97b16f274cf317b7 Mon Sep 17 00:00:00 2001 From: CookiePieWw Date: Thu, 21 Nov 2024 12:15:43 +0800 Subject: [PATCH 3/5] docs: refine --- docs/reference/sql/alter.md | 2 +- .../current/reference/sql/alter.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/sql/alter.md b/docs/reference/sql/alter.md index e22e72a4f1..aba905c61c 100644 --- a/docs/reference/sql/alter.md +++ b/docs/reference/sql/alter.md @@ -1,6 +1,6 @@ # ALTER -`ALTER` can be used to modify any database and table settings or metadata of the table, including: +`ALTER` can be used to modify any database options, table options or metadata of the table, including: * Modify database options * Add/Drop/Modify a column diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md index f9a3c3f825..ddddf5003e 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md @@ -1,6 +1,6 @@ # ALTER -`ALTER` 可以用来修改数据库和表的设置,或者修改表的元数据,包括: +`ALTER` 可以用来修改数据库的设置,表的设置或表的元数据,包括: * 修改数据库选项 * 添加/删除/修改列 From e0b58b0325892b15eb5a34f6c42247029757f025 Mon Sep 17 00:00:00 2001 From: CookiePieWw Date: Thu, 21 Nov 2024 14:40:50 +0800 Subject: [PATCH 4/5] docs: refine --- docs/reference/sql/alter.md | 52 +++++++++++-------- .../current/reference/sql/alter.md | 43 +++++++++------ 2 files changed, 59 insertions(+), 36 deletions(-) diff --git a/docs/reference/sql/alter.md b/docs/reference/sql/alter.md index aba905c61c..4f12c02bf6 100644 --- a/docs/reference/sql/alter.md +++ b/docs/reference/sql/alter.md @@ -7,31 +7,22 @@ * Rename a table * Modify table options -## Syntax +## ALTER DATABASE + +### Syntax ```sql ALTER DATABASE db [SET = [, ...] | UNSET [, ...] ] - -ALTER TABLE [db.]table - [ADD COLUMN name type [options] - | DROP COLUMN name - | MODIFY COLUMN name type - | MODIFY COLUMN name SET FULLTEXT [WITH ] - | MODIFY COLUMN name UNSET FULLTEXT - | RENAME name - | SET = [, ...] - | UNSET [, ...] - ] ``` -## Examples +### Examples -### Modify database options +#### Modify database options -`ALTER DATABASE` statements can be used to change the options of databases. +`ALTER DATABASE` statements can be used to modify the options of databases. Currently following options are supported: - `ttl`: the default retention time of data in database. @@ -48,7 +39,26 @@ Remove the default retention time of data in the database: ALTER DATABASE db UNSET 'ttl'; ``` -### Add column +## ALTER TABLE + +### Syntax + +```sql +ALTER TABLE [db.]table + [ADD COLUMN name type [options] + | DROP COLUMN name + | MODIFY COLUMN name type + | MODIFY COLUMN name SET FULLTEXT [WITH ] + | MODIFY COLUMN name UNSET FULLTEXT + | RENAME name + | SET = [, ...] + | UNSET [, ...] + ] +``` + +### Examples + +#### Add column Adds a new column to the table: @@ -75,7 +85,7 @@ Adds a new column as a tag(primary key) with a default value: ALTER TABLE monitor ADD COLUMN app STRING DEFAULT 'shop' PRIMARY KEY; ``` -### Remove column +#### Remove column Removes a column from the table: @@ -85,7 +95,7 @@ ALTER TABLE monitor DROP COLUMN load_15; The removed column can't be retrieved immediately by all subsequent queries. -### Modify column type +#### Modify column type Modify the date type of a column @@ -95,7 +105,7 @@ ALTER TABLE monitor MODIFY COLUMN load_15 STRING; The modified column cannot be a tag (primary key) or time index, and it must be nullable to ensure that the data can be safely converted (returns `NULL` on cast failures). -### Alter table options +#### Alter table options `ALTER TABLE` statements can also be used to change the options of tables. @@ -130,7 +140,7 @@ ALTER TABLE monitor SET 'compaction.twcs.max_inactive_window_runs'='6'; ALTER TABLE monitor UNSET 'ttl'; ``` -### Modify column fulltext index options +#### Modify column fulltext index options Enable fulltext index on a column: @@ -155,7 +165,7 @@ The column must be a string type to alter the fulltext index. If the fulltext index has never been enabled, you can enable it and specify the `analyzer` and `case_sensitive` options. When the fulltext index is already enabled on a column, you can disable it but **cannot modify the options**. -### Rename table +#### Rename table Renames the table: diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md index ddddf5003e..cd8712a6ea 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md @@ -7,14 +7,11 @@ * 重命名表 * 修改表选项 -## Syntax +## ALTER DATABASE -```sql -ALTER DATABASE db - [SET = [, ...] - | UNSET [, ...] - ] +### 语法 +```sql ALTER TABLE [db.]table [ADD COLUMN name type [options] | DROP COLUMN name @@ -26,9 +23,9 @@ ALTER TABLE [db.]table ] ``` -## 示例 +### 示例 -### 修改数据库选项 +#### 修改数据库选项 `ALTER DATABASE` 语句可以用来修改数据库的选项。 @@ -47,7 +44,24 @@ ALTER DATABASE db SET 'ttl'='1d'; ALTER DATABASE db UNSET 'ttl'; ``` -### 增加列 +## ALTER TABLE + +## 语法 + +```sql +ALTER TABLE [db.]table + [ADD COLUMN name type [options] + | DROP COLUMN name + | MODIFY COLUMN name type + | MODIFY COLUMN name SET FULLTEXT [WITH ] + | RENAME name + | SET = [, ...] + ] +``` + +### 示例 + +#### 增加列 在表中增加新列: @@ -75,7 +89,7 @@ ALTER TABLE monitor ADD COLUMN app STRING DEFAULT 'shop' PRIMARY KEY; ``` -### 移除列 +#### 移除列 从表中移除列: @@ -85,7 +99,7 @@ ALTER TABLE monitor DROP COLUMN load_15; 后续的所有查询立刻不能获取到被移除的列。 -### 修改列类型 +#### 修改列类型 修改列的数据类型 @@ -95,7 +109,7 @@ ALTER TABLE monitor MODIFY COLUMN load_15 STRING; 被修改的的列不能是 tag 列(primary key)或 time index 列,同时该列必须允许空值 `NULL` 存在来保证数据能够安全地进行转换(转换失败时返回 `NULL`)。 -### 修改表的参数 +#### 修改表的参数 `ALTER TABLE` 语句也可以用来更改表的选项。 当前支持修改以下表选项: @@ -130,8 +144,7 @@ ALTER TABLE monitor SET 'compaction.twcs.max_inactive_window_runs'='6'; ALTER TABLE monitor UNSET 'ttl'; ``` - -### 修改列全文索引选项 +#### 修改列全文索引选项 启用列的全文索引: @@ -156,7 +169,7 @@ ALTER TABLE monitor MODIFY COLUMN load_15 UNSET FULLTEXT; 当列的全文索引未开启过时,可以启用全文索引,并设置 `analyzer` 和 `case_sensitive` 选项;当列的全文索引选项已经启用时,可以关闭全文索引,**但不能修改选项**。 -### 重命名表 +#### 重命名表 ```sql ALTER TABLE monitor RENAME monitor_new; From 146223877713b705d6d216c403962282e24dd6e3 Mon Sep 17 00:00:00 2001 From: CookiePieWw Date: Thu, 21 Nov 2024 15:38:20 +0800 Subject: [PATCH 5/5] docs: apply cr --- docs/reference/sql/alter.md | 12 ++++++------ .../current/reference/sql/alter.md | 13 +++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/reference/sql/alter.md b/docs/reference/sql/alter.md index 4f12c02bf6..fce4b0cbfb 100644 --- a/docs/reference/sql/alter.md +++ b/docs/reference/sql/alter.md @@ -9,6 +9,8 @@ ## ALTER DATABASE +`ALTER DATABASE` statements can be used to modify the options of databases. + ### Syntax ```sql @@ -18,15 +20,13 @@ ALTER DATABASE db ] ``` -### Examples - -#### Modify database options - -`ALTER DATABASE` statements can be used to modify the options of databases. - Currently following options are supported: - `ttl`: the default retention time of data in database. +### Examples + +#### Modify default retention time of data in database + Change the default retention time of data in the database to 1 day: ```sql diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md index cd8712a6ea..7b84284d57 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/alter.md @@ -9,6 +9,9 @@ ## ALTER DATABASE + +`ALTER DATABASE` 语句可以用来修改数据库的选项。 + ### 语法 ```sql @@ -23,15 +26,13 @@ ALTER TABLE [db.]table ] ``` -### 示例 - -#### 修改数据库选项 - -`ALTER DATABASE` 语句可以用来修改数据库的选项。 - 当前支持修改以下数据库选项: - `ttl`: 数据库中数据的默认保留时间。 +### 示例 + +#### 修改数据库中数据的默认保留时间 + 修改数据库中数据的默认保留时间为 1 天: ```sql