SQL Anywhere uses schema, row, table, and position locks as necessary to ensure the level of consistency that you require. You do not need to explicitly request the use of a particular lock. Instead, you control the level of consistency that is maintained by choosing the isolation level that best fits your requirements. Knowledge of the types of locks will guide you in choosing isolation levels and understanding the impact of each level on performance. Keep in mind that any one transaction cannot block itself by acquiring locks; a locking conflict can only occur between two (or more) transactions.
While each of the four types of locks have specific purposes, all the types interact and therefore may cause a locking conflict between transactions. To ensure database consistency, only one transaction should change any one row at any one time. Otherwise, two simultaneous transactions might try to change one value to two different new ones. So, it is important that a row write lock be exclusive. In contrast, no difficulty arises if more than one transaction wants to read a row. Since neither is changing it, there is no conflict. So, row read locks may be shared across many connections.
The following table identifies the combination of locks that conflict. Schema locks are not included because they do not apply to rows.
Row locks | readpk | read | intent | writenopk | write |
---|---|---|---|---|---|
readpk | conflict | ||||
read | conflict | conflict | |||
intent | conflict | conflict | conflict | ||
writenopk | conflict | conflict | conflict | conflict | |
write | conflict | conflict | conflict | conflict | conflict |
Table locks | shared | intent | exclusive |
---|---|---|---|
shared | conflict | conflict | |
intent | conflict | conflict | |
exclusive | conflict | conflict | conflict |
Position locks | phantom | insert |
---|---|---|
phantom | conflict | |
insert | conflict |
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |