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 11 ■ INDEXES 455<br />

Bitmap join indexes do have a prerequisite. The join condition must join to a primary or<br />

unique key in the other table. In the preceding example, DEPT.DEPTNO is the primary key of the<br />

DEPT table, <strong>and</strong> the primary key must be in place, otherwise an error will occur:<br />

ops$tkyte@ORA10G> create bitmap index emp_bm_idx<br />

2 on emp( d.dname )<br />

3 from emp e, dept d<br />

4 where e.deptno = d.deptno<br />

5 /<br />

from emp e, dept d<br />

*<br />

ERROR at line 3:<br />

ORA-25954: missing primary key or unique constraint on dimension<br />

Bitmap Indexes Wrap-Up<br />

When in doubt, try it out. It is trivial to add a bitmap index to a table (or a bunch of them) <strong>and</strong><br />

see what it does for you. Also, you can usually create bitmap indexes much faster than B*Tree<br />

indexes. Experimentation is the best way to see if they are suited for your environment. I am<br />

frequently asked, “What defines low cardinality?” There is no cut-<strong>and</strong>-dried answer for this.<br />

Sometimes it is 3 values out of 100,000. Sometimes it is 10,000 values out of 1,000,000. Low<br />

cardinality doesn’t imply single-digit counts of distinct values. Experimentation is the way to<br />

discover if a bitmap is a good idea for your application. In general, if you have a large, mostly<br />

read-only environment with lots of ad hoc queries, a set of bitmap indexes may be exactly<br />

what you need.<br />

Function-Based Indexes<br />

Function-based indexes were added to <strong>Oracle</strong> 8.1.5. They are now a feature of St<strong>and</strong>ard Edition,<br />

whereas in releases prior to <strong>Oracle</strong>9i Release 2 they were a feature of Enterprise Edition.<br />

Function-based indexes give us the ability to index computed columns <strong>and</strong> use these<br />

indexes in a query. In a nutshell, this capability allows you to have case-insensitive searches or<br />

sorts, search on complex equations, <strong>and</strong> extend the SQL language efficiently by implementing<br />

your own functions <strong>and</strong> operators <strong>and</strong> then searching on them.<br />

There are many reasons why you would want to use a function-based index, with the following<br />

chief among them:<br />

• They are easy to implement <strong>and</strong> provide immediate value.<br />

• They can be used to speed up existing applications without changing any of their logic<br />

or queries.<br />

Important Implementation Details<br />

Unlike B*Tree <strong>and</strong> bitmap indexes, in <strong>Oracle</strong>9i Release 1 function-based indexes require some<br />

initial setup before we can create <strong>and</strong> then use them.

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

Saved successfully!

Ooh no, something went wrong!