Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql-statement: improve consistency, fix small errors #4263

Merged
merged 14 commits into from
Sep 27, 2020
Prev Previous commit
Next Next commit
update system-variables.md
Signed-off-by: Ran <huangran@pingcap.com>
  • Loading branch information
ran-huang committed Sep 1, 2020
commit a8b7a2f1e24130f1cd65c7d2ec71dae29abdbd16
63 changes: 28 additions & 35 deletions system-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,51 +200,44 @@ SET GLOBAL tidb_distsql_scan_concurrency = 10;

- 作用域:SESSION | GLOBAL
- 默认值:0
- TiDB 支持乐观事务模型,即在执行写入时,假设不存在冲突。冲突检查是在最后 commit 提交时才去检查。这里的检查指 unique key 检查。
- 这个变量用来控制是否每次写入一行时就执行一次唯一性检查。注意,开启该变量后,在大批量写入场景下,对性能会有影响。
- 该变量仅适用于乐观事务模型。当这个变量设置为 0 时,唯一索引的重复值检查会被推迟到事务提交时才进行。这有助于提高性能,但对于某些应用,可能导致非预期的行为。详情见[约束](/constraints.md)。

示例
- 乐观事务模型下将 `tidb_constraint_check_in_place` 设置为 0

- 默认关闭 `tidb_constraint_check_in_place` 时的行为:
```sql
ran-huang marked this conversation as resolved.
Show resolved Hide resolved
create table t (i int key);
insert into t values (1);
begin optimistic;
insert into t values (1);
```

{{< copyable "sql" >}}
```
Query OK, 1 row affected
```

```sql
create table t (i int key);
insert into t values (1);
begin;
insert into t values (1);
```
```sql
ran-huang marked this conversation as resolved.
Show resolved Hide resolved
tidb> commit; -- 事务提交时才检查
```

```
Query OK, 1 row affected
```
```
ERROR 1062 : Duplicate entry '1' for key 'PRIMARY'
```

commit 时才去做检查
- 乐观事务模型下将 `tidb_constraint_check_in_place` 设置为 1

{{< copyable "sql" >}}
{{< copyable "sql" >}}

```sql
commit;
```
```sql
set @@tidb_constraint_check_in_place=1;
begin optimistic;
insert into t values (1);
```

```
ERROR 1062 : Duplicate entry '1' for key 'PRIMARY'
```

- 打开 `tidb_constraint_check_in_place` 后:
```
ERROR 1062 : Duplicate entry '1' for key 'PRIMARY'
```

{{< copyable "sql" >}}

```sql
set @@tidb_constraint_check_in_place=1;
begin;
insert into t values (1);
```

```
ERROR 1062 : Duplicate entry '1' for key 'PRIMARY'
```
悲观事务模型中,始终默认执行约束检查。

### `tidb_current_ts`

Expand Down