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.

CHAPTER 11 ■ INDEXES 423<br />

value of Y. That is not to say that a bitmap index on a column with 1,000 distinct values<br />

in that same table would not be valid—it certainly can be. Bitmap indexes should never<br />

be considered in an OLTP database for concurrency-related issues (which we’ll discuss<br />

in due course). Note that bitmap indexes require the Enterprise or Personal Edition of<br />

<strong>Oracle</strong>.<br />

• Bitmap join indexes: These provide a means of denormalizing data in an index structure,<br />

instead of in a table. For example, consider the simple EMP <strong>and</strong> DEPT tables. Someone<br />

might ask the question, “How many people work in departments located in the city of<br />

Boston?” EMP has a foreign key to DEPT, <strong>and</strong> in order to count the employees in departments<br />

with a LOC value of Boston, we would normally have to join the tables to get the<br />

LOC column joined to the EMP records to answer this question. Using a bitmap join<br />

index, we can instead index the LOC column against the EMP table.<br />

• Function-based indexes: These are B*Tree or bitmap indexes that store the computed<br />

result of a function on a row’s column(s), not the column data itself. You can consider<br />

them an index on a virtual (or derived) column—in other words, a column that is not<br />

physically stored in the table. These may be used to speed up queries of the form<br />

SELECT * FROM T WHERE FUNCTION(DATABASE_COLUMN) = SOME_VALUE, since the value<br />

FUNCTION(DATABASE_COLUMN) has already been computed <strong>and</strong> stored in the index.<br />

• Application domain indexes: These are indexes you build <strong>and</strong> store yourself, either in<br />

<strong>Oracle</strong> or perhaps even outside of <strong>Oracle</strong>. You tell the optimizer how selective your<br />

index is <strong>and</strong> how costly it is to execute, <strong>and</strong> the optimizer will decide whether or not to<br />

use your index based on that information. The <strong>Oracle</strong> text index is an example of an<br />

application domain index; it is built using the same tools you may use to build your<br />

own index. It should be noted that the “index” created here need not use a traditional<br />

index structure. The <strong>Oracle</strong> text index, for example, uses a set of tables to implement its<br />

concept of an index.<br />

As you can see, there are many index types to choose from. In the following sections, I’ll<br />

present some technical details on how each one works <strong>and</strong> when it should be used. I would<br />

like to stress again that we will not cover certain DBA-related topics. For example, we will<br />

not discuss the mechanics of an online rebuild; rather, we will concentrate on practical<br />

application-related details.<br />

B*Tree Indexes<br />

B*Tree—or what I call “conventional”—indexes are the most commonly used type of indexing<br />

structure in the database. They are similar in implementation to a binary search tree. Their<br />

goal is to minimize the amount of time <strong>Oracle</strong> spends searching for data. Loosely speaking,<br />

if you have an index on a number column, then the structure might conceptually look like<br />

Figure 11-1.<br />

■Note There are block-level optimizations <strong>and</strong> compression of data that take place that make the real<br />

block structure look different from Figure 11-1.

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

Saved successfully!

Ooh no, something went wrong!