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.

448<br />

CHAPTER 11 ■ INDEXES<br />

laid out. If you can use the index to “answer the question,” then accessing a large percentage<br />

of the rows makes sense, since you are avoiding the extra scattered I/O to read the table. If you<br />

use the index to access the table, then you will need to ensure that you are processing a small<br />

percentage of the total table.<br />

You should consider the design <strong>and</strong> implementation of indexes during the design of your<br />

application, not as an afterthought (as I so often see). With careful planning <strong>and</strong> due consideration<br />

of how you are going to access the data, the indexes you need will be apparent in most<br />

all cases.<br />

Bitmap Indexes<br />

Bitmap indexes were added to <strong>Oracle</strong> in version 7.3 of the database. They are currently available<br />

with the <strong>Oracle</strong> Enterprise <strong>and</strong> Personal Editions, but not the St<strong>and</strong>ard Edition. Bitmap<br />

indexes are designed for data warehousing/ad hoc query environments where the full set of<br />

queries that may be asked of the data is not totally known at system implementation time.<br />

They are specifically not designed for OLTP systems or systems where data is frequently<br />

updated by many concurrent sessions.<br />

Bitmap indexes are structures that store pointers to many rows with a single index key<br />

entry, as compared to a B*Tree structure where there is parity between the index keys <strong>and</strong> the<br />

rows in a table. In a bitmap index, there will be a very small number of index entries, each of<br />

which points to many rows. In a conventional B*Tree, one index entry points to a single row.<br />

Let’s say we are creating a bitmap index on the JOB column in the EMP table as follows:<br />

Ops$tkyte@ORA10G> create BITMAP index job_idx on emp(job);<br />

Index created.<br />

<strong>Oracle</strong> will store something like what is shown in Table 11-6 in the index.<br />

Table 11-6. Representation of How <strong>Oracle</strong> Would Store the JOB-IDX Bitmap Index<br />

Value/Row 1 2 3 4 5 6 7 8 9 10 11 12 13 14<br />

ANALYST 0 0 0 0 0 0 0 1 0 1 0 0 1 0<br />

CLERK 1 0 0 0 0 0 0 0 0 0 1 1 0 1<br />

MANAGER 0 0 0 1 0 1 1 0 0 0 0 0 0 0<br />

PRESIDENT 0 0 0 0 0 0 0 0 1 0 0 0 0 0<br />

SALESMAN 0 1 1 0 1 0 0 0 0 0 0 0 0 0<br />

Table 11-6 shows that rows 8, 10, <strong>and</strong> 13 have the value ANALYST, whereas rows 4, 6, <strong>and</strong> 7<br />

have the value MANAGER. It also shows us that no rows are null (bitmap indexes store null<br />

entries; the lack of a null entry in the index implies there are no null rows). If we wanted to<br />

count the rows that have the value MANAGER, the bitmap index would do this very rapidly. If we<br />

wanted to find all the rows such that the JOB was CLERK or MANAGER, we could simply combine<br />

their bitmaps from the index, as shown in Table 11-7.

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

Saved successfully!

Ooh no, something went wrong!