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 13 ■ PARTITIONING 585<br />

ops$tkyte@ORA10G> create index local_prefixed on partitioned_table (a,b) local;<br />

Index created.<br />

ops$tkyte@ORA10G> create index local_nonprefixed on partitioned_table (b) local;<br />

Index created.<br />

Next, we’ll insert some data into one partition <strong>and</strong> gather statistics:<br />

ops$tkyte@ORA10G> insert into partitioned_table<br />

2 select mod(rownum-1,2)+1, rownum, 'x'<br />

3 from all_objects;<br />

48967 rows created.<br />

ops$tkyte@ORA10G> begin<br />

2 dbms_stats.gather_table_stats<br />

3 ( user,<br />

4 'PARTITIONED_TABLE',<br />

5 cascade=>TRUE );<br />

6 end;<br />

7 /<br />

PL/SQL procedure successfully completed.<br />

We take offline tablespace P2, which contains the PART_2 partition for both the tables <strong>and</strong><br />

indexes:<br />

ops$tkyte@ORA10G> alter tablespace p2 offline;<br />

Tablespace altered.<br />

Taking tablespace P2 offline will prevent <strong>Oracle</strong> from accessing those specific index partitions.<br />

It will be as if we had suffered “media failure,” causing them to become unavailable.<br />

Now we’ll query the table to see what index partitions are needed by different queries. This<br />

first query is written to permit the use of the local prefixed index:<br />

ops$tkyte@ORA10G> select * from partitioned_table where a = 1 <strong>and</strong> b = 1;<br />

A<br />

B DATA<br />

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

1 1 x<br />

That query succeeded, <strong>and</strong> we can see why by reviewing the explain plan. We’ll use the<br />

built-in package DBMS_XPLAN to see what partitions this query accesses. The PSTART (partition<br />

start) <strong>and</strong> PSTOP (partition stop) columns in the output show us exactly what partitions this<br />

query needs to have online <strong>and</strong> available in order to succeed:<br />

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

4 rows deleted.<br />

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

2 select * from partitioned_table where a = 1 <strong>and</strong> b = 1;<br />

Explained.

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

Saved successfully!

Ooh no, something went wrong!