![]() |
|
|
| |
|
||||
In database systems, isolation is a property that the changes made by an operation are not visible to other simultaneous operations on the system until its completion. This is one of the ACID properties.
Isolation LevelsThe Isolation property is the most often relaxed ACID property in a DBMS. This is because to maintain isolation a DBMS must aquire locks on returned data, which can involve a lot of overhead for the DBMS and thread contention for the locks. Most DBMS's offer a number of transation isolation levels which control the degree of locking which occurs when selecting data. For many database applications the majority of database transactions can be constructed in such a way as to not require high isolation levels, thus reducing the locking overhead for the system. The programmer must carefully analyse database access code to ensure that any relaxation of isolation does not cause difficult to find software bugs. Conversley, at higher isolation levels the possibility of deadlock is increased, which also requires careful analysis and programming techniques to avoid. The isolation levels available include:
The default isolation level of different DBMS systems varies quite widley. Most transactional databases which feature transactions allow the user to set any isolation level. Some DBMS systems also require additional syntax when performing a SELECT statement which is to aquire locks. Example QueriesIn these examples two transactions take place. In the first transaction, Query 1 is performed, then Query 2 is performed in the second transaction and the transaction committed, followed by Query 1 is being performed again in the first transaction. The queries use the following data table.
Phantom ReadsThe phantom reads phenomenon occours when range locks are not aquired on performing a SELECT. /* Query 1 */ SELECT * FROM users WHERE age BETWEEN 10 AND 30; /* Query 2 */ INSERT INTO users VALUES ( 3, Bob, 27 ); In the SERIALIZABLE isolation mode, Query 1 would result in all records with age in the range 10 to 30 being locked, thus Query 2 would block until the first transaction was committed. In REPEATABLE READ mode, the range would not be locked, allowing the record to be inserted and the second execution of Query 1 to return the new row in it's results. Non-repeatable ReadsNon-repeatable reads occur when read locks are not aquired on performing a SELECT. /* Query 1 */ SELECT * FROM users WHERE id = 1; /* Query 2 */ UPDATE users SET age = 21 WHERE id = 1; In the REPEATABLE READ isolation mode, the row with ID = 1 would be locked, thus blocking Query 2 until the first transaction was committed. In READ COMMITTED mode the second time Query 1 was executed the age would have changed. Dirty ReadsDirty reads works similarly to non-repeatable reads, however the second transaction would not need to be committed for the first query to return a different result. The only thing prevented in the READ UNCOMMITTED mode is that updates will not appear in the results out of order, that is earlier updates will always appear in a result set before later updates. (nb: this needs to be checked) See also
|
|||||||||||
|
|
|
|
|
|
Copyright 2008 WordIQ.com - Privacy Policy
::
Terms of Use
:: Contact Us
:: About Us This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Isolation (computer science)". |