Will out-of-transaction SELECT see only committed data?
UPD. My database is MySQL
UPD. I’m interested in simple SELECT statement which comes without explicit transaction. What data will it see? How can I change it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume you are asking regarding InnoDB, since MyISAM does not support transactions.
There is no such thing as out of transaction, even with the default
autocommit=1, every statement for itself is a transaction.The answer to your question depends on what you mean by
only committed data.Say we have a table with a row:
While session A is modifying the row:
If session B issues a select before session A commits the transaction, what will happen is dependent on the transaction isolation level of session B.
READ UNCOMMITTED: session B will read the newly modified row (counter = 101).READ COMMITTED/REPEATABLE READ (default): Session B will see the latest committed row (counter = 100).SERIALIZABLE: session B will block until session A commits.Here is how a one can change the session transaction level without declaring a transaction.