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 451<br />

9 1, 'M',<br />

10 2, 'F' ) gender,<br />

11 ceil(dbms_r<strong>and</strong>om.value(1,50)) location,<br />

12 decode( ceil(dbms_r<strong>and</strong>om.value(1,5)),<br />

13 1,'18 <strong>and</strong> under',<br />

14 2,'19-25',<br />

15 3,'26-30',<br />

16 4,'31-40',<br />

17 5,'41 <strong>and</strong> over'),<br />

18 rpad( '*', 20, '*')<br />

19 from big_table.big_table<br />

20 where rownum create bitmap index gender_idx on t(gender);<br />

Index created.<br />

ops$tkyte@ORA10G> create bitmap index location_idx on t(location);<br />

Index created.<br />

ops$tkyte@ORA10G> create bitmap index age_group_idx on t(age_group);<br />

Index created.<br />

ops$tkyte@ORA10G> exec dbms_stats.gather_table_stats( user, 'T', cascade=>true );<br />

PL/SQL procedure successfully completed.<br />

Now we’ll take a look at the plans for our various ad hoc queries from earlier:<br />

ops$tkyte@ORA10G> Select count(*)<br />

2 from T<br />

3 where gender = 'M'<br />

4 <strong>and</strong> location in ( 1, 10, 30 )<br />

5 <strong>and</strong> age_group = '41 <strong>and</strong> over';<br />

Execution Plan<br />

----------------------------------------------------------<br />

0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=5 Card=1 Bytes=13)<br />

1 0 SORT (AGGREGATE)<br />

2 1 BITMAP CONVERSION (COUNT) (Cost=5 Card=1 Bytes=13)<br />

3 2 BITMAP AND<br />

4 3 BITMAP INDEX (SINGLE VALUE) OF 'GENDER_IDX' (INDEX (BITMAP))<br />

5 3 BITMAP OR<br />

6 5 BITMAP INDEX (SINGLE VALUE) OF 'LOCATION_IDX' (INDEX (BITMAP))<br />

7 5 BITMAP INDEX (SINGLE VALUE) OF 'LOCATION_IDX' (INDEX (BITMAP))<br />

8 5 BITMAP INDEX (SINGLE VALUE) OF 'LOCATION_IDX' (INDEX (BITMAP))<br />

9 3 BITMAP INDEX (SINGLE VALUE) OF 'AGE_GROUP_IDX' (INDEX (BITMAP))

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

Saved successfully!

Ooh no, something went wrong!