Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
CHAPTER 6 ■ LOCKING AND LATCHING 207 34 and i.column_position
208 CHAPTER 6 ■ LOCKING AND LATCHING • You do not delete from the parent table. • You do not update the parent table’s unique/primary key value (watch for unintended updates to the primary key by tools!). • You do not join from the parent to the child (like DEPT to EMP). If you satisfy all three conditions, feel free to skip the index—it is not needed. If you meet any of the preceding conditions, be aware of the consequences. This is the one rare instance when Oracle tends to “overlock” data. Lock Escalation When lock escalation occurs, the system is decreasing the granularity of your locks. An example would be the database system turning your 100 row-level locks against a table into a single table-level lock. You are now using “one lock to lock everything” and, typically, you are also locking a whole lot more data than you were before. Lock escalation is used frequently in databases that consider a lock to be a scarce resource and overhead to be avoided. ■Note Oracle will never escalate a lock. Never. Oracle never escalates locks, but it does practice lock conversion or lock promotion— terms that are often confused with lock escalation. ■Note The terms “lock conversion” and “lock promotion” are synonymous. Oracle typically refers to the process as “lock conversion.” Oracle will take a lock at the lowest level possible (i.e., the least restrictive lock possible) and convert that lock to a more restrictive level if necessary. For example, if you select a row from a table with the FOR UPDATE clause, two locks will be created. One lock is placed on the row(s) you selected (and this will be an exclusive lock; no one else can lock that specific row in exclusive mode). The other lock, a ROW SHARE TABLE lock, is placed on the table itself. This will prevent other sessions from placing an exclusive lock on the table and thus prevent them from altering the structure of the table, for example. Another session can modify any other row in this table without conflict. As many commands as possible that could execute successfully given there is a locked row in the table will be permitted. Lock escalation is not a database “feature.” It is not a desired attribute. The fact that a database supports lock escalation implies there is some inherent overhead in its locking mechanism and significant work is performed to manage hundreds of locks. In Oracle, the overhead to have 1 lock or 1 million locks is the same: none.
- Page 202 and 203: CHAPTER 5 ■ ORACLE PROCESSES 157
- Page 204 and 205: CHAPTER 5 ■ ORACLE PROCESSES 159
- Page 206 and 207: CHAPTER 5 ■ ORACLE PROCESSES 161
- Page 208 and 209: CHAPTER 5 ■ ORACLE PROCESSES 163
- Page 210 and 211: CHAPTER 5 ■ ORACLE PROCESSES 165
- Page 212 and 213: CHAPTER 5 ■ ORACLE PROCESSES 167
- Page 214 and 215: CHAPTER 5 ■ ORACLE PROCESSES 169
- Page 216 and 217: CHAPTER 5 ■ ORACLE PROCESSES 171
- Page 218 and 219: CHAPTER 5 ■ ORACLE PROCESSES 173
- Page 220 and 221: CHAPTER 5 ■ ORACLE PROCESSES 175
- Page 222 and 223: CHAPTER 5 ■ ORACLE PROCESSES 177
- Page 224 and 225: CHAPTER 5 ■ ORACLE PROCESSES 179
- Page 226 and 227: CHAPTER 5 ■ ORACLE PROCESSES 181
- Page 228 and 229: CHAPTER 6 ■ ■ ■ Locking and L
- Page 230 and 231: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 232 and 233: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 234 and 235: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 236 and 237: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 238 and 239: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 240 and 241: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 242 and 243: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 244 and 245: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 246 and 247: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 248 and 249: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 250 and 251: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 254 and 255: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 256 and 257: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 258 and 259: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 260 and 261: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 262 and 263: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 264 and 265: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 266 and 267: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 268 and 269: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 270 and 271: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 272 and 273: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 274 and 275: CHAPTER 6 ■ LOCKING AND LATCHING
- Page 276 and 277: CHAPTER 7 ■ ■ ■ Concurrency a
- Page 278 and 279: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 280 and 281: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 282 and 283: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 284 and 285: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 286 and 287: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 288 and 289: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 290 and 291: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 292 and 293: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 294 and 295: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 296 and 297: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 298 and 299: CHAPTER 7 ■ CONCURRENCY AND MULTI
- Page 300 and 301: CHAPTER 8 ■ ■ ■ Transactions
208<br />
CHAPTER 6 ■ LOCKING AND LATCHING<br />
• You do not delete from the parent table.<br />
• You do not update the parent table’s unique/primary key value (watch for unintended<br />
updates to the primary key by tools!).<br />
• You do not join from the parent to the child (like DEPT to EMP).<br />
If you satisfy all three conditions, feel free to skip the index—it is not needed. If you meet<br />
any of the preceding conditions, be aware of the consequences. This is the one rare instance<br />
when <strong>Oracle</strong> tends to “overlock” data.<br />
Lock Escalation<br />
When lock escalation occurs, the system is decreasing the granularity of your locks. An example<br />
would be the database system turning your 100 row-level locks against a table into a single<br />
table-level lock. You are now using “one lock to lock everything” <strong>and</strong>, typically, you are also<br />
locking a whole lot more data than you were before. Lock escalation is used frequently in databases<br />
that consider a lock to be a scarce resource <strong>and</strong> overhead to be avoided.<br />
■Note <strong>Oracle</strong> will never escalate a lock. Never.<br />
<strong>Oracle</strong> never escalates locks, but it does practice lock conversion or lock promotion—<br />
terms that are often confused with lock escalation.<br />
■Note The terms “lock conversion” <strong>and</strong> “lock promotion” are synonymous. <strong>Oracle</strong> typically refers to the<br />
process as “lock conversion.”<br />
<strong>Oracle</strong> will take a lock at the lowest level possible (i.e., the least restrictive lock possible)<br />
<strong>and</strong> convert that lock to a more restrictive level if necessary. For example, if you select a row<br />
from a table with the FOR UPDATE clause, two locks will be created. One lock is placed on the<br />
row(s) you selected (<strong>and</strong> this will be an exclusive lock; no one else can lock that specific row in<br />
exclusive mode). The other lock, a ROW SHARE TABLE lock, is placed on the table itself. This will<br />
prevent other sessions from placing an exclusive lock on the table <strong>and</strong> thus prevent them from<br />
altering the structure of the table, for example. Another session can modify any other row in<br />
this table without conflict. As many comm<strong>and</strong>s as possible that could execute successfully<br />
given there is a locked row in the table will be permitted.<br />
Lock escalation is not a database “feature.” It is not a desired attribute. The fact that a<br />
database supports lock escalation implies there is some inherent overhead in its locking<br />
mechanism <strong>and</strong> significant work is performed to manage hundreds of locks. In <strong>Oracle</strong>, the<br />
overhead to have 1 lock or 1 million locks is the same: none.