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

SELECT /*+ INDEX( t t_idx_1 ) */ COUNT(*) FROM T<br />

WHERE OBJECT_NAME = :B3 AND OBJECT_TYPE = :B2 AND OWNER = :B1<br />

call count cpu elapsed disk query current rows<br />

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

Parse 1 0.00 0.00 0 0 0 0<br />

Execute 48243 10.63 10.78 0 0 0 0<br />

Fetch 48243 1.90 1.77 0 145133 0 48243<br />

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

total 96487 12.53 12.55 0 145133 0 48243<br />

Rows Row Source Operation<br />

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

48243 SORT AGGREGATE (cr=145133 pr=0 pw=0 time=2334197 us)<br />

57879 INDEX RANGE SCAN T_IDX_1 (cr=145133 pr=0 pw=0 time=1440672 us)(object...<br />

********************************************************************************<br />

SELECT /*+ INDEX( t t_idx_2 ) */ COUNT(*) FROM T<br />

WHERE OBJECT_NAME = :B3 AND OBJECT_TYPE = :B2 AND OWNER = :B1<br />

call count cpu elapsed disk query current rows<br />

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

Parse 1 0.00 0.00 0 0 0 0<br />

Execute 48243 11.00 10.78 0 0 0 0<br />

Fetch 48243 1.87 2.10 0 145168 0 48243<br />

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

total 96487 12.87 12.88 0 145168 0 48243<br />

Rows Row Source Operation<br />

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

48243 SORT AGGREGATE (cr=145168 pr=0 pw=0 time=2251857 us)<br />

57879 INDEX RANGE SCAN T_IDX_2 (cr=145168 pr=0 pw=0 time=1382547 us)(object...<br />

They processed the same exact number of rows <strong>and</strong> very similar numbers of blocks<br />

(minor variations coming from accidental ordering of rows in the table <strong>and</strong> consequential<br />

optimizations made by <strong>Oracle</strong>), used equivalent amounts of CPU time, <strong>and</strong> ran in about the<br />

same elapsed time (run this same test again <strong>and</strong> the CPU <strong>and</strong> ELAPSED numbers will be a little<br />

different, but on average they will be the same). There are no inherent efficiencies to be gained<br />

by placing the columns in order of how discriminating they are, <strong>and</strong> as stated previously, with<br />

index key compression there is an argument for putting the least selective first. If you run the<br />

preceding example with COMPRESS 2 on the indexes, you’ll find that the first index will perform<br />

about two-thirds the I/O of the second, given the nature of the query in this case.<br />

However, the fact is that the decision to put column C1 before C2 must be driven by how<br />

the index is used. If you have lots of queries like the following:<br />

select * from t where c1 = :x <strong>and</strong> c2 = :y;<br />

select * from t where c2 = :y;

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

Saved successfully!

Ooh no, something went wrong!