Reprint: Database Consistency of understanding

ACID:

  - Atomicity: the transaction is either completely or not at all. For this, the beginning of the transaction is marked with the BEGIN command, and the end is either COMMIT (commit changes) or ROLLBACK (undo changes).
  - Consistency: the transaction begins in a consistent state and, completing, also maintains consistency.
  - Isolation: other transactions running at the same time with this one should not affect it.
  - Durability: after the data are recorded, they should not be lost even in case of failure.

 

Consistency means that the data is meaningful and proper state on a semantic. Consistency of data visibility constraint is to ensure that the data in the intermediate state of multiple operations in a transaction is not visible to other transactions. Because these intermediate state is a transitional state, start state and end state of affairs is inconsistent with the transaction.
For chestnut, Zhang Doe to transfer $ 100. Affairs do is to lose 100 yuan from Zhang San account, plus 100 yuan on the account of John Doe. Consistency is the meaning of other things to see Joe Smith or John Doe has not transfer to the state or John Doe John Doe has been successfully transfer to the state, and $ 100 less for Joe Smith, not John Doe plus 100 yuan this intermediate state is not visible.
Then came the sound of retort:

1. either transfer all operations succeed or fail, it is atomic. From the point of view of all examples of success, then the consistency is slightly atomic part, why say consistency and atomicity alone? 
2. You are wrong. In uncommitted read isolation level is the internal affairs operation is visible, this time there will be dirty read, in clear violation of consistency, how to explain?

Well, your question makes sense, is also very good, this just shows that you understand the ACID properties of the transaction is in place. However, it should be noted that:

1. atomicity and consistency of the different emphases: atomic concerned state, either all succeed, or all fail, partially successful state does not exist. The visibility of the consistency of the data of interest, intermediate state data is not visible to the outside, only the initial state and final state data external visibility. 
2. Under uncommitted read isolation level will cause dirty read, this is because of a transactional data read operation of the internal affairs of another. ACID is consistency describes how a transaction should ideally, is a strong consistency state, if you want to do this, you need to use an exclusive lock to the transaction lined up, namely Serializable isolation level, such performance is greatly reduced. The reality is skinny, so the use of isolation of different isolation levels to destroy consistency, to get better performance.

  

Guess you like

Origin www.cnblogs.com/jkwll/p/11520989.html