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.

598<br />

CHAPTER 13 ■ PARTITIONING<br />

5 without validation<br />

6 UPDATE GLOBAL INDEXES<br />

7 /<br />

Table altered.<br />

then we would have discovered the indexes to be perfectly valid <strong>and</strong> usable both during <strong>and</strong><br />

after the operation:<br />

ops$tkyte@ORA10G> select index_name, status from user_indexes;<br />

INDEX_NAME<br />

STATUS<br />

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

FY_2006_IDX<br />

VALID<br />

FY_2004_IDX<br />

VALID<br />

PARTITIONED_IDX_GLOBAL VALID<br />

PARTITIONED_IDX_LOCAL<br />

N/A<br />

6 rows selected.<br />

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

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

2 from partitioned<br />

3 where timestamp between sysdate-50 <strong>and</strong> sysdate;<br />

COUNT(*)<br />

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

6750<br />

Execution Plan<br />

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

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

1 0 SORT (AGGREGATE)<br />

2 1 FILTER<br />

3 2 INDEX (RANGE SCAN) OF 'PARTITIONED_IDX_GLOBAL' (INDEX) (Cost=9...<br />

But there is a tradeoff: we are performing the logical equivalent of INSERT <strong>and</strong> DELETE<br />

operations on the global index structures. When we drop a partition, we have to delete all of<br />

the global index entries that might be pointing to that partition. When we did the exchange of<br />

a table with a partition, we had to delete all of the global index entries pointing to the original<br />

data <strong>and</strong> then insert all of the new ones that we just slid in there. So the amount of work performed<br />

by the ALTER comm<strong>and</strong>s was significantly increased.<br />

In fact, using runstats <strong>and</strong> a slightly modified version of the preceding example, we can<br />

measure the amount of “extra” work performed to maintain the global indexes during the partition<br />

operation. We’ll slide out FY_2004 <strong>and</strong> slide in FY_2006 as before, adding in the requisite<br />

index rebuild. This will be the sliding window implementation that causes the data to become<br />

unavailable due to the need to rebuild the global indexes. We’ll also then slide out FY_2005<br />

<strong>and</strong> slide in FY_2007 using the UPDATE GLOBAL INDEXES clause, to emulate the sliding window

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

Saved successfully!

Ooh no, something went wrong!