05.11.2015 Views

Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 7 ■ CONCURRENCY AND MULTI-VERSIONING 233<br />

• Phantom read: This means that if you execute a query at time T1 <strong>and</strong> re-execute it at<br />

time T2, additional rows may have been added to the database, which will affect your<br />

results. This differs from the nonrepeatable read in that with a phantom read, data you<br />

already read has not been changed, but rather that more data satisfies your query criteria<br />

than before.<br />

■Note The ANSI/ISO SQL st<strong>and</strong>ard defines transaction-level characteristics, not just individual statementby-statement–level<br />

characteristics. In the following pages, we’ll examine transaction-level isolation, not just<br />

statement-level isolation.<br />

The SQL isolation levels are defined based on whether or not they allow each of the preceding<br />

phenomena. I find it interesting to note that the SQL st<strong>and</strong>ard does not impose a<br />

specific locking scheme or m<strong>and</strong>ate particular behaviors, but rather describes these isolation<br />

levels in terms of these phenomena, allowing for many different locking/concurrency mechanisms<br />

to exist (see Table 7-1).<br />

Table 7-1. ANSI Isolation Levels<br />

Isolation Level Dirty Read Nonrepeatable Read Phantom Read<br />

READ UNCOMMITTED Permitted Permitted Permitted<br />

READ COMMITTED Permitted Permitted<br />

REPEATABLE READ<br />

Permitted<br />

SERIALIZABLE<br />

<strong>Oracle</strong> explicitly supports the READ COMMITTED <strong>and</strong> SERIALIZABLE isolation levels, as they<br />

are defined in the st<strong>and</strong>ard. However, this doesn’t tell the whole story. The SQL st<strong>and</strong>ard was<br />

attempting to set up isolation levels that would permit various degrees of consistency for<br />

queries performed in each level. REPEATABLE READ is the isolation level that the SQL st<strong>and</strong>ard<br />

claims will guarantee a read-consistent result from a query. In the SQL st<strong>and</strong>ard’s definition,<br />

READ COMMITTED does not give you consistent results, <strong>and</strong> READ UNCOMMITTED is the level to use<br />

to get non-blocking reads.<br />

However, in <strong>Oracle</strong>, READ COMMITTED has all of the attributes required to achieve readconsistent<br />

queries. In other databases, READ COMMITTED queries can <strong>and</strong> will return answers<br />

that never existed in the database at any point in time. Moreover, <strong>Oracle</strong> also supports the<br />

spirit of READ UNCOMMITTED. The goal of providing a dirty read is to supply a non-blocking read,<br />

whereby queries are not blocked by, <strong>and</strong> do not block, updates of the same data. However,<br />

<strong>Oracle</strong> does not need dirty reads to achieve this goal, nor does it support them. Dirty reads<br />

are an implementation other databases must use in order to provide non-blocking reads.<br />

In addition to the four defined SQL isolation levels, <strong>Oracle</strong> provides another level, namely<br />

READ ONLY. A READ ONLY transaction is equivalent to a REPEATABLE READ or SERIALIZABLE transaction<br />

that cannot perform any modifications in SQL. A transaction using a READ ONLY isolation<br />

level only sees those changes that were committed at the time the transaction began, but

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!