From 1f48fb8a32e66789dd1b09bd2e50cdc02640c019 Mon Sep 17 00:00:00 2001 From: Dino123-maker <1275505164@qq.com> Date: Mon, 20 Oct 2025 14:09:04 +0800 Subject: [PATCH] add sync table command --- .../data-and-status-management/SYNC-TABLE.md | 76 +++++++++++++++++++ .../data-and-status-management/SYNC-TABLE.md | 75 ++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 docs/sql-manual/sql-statements/table-and-view/data-and-status-management/SYNC-TABLE.md create mode 100644 i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-statements/table-and-view/data-and-status-management/SYNC-TABLE.md diff --git a/docs/sql-manual/sql-statements/table-and-view/data-and-status-management/SYNC-TABLE.md b/docs/sql-manual/sql-statements/table-and-view/data-and-status-management/SYNC-TABLE.md new file mode 100644 index 0000000000000..b63b7bb4dd2e9 --- /dev/null +++ b/docs/sql-manual/sql-statements/table-and-view/data-and-status-management/SYNC-TABLE.md @@ -0,0 +1,76 @@ +--- +{ + "title": "SYNC TABLE", + "language": "en" +} + + +--- + +## Description + +This statement is used for tables that have the asynchronous group commit feature enabled. + +In the async_mode, write operations return success immediately after the data is written to the memory buffer, without waiting for the data to be committed to disk. But we don't know when the data will be visible. + +The `SYNC TABLE` command is used to address this issue. It blocks the current session and waits for the ongoing asynchronous import transaction tasks for the specified table to complete before returning. This ensures that the data from the latest group commit batch is visible after the command finishes. + +## Syntax + +```sql +SYNC TABLE +``` + +## Required Parameters + + + +> The name of the table for which to wait for the group commit in async_mode to complete. + +## Example + +- Create table and set group commit in async_mode. + + ```sql + CREATE TABLE `dt` ( + `id` int(11) NOT NULL, + `name` varchar(50) NULL, + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 3 + PROPERTIES ( + "replication_num" = "1", + "group_commit_interval_ms" = "10000" + ); + + SET group_commit = 'async_mode'; + ``` + +- Insert into some data and after waiting, data becomes visible. + ```sql + INSERT INTO dt VALUES (1, "tom"), (2, "jerry"); + + sync table dt; + + select * from dt; + +------+-------+ + | id | name | + +------+-------+ + | 2 | jerry | + | 1 | tom | + +------+-------+ + 2 rows in set (0.07 sec) + ``` +## Usage Note + +1. This command is not supported in the storage-computing separation mode. Executing it in this mode will result in an error, for example: + + ```sql + sync table dt; + ``` + + The error message is as follows: + + ```sql + ERROR 1105 (HY000): errCode = 2, detailMessage = syncTable command not support in cloud mode now. + ``` \ No newline at end of file diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-statements/table-and-view/data-and-status-management/SYNC-TABLE.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-statements/table-and-view/data-and-status-management/SYNC-TABLE.md new file mode 100644 index 0000000000000..370ff3f1b6b61 --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-statements/table-and-view/data-and-status-management/SYNC-TABLE.md @@ -0,0 +1,75 @@ +--- +{ + "title": "SYNC TABLE", + "language": "zh-CN" +} + +--- + +## 描述 + +此语句适用于启用了异步组提交功能的表。 + +在 异步模式下,写入操作在数据写入内存缓冲区后立即返回成功,无需等待数据提交到磁盘。这可以提高导入性能,但我们不知道何时数据可见。 + +`SYNC TABLE`命令用于解决此问题。它会阻塞当前会话,并等待指定表正在进行的异步导入事务任务完成后再返回。这确保了命令完成后最新组提交批次的数据可见。 + +## 语法 + +```sql +SYNC TABLE +``` + +## 必选参数 + +1. `` :等待异步模式下的组提交完成的表的名称。 + +## 示例 + +1. 创建表并在设置组提交为异步模式。 + + ```sql + CREATE TABLE `dt` ( + `id` int(11) NOT NULL, + `name` varchar(50) NULL, + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS 3 + PROPERTIES ( + "replication_num" = "1", + "group_commit_interval_ms" = "10000" + ); + + SET group_commit = 'async_mode'; + ``` + +2. 插入一些数据,等待后数据变得可见。 + + ```sql + INSERT INTO dt VALUES (1, "tom"), (2, "jerry"); + + sync table dt; + + select * from dt; + +------+-------+ + | id | name | + +------+-------+ + | 2 | jerry | + | 1 | tom | + +------+-------+ + 2 rows in set (0.07 sec) + ``` + +## 注意事项(Usage Note) + +1. 存算分离模式不支持这个命令,在此模式下执行会报错,例如: + + ```sql + sync table dt; + ``` + + 报错信息如下: + + ```sql + ERROR 1105 (HY000): errCode = 2, detailMessage = syncTable command not support in cloud mode now. + ``` \ No newline at end of file