Several questions about the database 'affairs' 'lock' the

Disclaimer: This article is a blogger original article, follow the CC 4.0 by-sa copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/Isabella327/article/details/96865317

1. When used in the transaction?

A: A transaction is a sequence of operations, which is characterized not be divided, these actions are either executed or not executed. For example the bank transfer: account number and other grants from a debit account, these two operations 'bound'. A complete business needs batch DML (insert, update, delete) completed a joint statement together.

2. Basic elements of affairs?

Answer: the ACID

  • Atomic (atomic): operating a transaction submitted either all succeed, or all fail rolled back.
  • Consistency (consistency): consistent state from one consistent state to another.
  • Isolation (isolation): a transaction made changes before submitting it to other transactions is not visible.
  • Persistence (durability): Once the transaction is committed, the changes made in the database will be permanently sealed.

3. The transaction isolation level?

answer:

  1. Not authorized to read (read uncommitted): a transaction write data, write data does not allow other affairs, but allows other transactions to read. It is a transaction to read data from other uncommitted transactions. (To solve the problem of lost updates, dirty read problem)
  2. Authorized to read (read committed): a transaction reading data, writing data to allow other affairs, but did not block access to other transactions when the bank submitted. It is a transaction to read data after the other transaction commits. Oracle default isolation level. (Solve the problem of dirty reads, non-repeatable read problems occur)
  3. Repeatable read : a transaction when reading other transactions can not read write, write when a transaction other transactions can not write unreadable. Is a transaction on the same data to be read is the same, I do not care about other transactions modifying the data. MySQL default isolation level. (Phantom read problems arise)
  4. Sequence of : performing a transaction by one (low performance)

4. database concurrency problems occur?

answer:

  1. Update loss : two business-to-line data update, update a transaction covered by another's;
  2. Dirty read : A transaction reads data to another uncommitted transaction;
  3. Non-repeatable read : the result of a transaction data read twice in the same row are different (due to the data updating);
  4. Magic Reading : Transaction data appears first case does not appear in the second reading of the time (due to other matters caused by insertion or deletion of data).

5. concurrency control techniques?

answer:

  1. A shared lock (s locks, read locks): read but not written, but it could also add other read locks;
  2. Exclusive lock (x locks, write locks, eXclusive lock): readable and writable, other transactions can not be locked;
  3. Pessimistic locking : every time someone thought to take the data will change the data, each take all locked;
  4. Optimistic locking : Each take data that other people will not change the data, do not get locked each time, we will see if there are other people update when the update, allowing users to handle;

Guess you like

Origin blog.csdn.net/Isabella327/article/details/96865317