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.

234<br />

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

inserts, updates, <strong>and</strong> deletes are not permitted in this mode (other sessions may update data,<br />

but not the READ ONLY transaction). Using this mode, you can achieve REPEATABLE READ <strong>and</strong><br />

SERIALIZABLE levels of isolation.<br />

Let’s now move on to discuss exactly how multi-versioning <strong>and</strong> read consistency fits into<br />

the isolation scheme, <strong>and</strong> how databases that do not support multi-versioning achieve the<br />

same results. This information is instructive for anyone who has used another database <strong>and</strong><br />

believes he or she underst<strong>and</strong>s how the isolation levels must work. It is also interesting to<br />

see how a st<strong>and</strong>ard that was supposed to remove the differences between the databases,<br />

ANSI/ISO SQL, actually allows for them. The st<strong>and</strong>ard, while very detailed, can be implemented<br />

in very different ways.<br />

READ UNCOMMITTED<br />

The READ UNCOMMITTED isolation level allows dirty reads. <strong>Oracle</strong> does not make use of dirty<br />

reads, nor does it even allow for them. The basic goal of a READ UNCOMMITTED isolation level is<br />

to provide a st<strong>and</strong>ards-based definition that caters for non-blocking reads. As we have seen,<br />

<strong>Oracle</strong> provides for non-blocking reads by default. You would be hard-pressed to make a<br />

SELECT query block in the database (as noted earlier, there is the special case of a distributed<br />

transaction). Every single query, be it a SELECT, INSERT, UPDATE, MERGE, or DELETE, executes in a<br />

read-consistent fashion. It might seem funny to refer to an UPDATE statement as a query—but it<br />

is. UPDATE statements have two components: a read component as defined by the WHERE clause<br />

<strong>and</strong> a write component as defined by the SET clause. UPDATE statements read from <strong>and</strong> write<br />

to the database—as do all DML statements. The special case of a single row INSERT using the<br />

VALUES clause is the only exception to this, as such statements have no read component, just<br />

the write component.<br />

In Chapter 1, <strong>Oracle</strong>’s method of obtaining read consistency was demonstrated by way<br />

of a simple single table query, which retrieved rows that were deleted after the cursor was<br />

opened. We’re now going to explore a real-world example to see what happens in <strong>Oracle</strong> using<br />

multi-versioning, as well as what happens in any number of other databases.<br />

Let’s start with the same basic table <strong>and</strong> query:<br />

create table accounts<br />

( account_number number primary key,<br />

account_balance number not null<br />

);<br />

select sum(account_balance) from accounts;<br />

Before the query begins, we have the data shown in Table 7-2.<br />

Table 7-2. ACCOUNTS Table Before Modifications<br />

Row Account Number Account Balance<br />

1 123 $500.00<br />

2 456 $240.25<br />

. . . . . . . . .<br />

342,023 987 $100.00

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

Saved successfully!

Ooh no, something went wrong!