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.

488<br />

CHAPTER 11 ■ INDEXES<br />

it makes more sense to place the index on T(C2,C1). This single index could be used by either<br />

of the queries. Additionally, using index key compression (which we looked at with regard to<br />

IOTs <strong>and</strong> will examine further later), we can build a smaller index if C2 is first. This is because<br />

each value of C2 repeats itself on average four times in the index. If C1 <strong>and</strong> C2 are both, on average,<br />

10 bytes in length, the index entries for this index would nominally be 2,000,000 bytes<br />

(100,000 ✕ 20). Using index key compression on (C2, C1), we could shrink this index to<br />

1,250,000 (100,000 ✕ 12.5), since three out of four repetitions of C2 could be suppressed.<br />

In <strong>Oracle</strong> 5 (yes, version 5!), there was an argument for placing the most selective columns<br />

first in an index. It had to do with the way version 5 implemented index compression (not the<br />

same as index key compression). This feature was removed in version 6 with the addition of<br />

row-level locking. Since then, it is not true that putting the most discriminating entries first in<br />

the index will make the index smaller or more efficient. It seems like it will, but it will not. With<br />

index key compression, there is a compelling argument to go the other way since it can make<br />

the index smaller. However, it should be driven by how you use the index, as previously stated.<br />

Summary<br />

In this chapter, we covered the different types of indexes <strong>Oracle</strong> has to offer. We started with<br />

the basic B*Tree index <strong>and</strong> looked at various subtypes of this index, such as the reverse key<br />

index (designed for <strong>Oracle</strong> RAC) <strong>and</strong> descending indexes for retrieving data sorted in a mix<br />

of descending <strong>and</strong> ascending order. We spent some time looking at when you should use an<br />

index <strong>and</strong> why an index may not be useful in various circumstances.<br />

We then looked at bitmap indexes, an excellent method for indexing low to medium cardinality<br />

data in a data warehouse (read-intensive, non-OLTP) environment. We covered the<br />

times it would be appropriate to use a bitmapped index <strong>and</strong> why you would never consider<br />

one for use in an OLTP environment—or any environment where multiple users must concurrently<br />

update the same column.<br />

We moved on to cover function-based indexes, which are actually special cases of B*Tree<br />

<strong>and</strong> bitmapped indexes. A function-based index allows us to create an index on a function of a<br />

column (or columns), which means that we can precompute <strong>and</strong> store the results of complex<br />

calculations <strong>and</strong> user-written functions for blazing-fast index retrieval later. We looked at<br />

some important implementation details surrounding function-based indexes, such as the<br />

necessary system- <strong>and</strong> session-level settings that must be in place for them to be used. We followed<br />

that with examples of function-based indexes both on built-in <strong>Oracle</strong> functions <strong>and</strong><br />

user-written ones. Lastly, we looked at a few caveats with regard to function-based indexes.<br />

We then examined a very specialized index type called the application domain index.<br />

Rather than go into how to build one of those from scratch (which involves a long, complex<br />

sequence of events), we looked at an example that had already been implemented: the text<br />

index.<br />

We closed with some of the most frequently asked questions on indexes that I receive as<br />

well as some myths about indexes. This section covered topics ranging from the simple question<br />

“Do indexes work with views?” to the more complex <strong>and</strong> sublime myth “Space is never<br />

reused in an index.” We answered these questions <strong>and</strong> debunked the myths mostly through<br />

example, demonstrating the concepts as we went along.

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

Saved successfully!

Ooh no, something went wrong!