Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

rekharaghuram
from rekharaghuram More from this publisher
05.11.2015 Views

CHAPTER 13 ■ PARTITIONING 603 5 select 'p3' pname, empno, job, loc from emp partition(p3) 6 union all 7 select 'p4' pname, empno, job, loc from emp partition(p4) 8 / PN EMPNO JOB LOC -- ---------- --------- ------------- p2 7499 SALESMAN CHICAGO 7698 MANAGER CHICAGO 7654 SALESMAN CHICAGO 7900 CLERK CHICAGO 7844 SALESMAN CHICAGO 7521 SALESMAN CHICAGO p3 7369 CLERK DALLAS 7876 CLERK DALLAS 7902 ANALYST DALLAS 7788 ANALYST DALLAS 7566 MANAGER DALLAS p4 7782 MANAGER NEW YORK 7839 PRESIDENT NEW YORK 7934 CLERK NEW YORK 14 rows selected. This shows the distribution of data, by location, into the individual partitions. We can now review some query plans to see what we could expect performance-wise: ops$tkyte@ORA10G> variable x varchar2(30); ops$tkyte@ORA10G> begin 2 dbms_stats.set_table_stats 3 ( user, 'EMP', numrows=>100000, numblks => 10000 ); 4 end; 5 / PL/SQL procedure successfully completed. ops$tkyte@ORA10G> delete from plan_table; 3 rows deleted. ops$tkyte@ORA10G> explain plan for 2 select empno, job, loc from emp where empno = :x; Explained. ops$tkyte@ORA10G> select * from table(dbms_xplan.display);

604 CHAPTER 13 ■ PARTITIONING PLAN_TABLE_OUTPUT ------------------------------------------------------------------------ | Operation | Name |Rows |Bytes|Pstart|Pstop| ------------------------------------------------------------------------ | SELECT STATEMENT | | 1| 27| | | | TABLE ACCESS BY GLOBAL INDEX ROWID| EMP | 1| 27|ROWID |ROWID| | INDEX UNIQUE SCAN | EMP_PK | 1| | | | ------------------------------------------------------------------------ Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("EMPNO"=TO_NUMBER(:X)) ■Note The explain plan format has been edited to fit on the page. Columns in the report not relevant to the discussion have been omitted. The plan here shows an INDEX UNIQUE SCAN of the nonpartitioned index EMP_PK that was created in support of our primary key. Then there is a TABLE ACCESS BY GLOBAL INDEX ROWID, with a PSTART and PSTOP of ROWID/ROWID, meaning that when we get the ROWID from the index, it will tell us precisely which index partition to read to get this row. This index access will be as effective as on a nonpartitioned table and perform the same amount of I/O to do so. It is just a simple, single index unique scan followed by a “get this row by ROWID.” Now, let’s look at one of the other global indexes, the one on JOB: ops$tkyte@ORA10G> delete from plan_table; 3 rows deleted. ops$tkyte@ORA10G> explain plan for 2 select empno, job, loc from emp where job = :x; Explained. ops$tkyte@ORA10G> select * from table(dbms_xplan.display); PLAN_TABLE_OUTPUT --------------------------------------------------------------------------- | Operation |Name |Rows |Bytes|Pstart|Pstop| --------------------------------------------------------------------------- | SELECT STATEMENT | | 1000|27000| | | | TABLE ACCESS BY GLOBAL INDEX ROWID|EMP | 1000|27000|ROWID |ROWID| | INDEX RANGE SCAN |EMP_JOB_IDX| 400| | | | --------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 2 - access("JOB"=:X)

CHAPTER 13 ■ PARTITIONING 603<br />

5 select 'p3' pname, empno, job, loc from emp partition(p3)<br />

6 union all<br />

7 select 'p4' pname, empno, job, loc from emp partition(p4)<br />

8 /<br />

PN EMPNO JOB LOC<br />

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

p2 7499 SALESMAN CHICAGO<br />

7698 MANAGER CHICAGO<br />

7654 SALESMAN CHICAGO<br />

7900 CLERK CHICAGO<br />

7844 SALESMAN CHICAGO<br />

7521 SALESMAN CHICAGO<br />

p3 7369 CLERK DALLAS<br />

7876 CLERK DALLAS<br />

7902 ANALYST DALLAS<br />

7788 ANALYST DALLAS<br />

7566 MANAGER DALLAS<br />

p4 7782 MANAGER NEW YORK<br />

7839 PRESIDENT NEW YORK<br />

7934 CLERK NEW YORK<br />

14 rows selected.<br />

This shows the distribution of data, by location, into the individual partitions. We can now<br />

review some query plans to see what we could expect performance-wise:<br />

ops$tkyte@ORA10G> variable x varchar2(30);<br />

ops$tkyte@ORA10G> begin<br />

2 dbms_stats.set_table_stats<br />

3 ( user, 'EMP', numrows=>100000, numblks => 10000 );<br />

4 end;<br />

5 /<br />

PL/SQL procedure successfully completed.<br />

ops$tkyte@ORA10G> delete from plan_table;<br />

3 rows deleted.<br />

ops$tkyte@ORA10G> explain plan for<br />

2 select empno, job, loc from emp where empno = :x;<br />

Explained.<br />

ops$tkyte@ORA10G> select * from table(dbms_xplan.display);

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

Saved successfully!

Ooh no, something went wrong!