# SAVEPOINT

+ `SAVEPOINT` is used to set a savepoint in the current transaction
+ `ROLLBACK TO SAVEPOINT` 
  + Rolls back a transaction to the savepoint
  + Does NOT terminate the transaction
  + Deletes other savepoints after the savepoint rolled back to
  + Does NOT rollback the the locks, in pessimistic transactions


------------------------------------------------------------
+ `SAVEPOINT` is used to set a savepoint of a specified name in the current transaction. If a savepoint with the same name already exists, it will be deleted and a new savepoint with the same name will be set.

+ `ROLLBACK TO SAVEPOINT` rolls back a transaction to the savepoint of a specified name and does not terminate the transaction. Data changes made to the table data after the savepoint will be reverted in the rollback, and all savepoints after the savepoint are deleted. In a pessimistic transaction, the locks held by the transaction are not rolled back. Instead, the locks will be released when the transaction ends.

+ When `ROLLBACK TO SAVEPOINT` is used to roll back a transaction to a specified savepoint, MySQL releases the locks held only after the specified savepoint, while in TiDB pessimistic transaction, TiDB does not immediately release the locks held after the specified savepoint. Instead, TiDB releases all locks when the transaction is committed or rolled back.