SAVEPOINTidentifierROLLBACK [WORK] TO [SAVEPOINT]identifierRELEASE SAVEPOINTidentifier
InnoDB支持 SQL 语句SAVEPOINT,
ROLLBACK TO
SAVEPOINT,
RELEASE
SAVEPOINT以及可选的WORK关键字用于ROLLBACK.InnoDB supports the SQL statements
SAVEPOINT,
ROLLBACK TO
SAVEPOINT,
RELEASE
SAVEPOINT and the optional WORK
keyword for
ROLLBACK.
SAVEPOINT 语句设置名为 identifier 的命名事务保存点。如果当前事务有同名保存点,旧存点会被删除,新存点被设置。The SAVEPOINT statement sets a
named transaction savepoint with a name of
identifier. If the current transaction
has a savepoint with the same name, the old savepoint is deleted
and a new one is set.
ROLLBACK TO
SAVEPOINT 语句可在不终止事务的情况下回滚到指定保存点。当前事务在保存点设置后对行所做的修改会在回滚中被撤销,但 InnoDB 不会释放保存点后存储在内存中的行锁。(对于新插入的行,锁信息由存储在该行的事务 ID 传递;该锁不会单独存储在内存中。在这种情况下,行锁会在撤销时释放。)在命名保存点之后设置的保存点会被删除。The ROLLBACK TO
SAVEPOINT statement rolls back a transaction to the
named savepoint without terminating the transaction. Modifications
that the current transaction made to rows after the savepoint was
set are undone in the rollback, but InnoDB does
not release the row locks that were stored in
memory after the savepoint. (For a new inserted row, the lock
information is carried by the transaction ID stored in the row;
the lock is not separately stored in memory. In this case, the row
lock is released in the undo.) Savepoints that were set at a later
time than the named savepoint are deleted.
如果 ROLLBACK TO
SAVEPOINT 语句返回以下错误,表示不存在指定名称的存档:If the ROLLBACK TO
SAVEPOINT statement returns the following error, it
means that no savepoint with the specified name exists:
ERROR 1305 (42000): SAVEPOINT identifier does not exist
The RELEASE
SAVEPOINT 语句会从当前事务的存档集合中移除命名的保存点。不会发生提交或回滚。如果不存在该保存点,则为错误。The RELEASE
SAVEPOINT statement removes the named savepoint from the
set of savepoints of the current transaction. No commit or
rollback occurs. It is an error if the savepoint does not exist.
如果您执行COMMIT或 ROLLBACK。All savepoints of the current transaction are deleted if you
execute a COMMIT, or a
ROLLBACK that
does not name a savepoint.
当调用存储函数或激活触发器时,会创建一个新的保存点级别。之前级别的保存点将不可用,因此不会与新级别的保存点冲突。当函数或触发器终止时,它创建的所有保存点会被释放,之前的保存点级别会被恢复。A new savepoint level is created when a stored function is invoked or a trigger is activated. The savepoints on previous levels become unavailable and thus do not conflict with savepoints on the new level. When the function or trigger terminates, any savepoints it created are released and the previous savepoint level is restored.