开发者

Read changes from within a transaction

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 e开发者_开发技巧asily test this. But putting a question in SO brings up a lot of good suggestions. Thanks for any input.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜