05.11.2015 Views

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

242<br />

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

report need to be consistent with respect to a single point in time. In other systems, you would<br />

use REPEATABLE READ <strong>and</strong> suffer the associated affects of the shared read lock. In <strong>Oracle</strong>, you<br />

will use the READ ONLY transaction. In this mode, the output you produce in a report that uses<br />

50 SELECT statements to gather the data will be consistent with respect to a single point in<br />

time—the time the transaction began. You will be able to do this without locking a single piece<br />

of data anywhere.<br />

This aim is achieved by using the same multi-versioning as used for individual statements.<br />

The data is reconstructed as needed from the rollback segments <strong>and</strong> presented to you<br />

as it existed when the report began. READ ONLY transactions are not trouble-free, however.<br />

Whereas you might see an ORA-08177 error in a SERIALIZABLE transaction, you expect to see an<br />

ORA-1555: snapshot too old error with READ ONLY transactions. This will happen on a system<br />

where other people are actively modifying the information you are reading. The changes<br />

(undo) made to this information are recorded in the rollback segments. But rollback segments<br />

are used in a circular fashion in much the same manner as redo logs. The longer the report<br />

takes to run, the better the chance that some undo you need to reconstruct your data won’t<br />

be there anymore. The rollback segment will have wrapped around, <strong>and</strong> the portion of it you<br />

need we be reused by some other transaction. At this point, you will receive the ORA-1555 error<br />

<strong>and</strong> have to start over again.<br />

The only solution to this sticky issue is to have rollback segments that are sized correctly<br />

for your system. Time <strong>and</strong> time again, I see people trying to save a few megabytes of disk space<br />

by having the smallest possible rollback segments (“Why ‘waste’ space on something I don’t<br />

really need?” is the thought). The problem is that the rollback segments are a key component<br />

of the way the database works, <strong>and</strong> unless they are sized correctly, you will hit this error. In<br />

16 years of using <strong>Oracle</strong> 6, 7, <strong>and</strong> 8, I can say I have never hit an ORA-1555 error outside of a<br />

testing or development system. In such a case, you know you have not sized the rollback segments<br />

correctly <strong>and</strong> you fix it. We will revisit this issue in Chapter 9.<br />

Implications of Multi-Version Read Consistency<br />

So far, we’ve seen how multi-versioning provides us with non-blocking reads, <strong>and</strong> I have<br />

stressed that this is a good thing: consistent (correct) answers with a high degree of concurrency.<br />

What could be wrong with that? Well, unless you underst<strong>and</strong> that it exists <strong>and</strong> what<br />

it implies, then you are probably doing some of your transactions incorrectly. Recall from<br />

Chapter 1 the scheduling resources example whereby we had to employ some manual locking<br />

techniques (via SELECT FOR UPDATE to serialize modifications to the SCHEDULES table by<br />

resource). But can it affect us in other ways? The answer to that is definitely yes. We’ll go into<br />

the specifics in the sections that follow.<br />

A Common Data Warehousing Technique That Fails<br />

A common data warehousing technique I’ve seen people employ goes like this:<br />

1. They use a trigger to maintain a LAST_UPDATED column in the source table, much like<br />

the method described in the last chapter, in the “Optimistic Locking” section.<br />

2. To initially populate a data warehouse table, they remember what time it is right now<br />

by selecting out SYSDATE on the source system. For example, suppose it is exactly<br />

9:00 am right now.

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

Saved successfully!

Ooh no, something went wrong!