Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 <table_name>
```

## Required Parameters

<table_name>

> 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.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
{
"title": "SYNC TABLE",
"language": "zh-CN"
}

---

## 描述

此语句适用于启用了异步组提交功能的表。

在 异步模式下,写入操作在数据写入内存缓冲区后立即返回成功,无需等待数据提交到磁盘。这可以提高导入性能,但我们不知道何时数据可见。

`SYNC TABLE`命令用于解决此问题。它会阻塞当前会话,并等待指定表正在进行的异步导入事务任务完成后再返回。这确保了命令完成后最新组提交批次的数据可见。

## 语法

```sql
SYNC TABLE <table_name>
```

## 必选参数

1. `<table_name>` :等待异步模式下的组提交完成的表的名称。

## 示例

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.
```