Skip to content

Latest commit

 

History

History
50 lines (33 loc) · 1.89 KB

sql-statement-commit.md

File metadata and controls

50 lines (33 loc) · 1.89 KB
title summary aliases
COMMIT | TiDB SQL Statement Reference
An overview of the usage of COMMIT for the TiDB database.
/docs/dev/sql-statements/sql-statement-commit/
/docs/dev/reference/sql/statements/commit/

COMMIT

This statement commits a transaction inside of the TIDB server.

In the absence of a BEGIN or START TRANSACTION statement, the default behavior of TiDB is that every statement will be its own transaction and autocommit. This behavior ensures MySQL compatibility.

Synopsis

CommitStmt:

CommitStmt

CompletionTypeWithinTransaction:

CompletionTypeWithinTransaction

Examples

mysql> CREATE TABLE t1 (a int NOT NULL PRIMARY KEY);
Query OK, 0 rows affected (0.12 sec)

mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t1 VALUES (1);
Query OK, 1 row affected (0.00 sec)

mysql> COMMIT;
Query OK, 0 rows affected (0.01 sec)

MySQL compatibility

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

See also