I am using Django and MySQL. I need to be able to do what in Oracle is called an autonomous transaction, that is, committing only part of a transaction (or, rather, having a transaction within a transaction). I need this for two cases (although I’m thinking that the solution will be the same):
-
Error logging. I log errors in an error table and want to commit these inserts even if I rollback all other transactions.
-
I use a table to create a sequence (using TABLE sequence and LAST_INSERT_ID() as described here: http://dev.mysql.com/doc/refman/5.0/en/information-functions.html). I want to get/update this sequence and then commit the statement, thereby unlocking the table for other transactions that need the sequence. It’s fine if the table gets incremented even if I rollback the other transactions.
Interesting subject, apparently there’s no such thing in mysql but a guy recommends to use (for your log table problem) a myisam table, so since it is outside transactions, the data gets posted anyway.
I am adding a second answer since I just figured out this alternative: what you could do is to handle the log transaction from another connection with another user in your database.
Mysql handles the connection pool per user so it will never use the same connection for the main operations and the log operations, allowing you to commit the logs connection independently.