Statements That Cause an Implicit Commit
The statements listed in this section (and any synonyms for them) implicitly end a transaction, as if you had done a COMMIT before executing the statement. As of MariaDB 5.5.3, most of these statements also cause an implicit commit after executing; for additional details, see the end of this section.
- Data definition language (DDL) statements that define or modify database objects.
ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME,ALTER EVENT,ALTER PROCEDURE,ALTER TABLE,ALTER VIEW,CREATE DATABASE,CREATE EVENT,CREATE INDEX,CREATE PROCEDURE,CREATE TABLE,CREATE TRIGGER,CREATE VIEW,DROP DATABASE,DROP EVENT,DROP INDEX,DROP PROCEDURE,DROP TABLE,DROP TRIGGER,DROP VIEW,RENAME TABLE,TRUNCATE TABLE.ALTER FUNCTION,CREATE FUNCTIONandDROP FUNCTIONalso cause an implicit commit when used with stored functions, but not with UDFs. (ALTER FUNCTIONcan only be used with stored functions.)ALTER TABLE,CREATE TABLE, andDROP TABLEdo not commit a transaction if theTEMPORARYkeyword is used. (This does not apply to other operations on temporary tables such asCREATE INDEX, which do cause a commit.) However, although no implicit commit occurs, neither can the statement be rolled back. Therefore, use of such statements will violate transaction atomicity: For example, if you useCREATE TEMPORARY TABLEand then roll back the transaction, the table remains in existence.The
CREATE TABLEstatement inInnoDBis processed as a single transaction. This means that aROLLBACKfrom the user does not undoCREATE TABLEstatements the user made during that transaction.CREATE TABLE ... SELECTcauses an implicit commit before and after the statement is executed when you are creating nontemporary tables. (No commit occurs forCREATE TEMPORARY TABLE ... SELECT.) This is to prevent an issue during replication where the table could be created on the master after a rollback, but fail to be recorded in the binary log, and therefore not replicated to the slave. For more information, see Bug #22865. - Statements that implicitly use or modify tables in the
MariaDBdatabase.CREATE USER,DROP USER,GRANT,RENAME USER,REVOKE,SET PASSWORD. - Transaction-control and locking statements.
BEGIN,LOCK TABLES,SET autocommit = 1(if the value is not already 1),START TRANSACTION,UNLOCK TABLES.UNLOCK TABLEScommits a transaction only if any tables currently have been locked withLOCK TABLESto acquire nontransactional table locks. A commit does not occur forUNLOCK TABLESfollowingFLUSH TABLES WITH READ LOCKbecause the latter statement does not acquire table-level locks.Transactions cannot be nested. This is a consequence of the implicit commit performed for any current transaction when you issue a
START TRANSACTIONstatement or one of its synonyms.Statements that cause an implicit commit cannot be used in an XA transaction while the transaction is in an
ACTIVEstate.The
BEGINstatement differs from the use of theBEGINkeyword that starts aBEGIN ... ENDcompound statement. The latter does not cause an implicit commit. See , "BEGIN ... ENDCompound-Statement Syntax". - Data loading statements.
LOAD DATA INFILE.LOAD DATA INFILEcauses an implicit commit only for tables using theNDBstorage engine. For more information, see Bug #11151. - Administrative statements.
ANALYZE TABLE,CACHE INDEX,CHECK TABLE,LOAD INDEX INTO CACHE,OPTIMIZE TABLE,REPAIR TABLE.
As of MariaDB 5.5.3, most statements that previously caused an implicit commit before executing also do so after executing. The intent is to handle each such statement in its own special transaction because it cannot be rolled back anyway. The following list provides additional details pertaining to this change:
- The
CREATE TABLEvariants (CREATE TABLEforInnoDBtables andCREATE TABLE ... SELECT) that previously were special cases no longer are so becauseCREATE TABLEuniformly causes an implicit commit before and after executing. - The
FLUSHandRESETstatements cause an implicit commit. - Transaction-control and locking statements behave as before.