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 10 ■ DATABASE TABLES 369<br />

In this situation, regardless of the size of the data stored in it, Z will be stored “out of line”<br />

in the overflow segment.<br />

Which is better, then: PCTTHRESHOLD, INCLUDING, or some combination of both? It depends<br />

on your needs. If you have an application that always, or almost always, uses the first four<br />

columns of a table <strong>and</strong> rarely accesses the last five columns, using INCLUDING would be appropriate.<br />

You would include up to the fourth column <strong>and</strong> let the other five be stored out of line. At<br />

runtime, if you need them, the columns will be retrieved in much the same way as a migrated<br />

or chained row would be. <strong>Oracle</strong> will read the “head” of the row, find the pointer to the rest of<br />

the row, <strong>and</strong> then read that. If, on the other h<strong>and</strong>, you cannot say that you almost always access<br />

these columns <strong>and</strong> hardly ever access those columns, you should give some consideration to<br />

PCTTHRESHOLD. Setting PCTTHRESHOLD is easy once you determine the number of rows you would<br />

like to store per index block on average. Suppose you wanted 20 rows per index block. Well, that<br />

means each row should be one-twentieth (5 percent). Your PCTTHRESHOLD would be 5, <strong>and</strong> each<br />

chunk of the row that stays on the index leaf block should consume no more than 5 percent of<br />

the block.<br />

The last thing to consider with IOTs is indexing. You can have an index on an IOT itself—<br />

sort of like having an index on an index. These are called secondary indexes. Normally, an index<br />

contains the physical address of the row it points to, the rowid. An IOT secondary index cannot<br />

do this; it must use some other way to address the row. This is because a row in an IOT can<br />

move around a lot, <strong>and</strong> it does not “migrate” in the way a row in a heap organized table would.<br />

A row in an IOT is expected to be at some position in the index structure, based on its primary<br />

key value; it will only be moving because the size <strong>and</strong> shape of the index itself is changing.<br />

(We’ll cover more about how index structures are maintained in the next chapter.) To accommodate<br />

this, <strong>Oracle</strong> introduced a logical rowid. These logical rowids are based on the IOT’s<br />

primary key. They may also contain a “guess” as to the current location of the row, although<br />

this guess is almost always wrong because after a short while, data in an IOT tends to move.<br />

The guess is the physical address of the row in the IOT when it was first placed into the secondary<br />

index structure. If the row in the IOT has to move to another block, the guess in the<br />

secondary index becomes “stale.” Therefore, an index on an IOT is slightly less efficient than<br />

an index on a regular table. On a regular table, an index access typically requires the I/O to<br />

scan the index structure <strong>and</strong> then a single read to read the table data. With an IOT, typically<br />

two scans are performed: one on the secondary structure <strong>and</strong> the other on the IOT itself. That<br />

aside, indexes on IOTs provide fast <strong>and</strong> efficient access to the data in the IOT using columns<br />

other than the primary key.<br />

Index Organized Tables Wrap-Up<br />

Getting the right mix of data on the index block versus data in the overflow segment is the most<br />

critical part of the IOT setup. Benchmark various scenarios with different overflow conditions,<br />

<strong>and</strong> see how they will affect your INSERTs, UPDATEs, DELETEs, <strong>and</strong> SELECTs. If you have a structure<br />

that is built once <strong>and</strong> read frequently, stuff as much of the data onto the index block as<br />

you can. If you frequently modify the structure, you will have to achieve some balance between<br />

having all of the data on the index block (great for retrieval) versus reorganizing data in the<br />

index frequently (bad for modifications). The freelist consideration you had for heap tables<br />

applies to IOTs as well. PCTFREE <strong>and</strong> PCTUSED play two roles in an IOT. PCTFREE is not nearly<br />

as important for an IOT as for a heap table, <strong>and</strong> PCTUSED doesn’t come into play normally.

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

Saved successfully!

Ooh no, something went wrong!