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.

462<br />

CHAPTER 11 ■ INDEXES<br />

Fetch 0 0.00 0.00 0 0 0 0<br />

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

total 2 0.49 0.50 0 15439 948 9999<br />

But with the index, it takes about 1.2 seconds:<br />

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

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

Parse 1 0.03 0.04 0 0 0 0<br />

Execute 1 1.14 1.12 2 15650 7432 9999<br />

Fetch 0 0.00 0.00 0 0 0 0<br />

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

total 2 1.17 1.16 2 15650 7432 9999<br />

This was the overhead introduced in the management of the new index on the MY_SOUNDEX<br />

function—both in the performance overhead of simply having an index (any type of index will<br />

affect insert performance) <strong>and</strong> the fact that this index had to call a stored procedure 9,999 times.<br />

Now, to test the query, we’ll just rerun the query:<br />

ops$tkyte@ORA10G> REM reset our counter<br />

ops$tkyte@ORA10G> exec stats.cnt := 0<br />

PL/SQL procedure successfully completed.<br />

ops$tkyte@ORA10G> set timing on<br />

ops$tkyte@ORA10G> set autotrace on explain<br />

ops$tkyte@ORA10G> select ename, hiredate<br />

2 from emp<br />

3 where substr(my_soundex(ename),1,6) = my_soundex('Kings')<br />

4 /<br />

ENAME HIREDATE<br />

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

Ku$_Chunk_ 10-AUG-04<br />

Ku$_Chunk_ 10-AUG-04<br />

Elapsed: 00:00:00.02<br />

Execution Plan<br />

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

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

1 0 TABLE ACCESS (BY INDEX ROWID) OF 'EMP' (TABLE) (Cost=2 Card=1 Bytes=16)<br />

2 1 INDEX (RANGE SCAN) OF 'EMP_SOUNDEX_IDX' (INDEX) (Cost=1 Card=35)<br />

ops$tkyte@ORA10G> set autotrace off<br />

ops$tkyte@ORA10G> set timing off<br />

ops$tkyte@ORA10G> set serveroutput on<br />

ops$tkyte@ORA10G> exec dbms_output.put_line( stats.cnt );<br />

2<br />

PL/SQL procedure successfully completed.

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

Saved successfully!

Ooh no, something went wrong!