[doc] mod alter-table-replace (#10324)

Modify alter-table-replace to alter-table-replace-column, move alter-table-replace to data-definition-statements.
This commit is contained in:
Stalary
2022-06-30 08:11:59 +08:00
committed by GitHub
parent 2c35abe940
commit 73999feca7
6 changed files with 74 additions and 161 deletions

View File

@ -153,8 +153,7 @@ module.exports = [
directoryPath: "alter-table/",
initialOpenGroupIndex: -1,
children: [
"schema-change",
"replace-table"
"schema-change"
],
},
{

View File

@ -153,8 +153,7 @@ module.exports = [
directoryPath: "alter-table/",
initialOpenGroupIndex: -1,
children: [
"schema-change",
"replace-table"
"schema-change"
],
},
{

View File

@ -1,72 +0,0 @@
---
{
"title": "Replace Table",
"language": "en"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# Replace Table
In version 0.14, Doris supports atomic replacement of two tables.
This operation only applies to OLAP tables.
For partition level replacement operations, please refer to [Temporary Partition Document](../partition/table-temp-partition.md)
## Syntax
```
ALTER TABLE [db.]tbl1 REPLACE WITH tbl2
[PROPERTIES('swap' = 'true')];
```
Replace table `tbl1` with table `tbl2`.
If the `swap` parameter is `true`, after replacement, the data in the table named `tbl1` is the data in the original `tbl2` table. The data in the table named `tbl2` is the data in the original table `tbl1`. That is, the data of the two tables are interchanged.
If the `swap` parameter is `false`, after replacement, the data in the table named `tbl1` is the data in the original `tbl2` table. The table named `tbl2` is dropped.
## Principle
The replacement table function actually turns the following set of operations into an atomic operation.
Suppose you want to replace table A with table B, and `swap` is `true`, the operation is as follows:
1. Rename table B to table A.
2. Rename table A to table B.
If `swap` is `false`, the operation is as follows:
1. Drop table A.
2. Rename table B to table A.
## Notice
1. The `swap` parameter defaults to `true`. That is, the replacement table operation is equivalent to the exchange of two table data.
2. If the `swap` parameter is set to `false`, the replaced table (table A) will be dropped and cannot be recovered.
3. The replacement operation can only occur between two OLAP tables, and the table structure of the two tables is not checked for consistency.
4. The replacement operation will not change the original permission settings. Because the permission check is based on the table name.
## Best Practices
1. Atomic Overwrite Operation
In some cases, the user wants to be able to rewrite the data of a certain table, but if it is dropped and then imported, there will be a period of time in which the data cannot be viewed. At this time, the user can first use the `CREATE TABLE LIKE` statement to create a new table with the same structure, import the new data into the new table, and replace the old table atomically through the replacement operation to achieve the goal. For partition level atomic overwrite operation, please refer to [Temporary partition document](../partition/table-temp-partition.md)

View File

@ -1,11 +1,11 @@
---
{
"title": "ALTER-TABLE-REPLACE",
"title": "ALTER-TABLE-REPLACE-COLUMN",
"language": "en"
}
---
<!--
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
@ -32,19 +32,46 @@ ALTER TABLE REPLACE
### Description
This statement is used to modify the attributes of the schema of the existing table. The syntax is basically similar to [ALTER TABLE CULUMN](ALTER-TABLE-COLUMN.md).
Atomic substitution of two tables. This operation applies only to OLAP tables.
```sql
ALTER TABLE [database.]table MODIFY NEW_COLUMN_INFO REPLACE OLD_COLUMN_INFO ;
ALTER TABLE [db.]tbl1 REPLACE WITH TABLE tbl2
[PROPERTIES('swap' = 'true')];
```
Replace table tbl1 with table tbl2.
If the `swap` parameter is `true`, the data in the table named `tbl1` will be the data in the original table named `tbl2` after the replacement. The data in the table named `tbl2` is the data in the original `tbl1` table. That is, two tables of data have been swapped.
If the `swap` parameter is `false`, the data in the `tbl1` table will be the data in the `tbl2` table after the replacement. The table named `tbl2` is deleted.
#### Theory
The replace table function actually turns the following set of operations into an atomic operation.
If you want to replace table A with table B and `swap` is `true`, do the following:
1. Rename table B as table A.
2. Rename table A as table B.
If `swap` is `false`, do as follows:
1. Delete table A.
2. Rename table B as table A.
#### Notice
1. The default `swap` parameter is `true`. That is, a table replacement operation is equivalent to an exchange of data between two tables.
2. If the `swap` parameter is set to false, the replaced table (table A) will be deleted and cannot be restored.
3. The replacement operation can only occur between two OLAP tables and does not check whether the table structure of the two tables is consistent.
4. The original permission Settings are not changed. Because the permission check is based on the table name.
### Example
1. Modify the maximum length of the val1 column of base index. The original val1 is (val1 VARCHAR(32) REPLACE DEFAULT "abc")
1. Swap `tbl1` with `tbl2` without deleting the `tbl1` table
```sql
ALTER TABLE example_db.my_table
MODIFY COLUMN val1 VARCHAR(64) REPLACE DEFAULT "abc";
ALTER TABLE tbl1 REPLACE WITH TABLE tbl2
[PROPERTIES('swap' = 'true')];
```
### Keywords
@ -54,4 +81,6 @@ ALTER, TABLE, REPLACE, ALTER TABLE
```
### Best Practice
1. Atomic overlay write operations
In some cases, the user wants to be able to rewrite the data of a table, but if the deletion and then import method is used, the data cannot be viewed for a period of time. In this case, you can use the `CREATE TABLE LIKE` statement to CREATE a new TABLE with the same structure. After importing the new data into the new TABLE, you can replace the old TABLE atomic to achieve the purpose.

View File

@ -1,71 +0,0 @@
---
{
"title": "替换表",
"language": "zh-CN"
}
---
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
# 替换表
在 0.14 版本中,Doris 支持对两个表进行原子的替换操作。 该操作仅适用于 OLAP 表。
分区级别的替换操作,请参阅 [临时分区文档](../partition/table-tmp-partition.md)
## 语法说明
```text
ALTER TABLE [db.]tbl1 REPLACE WITH TABLE tbl2
[PROPERTIES('swap' = 'true')];
```
将表 tbl1 替换为表 tbl2。
如果 `swap` 参数为 `true`,则替换后,名称为 `tbl1` 表中的数据为原 `tbl2` 表中的数据。而名称为 `tbl2` 表中的数据为原 `tbl1` 表中的数据。即两张表数据发生了互换。
如果 `swap` 参数为 `false`,则替换后,名称为 `tbl1` 表中的数据为原 `tbl2` 表中的数据。而名称为 `tbl2` 表被删除。
## 原理
替换表功能,实际上是将以下操作集合变成一个原子操作。
假设要将表 A 替换为表 B,且 `swap``true`,则操作如下:
1. 将表 B 重名为表 A。
2. 将表 A 重名为表 B。
如果 `swap``false`,则操作如下:
1. 删除表 A。
2. 将表 B 重名为表 A。
## 注意事项
1. `swap` 参数默认为 `true`。即替换表操作相当于将两张表数据进行交换。
2. 如果设置 `swap` 参数为 `false`,则被替换的表(表A)将被删除,且无法恢复。
3. 替换操作仅能发生在两张 OLAP 表之间,且不会检查两张表的表结构是否一致。
4. 替换操作不会改变原有的权限设置。因为权限检查以表名称为准。
## 最佳实践
1. 原子的覆盖写操作
某些情况下,用户希望能够重写某张表的数据,但如果采用先删除再导入的方式进行,在中间会有一段时间无法查看数据。这时,用户可以先使用 `CREATE TABLE LIKE` 语句创建一个相同结构的新表,将新的数据导入到新表后,通过替换操作,原子的替换旧表,以达到目的。分区级别的原子覆盖写操作,请参阅 [临时分区文档](../partition/table-tmp-partition.md)。

View File

@ -1,11 +1,11 @@
---
{
"title": "ALTER-TABLE-REPLACE",
"title": "ALTER-TABLE-REPLACE-COLUMN",
"language": "zh-CN"
}
---
<!--
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
@ -32,19 +32,46 @@ ALTER TABLE REPLACE
### Description
该语句用于对已有 table 的 Schema 的进行属性的修改操作。语法基本类似于 [ALTER TABLE CULUMN](ALTER-TABLE-COLUMN.md)
对两个表进行原子的替换操作。 该操作仅适用于 OLAP 表
```sql
ALTER TABLE [database.]table MODIFY NEW_COLUMN_INFO REPLACE OLD_COLUMN_INFO ;
ALTER TABLE [db.]tbl1 REPLACE WITH TABLE tbl2
[PROPERTIES('swap' = 'true')];
```
将表 tbl1 替换为表 tbl2。
如果 `swap` 参数为 `true`,则替换后,名称为 `tbl1` 表中的数据为原 `tbl2` 表中的数据。而名称为 `tbl2` 表中的数据为原 `tbl1` 表中的数据。即两张表数据发生了互换。
如果 `swap` 参数为 `false`,则替换后,名称为 `tbl1` 表中的数据为原 `tbl2` 表中的数据。而名称为 `tbl2` 表被删除。
#### 原理
替换表功能,实际上是将以下操作集合变成一个原子操作。
假设要将表 A 替换为表 B,且 `swap``true`,则操作如下:
1. 将表 B 重名为表 A。
2. 将表 A 重名为表 B。
如果 `swap``false`,则操作如下:
1. 删除表 A。
2. 将表 B 重名为表 A。
#### 注意事项
1. `swap` 参数默认为 `true`。即替换表操作相当于将两张表数据进行交换。
2. 如果设置 `swap` 参数为 `false`,则被替换的表(表A)将被删除,且无法恢复。
3. 替换操作仅能发生在两张 OLAP 表之间,且不会检查两张表的表结构是否一致。
4. 替换操作不会改变原有的权限设置。因为权限检查以表名称为准。
### Example
1. 修改 base index 的 val1 列最大长度。原 val1 为 (val1 VARCHAR(32) REPLACE DEFAULT "abc")
1. `tbl1``tbl2` 进行交换,不删除 `tbl1`
```sql
ALTER TABLE example_db.my_table
MODIFY COLUMN val1 VARCHAR(64) REPLACE DEFAULT "abc";
ALTER TABLE tbl1 REPLACE WITH TABLE tbl2
[PROPERTIES('swap' = 'true')];
```
### Keywords
@ -54,4 +81,6 @@ ALTER, TABLE, REPLACE, ALTER TABLE
```
### Best Practice
1. 原子的覆盖写操作
某些情况下,用户希望能够重写某张表的数据,但如果采用先删除再导入的方式进行,在中间会有一段时间无法查看数据。这时,用户可以先使用 `CREATE TABLE LIKE` 语句创建一个相同结构的新表,将新的数据导入到新表后,通过替换操作,原子的替换旧表,以达到目的。分区级别的原子覆盖写操作,请参阅 [临时分区文档](../partition/table-tmp-partition.md)。