You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: constraints.md
+14-6
Original file line number
Diff line number
Diff line change
@@ -80,7 +80,7 @@ SELECT * FROM users;
80
80
81
81
## UNIQUE KEY
82
82
83
-
In TiDB's optimistic transaction mode, UNIQUE constraints are [checked lazily](/transaction-overview.md#lazy-check-of-constraints) by default. By batching checks when the transaction is committed, TiDB can reduce network overhead and improve performance.
83
+
Depending on the transaction mode and the value of `tidb_constraint_check_in_place`, TiDB might check `UNIQUE` constraints [lazily](/transaction-overview.md#lazy-check-of-constraints). This helps improve performance by batching network access.
84
84
85
85
For example:
86
86
@@ -96,23 +96,31 @@ CREATE TABLE users (
96
96
INSERT INTO users (username) VALUES ('dave'), ('sarah'), ('bill');
97
97
```
98
98
99
+
With the default of pessimistic locking:
100
+
99
101
{{< copyable "sql" >}}
100
102
101
103
```sql
102
-
START TRANSACTION;
104
+
BEGIN;
105
+
INSERT INTO users (username) VALUES ('jane'), ('chris'), ('bill');
103
106
```
104
107
105
108
```
106
-
Query OK, 0 rows affected (0.00 sec)
109
+
ERROR 1062 (23000): Duplicate entry 'bill' for key 'username'
107
110
```
108
111
112
+
With optimistic locking and `tidb_constraint_check_in_place=0`:
113
+
109
114
{{< copyable "sql" >}}
110
115
111
116
```sql
117
+
BEGIN OPTIMISTIC;
112
118
INSERT INTO users (username) VALUES ('jane'), ('chris'), ('bill');
113
119
```
114
120
115
121
```
122
+
Query OK, 0 rows affected (0.00 sec)
123
+
116
124
Query OK, 3 rows affected (0.00 sec)
117
125
Records: 3 Duplicates: 0 Warnings: 0
118
126
```
@@ -138,9 +146,9 @@ COMMIT;
138
146
ERROR 1062 (23000): Duplicate entry 'bill' for key 'username'
139
147
```
140
148
141
-
The first `INSERT` statement will not cause duplicate key errors, which is consistent with MySQL's rules. This check will be delayed until the transaction is committed.
149
+
In the optimistic example, the unique check was delayed until the transaction is committed. This resulted in a duplicate key error, because the value `bill` was already present.
142
150
143
-
You can disable this behavior by setting `tidb_constraint_check_in_place` to `1`. This variable setting does not take effect on pessimistic transactions, because in the pessimistic transaction mode the constraints are always checked when the statement is executed. If this behavior is disabled, the unique constraint is checked when the statement is executed.
151
+
You can disable this behavior by setting `tidb_constraint_check_in_place` to `1`. This variable setting does not take effect on pessimistic transactions, because in the pessimistic transaction mode the constraints are always checked when the statement is executed. When `tidb_constraint_check_in_place=1`, the unique constraint is checked when the statement is executed.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-alter-database.md
+4
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,10 @@ alter_specification:
30
30
31
31
The `alter_specification` option specifies the `CHARACTER SET` and `COLLATE` of a specified database. Currently, TiDB only supports some character sets and collations. See [Character Set and Collation Support](/character-set-and-collation.md) for details.
32
32
33
+
## MySQL compatibility
34
+
35
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
You can add the `PESSIMISTIC` or `OPTIMISTIC` option to the `BEGIN` statement in TiDB to indicate the type of transaction that this statement starts.
37
+
TiDB supports the syntax extension of `BEGIN PESSMISTIC` or `BEGIN OPTIMISTIC`. This enables you to override the default transactional model for your transaction.
*In MySQL, with the exception of Group Replication with multiple primaries, it is not typical that a `COMMIT` statement could result in an error. By contrast, TiDB uses optimistic concurrency control and conflicts may result in `COMMIT` returning an error.
42
-
*Be default, `UNIQUE` and `PRIMARY KEY` constraint checks are deferred until statement commit. This behavior can be changed by setting `tidb_constraint_check_in_place=TRUE`.
41
+
*By default, TiDB 3.0.8 and later versions use [Pessimistic Locking](/pessimistic-transaction.md). When using [Optimistic Locking](/optimistic-transaction.md), it is important to consider that a `COMMIT` statement might fail because rows have been modified by another transaction.
42
+
*When Optimistic Locking is enabled, `UNIQUE` and `PRIMARY KEY` constraint checks are deferred until statement commit. This results in additional situations where a a `COMMIT` statement might fail. This behavior can be changed by setting `tidb_constraint_check_in_place=TRUE`.
43
43
* TiDB only has syntactic support for `CompletionTypeWithinTransaction`. Closing the connection or continuing to open a new transaction after the transaction is committed is not supported.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-create-database.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -65,7 +65,7 @@ mysql> SHOW TABLES;
65
65
66
66
## MySQL compatibility
67
67
68
-
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
68
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-create-role.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -156,7 +156,7 @@ mysql> SHOW TABLES IN test;
156
156
157
157
## MySQL compatibility
158
158
159
-
This statement is understood to be fully compatible with roles, which are a feature of MySQL 8.0. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
159
+
This statement is understood to be fully compatible with roles, which are a feature of MySQL 8.0. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-create-sequence.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -298,9 +298,9 @@ You can control a sequence through the following expression functions:
298
298
299
299
## MySQL compatibility
300
300
301
-
Currently, MySQL does not have the sequence option. The TiDB sequence is borrowed from MariaDB. Except for the `SETVAL` function, all other functions have the same progressions with those functions of MariaDB.
301
+
This statement is a TiDB extension. The implementation is modeled on sequences available in MariaDB.
302
302
303
-
Here "progression" means that the numbers in a sequence follow a certain arithmetic progression rule defined by the sequence. Although you can use `SETVAL` to set the current value of a sequence, the subsequent values of the sequence still follow the original progression rule.
303
+
Except for the `SETVAL` function, all other functions have the same _progressions_ as MariaDB. Here "progression" means that the numbers in a sequence follow a certain arithmetic progression rule defined by the sequence. Although you can use `SETVAL` to set the current value of a sequence, the subsequent values of the sequence still follow the original progression rule.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-create-table-like.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ If the table to be copied is defined with the `PRE_SPLIT_REGIONS` attribute, the
53
53
54
54
## MySQL compatibility
55
55
56
-
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
56
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
48
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-delete.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ mysql> SELECT * FROM t1;
53
53
54
54
## MySQL compatibility
55
55
56
-
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
56
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
57
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-drop-database.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ mysql> SHOW DATABASES;
48
48
49
49
## MySQL compatibility
50
50
51
-
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
51
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-drop-role.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -200,7 +200,7 @@ ERROR 3530 (HY000): `analyticsteam`@`%` is is not granted to jennifer@%
200
200
201
201
## MySQL compatibility
202
202
203
-
This statement is understood to be fully compatible with roles, which are a feature of MySQL 8.0. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
203
+
This statement is understood to be fully compatible with roles, which are a feature of MySQL 8.0. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-drop-view.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -75,7 +75,7 @@ mysql> SELECT * FROM t1;
75
75
76
76
## MySQL compatibility
77
77
78
-
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
78
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
40
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-flashback-table.md
+4
Original file line number
Diff line number
Diff line change
@@ -100,3 +100,7 @@ From the above process, you can see that TiDB always operates on the metadata of
100
100
> You cannot use `FLASHBACK` statements to restore the same deleted table multiple times, because the ID of the restored table is the same ID of the dropped table, and TiDB requires that all existing tables must have a globally unique table ID.
101
101
102
102
The `FLASHBACK TABLE` operation is done by TiDB obtaining the table metadata through snapshot read, and then going through the process of table creation similar to `CREATE TABLE`. Therefore, `FLASHBACK TABLE` is, in essence, a kind of DDL operation.
103
+
104
+
## MySQL compatibility
105
+
106
+
This statement is a TiDB extension to MySQL syntax.
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
35
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-flush-tables.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -50,8 +50,8 @@ ERROR 1105 (HY000): FLUSH TABLES WITH READ LOCK is not supported. Please use @@
50
50
51
51
## MySQL compatibility
52
52
53
-
* TiDB does not have a concept of table cache as in MySQL. Thus, `FLUSH TABLES` is parsed but ignored in TiDB for compatibility.
54
-
* The statement `FLUSH TABLES WITH READ LOCK` produces an error, as TiDB does not currently support locking tables. It is recommended to use [Historical reads] for this purpose instead.
53
+
* TiDB does not have a concept of table cache as in MySQL. Thus, `FLUSH TABLES` is parsed but ignored in TiDB for compatibility.
54
+
* The statement `FLUSH TABLES WITH READ LOCK` produces an error, as TiDB does not currently support locking tables. It is recommended to use [Historical reads](/read-historical-data.md) for this purpose instead.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-grant-role.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -156,7 +156,7 @@ mysql> SHOW TABLES IN test;
156
156
157
157
## MySQL compatibility
158
158
159
-
This statement is understood to be fully compatible with roles, which are a feature of MySQL 8.0. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
159
+
This statement is understood to be fully compatible with roles, which are a feature of MySQL 8.0. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-insert.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -102,7 +102,7 @@ mysql> SELECT * FROM t2;
102
102
103
103
## MySQL compatibility
104
104
105
-
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
105
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
The statement `KILL TIDB` is used to terminate connections in TiDB.
10
10
11
-
By design, this statement is not compatible with MySQL by default. This helps prevent against a case of a connection being terminated on the wrong TiDB server, since it is common to place multiple TiDB servers behind a load balancer.
* By design, this statement is not compatible with MySQL by default. This helps prevent against a case of a connection being terminated on the wrong TiDB server, because it is common to place multiple TiDB servers behind a load balancer.
41
40
* The `KILL TIDB` statement is a TiDB extension. If you are certain that the session you are attempting to kill is on the same TiDB server, set [`compatible-kill-query = true`](/tidb-configuration-file.md#compatible-kill-query) in your configuration file.
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
44
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-recover-table.md
+4
Original file line number
Diff line number
Diff line change
@@ -123,3 +123,7 @@ When deleting a table, TiDB only deletes the table metadata, and writes the tabl
123
123
Therefore, to recover a table, you only need to recover the table metadata anddelete the corresponding row record in the `mysql.gc_delete_range` table before the GC Worker deletes the table data. You can use a snapshot read of TiDB to recover the table metadata. Refer to [Read Historical Data](/read-historical-data.md) for details.
124
124
125
125
Table recovery is done by TiDB obtaining the table metadata through snapshot read, and then going through the process of table creation similar to `CREATE TABLE`. Therefore, `RECOVER TABLE` itself is, in essence, a kind of DDL operation.
126
+
127
+
## MySQL compatibility
128
+
129
+
This statement is a TiDB extension to MySQL syntax.
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
55
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-rename-table.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ mysql> SHOW TABLES;
46
46
47
47
## MySQL compatibility
48
48
49
-
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
49
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
Copy file name to clipboardexpand all lines: sql-statements/sql-statement-replace.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,7 @@ mysql> SELECT * FROM t1;
70
70
71
71
## MySQL compatibility
72
72
73
-
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
73
+
This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
0 commit comments