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.

CHAPTER 9 ■ REDO AND UNDO 323<br />

Investigating Undo<br />

We’ve already discussed a lot of undo segment topics. We’ve seen how they are used during<br />

recovery, how they interact with the redo logs, <strong>and</strong> how they are used for consistent, nonblocking<br />

reads of data. In this section, we’ll look at the most frequently raised issues with<br />

undo segments.<br />

The bulk of our time will be spent on the infamous ORA-01555: snapshot too old error, as<br />

this single issue causes more confusion than any other topic in the entire set of database topics.<br />

Before we do this, however, we’ll investigate one other undo-related issue in the next<br />

section: the question of what type of DML operation generates the most <strong>and</strong> least undo (you<br />

might already be able to answer that yourself, given the preceding examples with temporary<br />

tables).<br />

What Generates the Most <strong>and</strong> Least Undo?<br />

This is a frequently asked but easily answered question. The presence of indexes (or the fact<br />

that a table is an index-organized table) may affect the amount of undo generated dramatically,<br />

as indexes are complex data structures <strong>and</strong> may generate copious amounts of undo<br />

information.<br />

That said, an INSERT will, in general, generate the least amount of undo, since all <strong>Oracle</strong><br />

needs to record for this is a rowid to “delete.” An UPDATE is typically second in the race (in most<br />

cases). All that needs to be recorded are the changed bytes. It is most common that you UPDATE<br />

some small fraction of the entire row’s data. Therefore, a small fraction of the row must be<br />

remembered in the undo. Many of the previous examples run counter to this rule of thumb,<br />

but that is because they update large, fixed-sized rows, <strong>and</strong> they update the entire row. It is<br />

much more common to UPDATE a row <strong>and</strong> change a small percentage of the total row. A DELETE<br />

will, in general, generate the most undo. For a DELETE, <strong>Oracle</strong> must record the entire row’s<br />

before image into the undo segment. The previous temporary table example, with regard to<br />

redo generation, demonstrated that fact: the DELETE generated the most redo, <strong>and</strong> since the<br />

only logged element of the DML operation on a temporary table is the undo, we in fact<br />

observed that the DELETE generated the most undo. The INSERT generated very little undo that<br />

needed to be logged. The UPDATE generated an amount equal to the before image of the data<br />

that was changed, <strong>and</strong> the DELETE generated the entire set of data written into the undo<br />

segment.<br />

As previously mentioned, you must also take into consideration the work performed on<br />

an index. You will find that an update of an unindexed column not only executes much faster,<br />

but will tend to generate significantly less undo than an update of an indexed column. For<br />

example, we’ll create a table with two columns both containing the same information <strong>and</strong><br />

index one of them:<br />

ops$tkyte@ORA10G> create table t<br />

2 as<br />

3 select object_name unindexed,<br />

4 object_name indexed<br />

5 from all_objects<br />

6 /<br />

Table created.

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

Saved successfully!

Ooh no, something went wrong!