Back-story: A developer came to me and wanted explanation for a weird
behavior in MySQL. They inserted a record (to InnoDB table), committed,
and after receiving a message (on another application) tried to read
that inserted record immediately, but the newly inserted record was not
found. Problem only happened in production, but not always (quite
frequently).
After comparing the MySQL parameter files between production and development environments I discovered that in production autocommit
was disabled to make MySQL behave more like Oracle. This setting was
removed from development after we rebuilt the environment (to use
multiple MySQL instances with Oracle Clusterware, instead of one large
MySQL instance), but the rebuild was not yet done in production.
The default transaction level for MySQL InnoDB is REPEATABLE READ
(unlike Oracle, that has READ COMMITTED as default), that means that the
SELECT query always returns the data at the time point when the transaction
was started. If autocommit is off, then the first issued select
statement will open the transaction and any subsequent select statement
will return the data at the time point when the first select was issued,
until transaction is ended with COMMIT/ROLLBACK. If autocommit is
enabled, SELECT statement is run in a self-contained transaction, ending
with COMMIT, so the end result is like READ COMMITTED isolation level
in Oracle.
http://ilmarkerm.blogspot.com/2012/06/little-side-effect-of-having-autocommit.html
Sabtu, 23 Juni 2012
A little "side-effect" of having autocommit off in MySQL
Langganan:
Posting Komentar (Atom)
0 komentar:
Posting Komentar