views:

22

answers:

1

Whatever changes made to the MySQL database, are those changes readable within the same transaction? Or should I commit the transaction to read the changes?

I could easily test this. But putting a question in SO brings up a lot of good suggestions. Thanks for any input.

+2  A: 

Assuming you're using InnoDB, the answer to your first question is generally yes, implying the answer to your second is generally no.

By default MySQL's InnoDB uses a technique called consistent non-locking reads:

The query sees the changes made by transactions that committed before that point of time, and no changes made by later or uncommitted transactions. The exception to this rule is that the query sees the changes made by earlier statements within the same transaction.

That being said, there's a lot of stuff to know about transactions. You can change the isolation level of a transaction in order to control the transaction results more thoroughly.

The chapter on the InnoDB Transaction Model is a great place to start.

zombat
Thanks! The link about locks set by statements is very useful.
Nirmal