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 595 Now we’re ready to update the “live” data using an exchange partition: ops$tkyte@ORA10G> alter table partitioned 2 exchange partition fy_2004 3 with table fy_2004 4 including indexes 5 without validation 6 / Table altered. ops$tkyte@ORA10G> alter table partitioned 2 drop partition fy_2004 3 / Table altered. This is all we need to do to “age” the old data out. We turned the partition into a full table and the empty table into a partition. This was a simple data dictionary update. No large amount of I/O took place—it just happened. We can now export that FY_2004 table (perhaps using a transportable tablespace) out of our database for archival purposes. We could reattach it quickly if we ever needed to. Next, we want to slide in the new data: ops$tkyte@ORA10G> alter table partitioned 2 add partition fy_2006 3 values less than ( to_date('01-jan-2007','dd-mon-yyyy') ) 4 / Table altered. ops$tkyte@ORA10G> alter table partitioned 2 exchange partition fy_2006 3 with table fy_2006 4 including indexes 5 without validation 6 / Table altered. Again, this was instantaneous; it was accomplished via simple data dictionary updates. Adding the empty partition took very little time to process. Then, we exchange the newly created empty partition with the full table, and the full table with the empty partition, and that operation is performed quickly as well. The new data is online. Looking at our indexes, however, we’ll find the following: ops$tkyte@ORA10G> select index_name, status from user_indexes; INDEX_NAME STATUS ------------------------------ -------- FY_2006_IDX VALID FY_2004_IDX VALID PARTITIONED_IDX_GLOBAL UNUSABLE

596 CHAPTER 13 ■ PARTITIONING The global index is, of course, unusable after this operation. Since each index partition can point to any table partition, and we just took away a partition and added a partition, that index is invalid. It has entries that point into the partition we dropped. It has no entries that point into the partition we just added. Any query that would make use of this index either will fail and not execute or, if we skip unusable indexes, the query’s performance will be negatively impacted by not being able to use the index: ops$tkyte@ORA10G> set autotrace on explain ops$tkyte@ORA10G> select /*+ index( partitioned PARTITIONED_IDX_GLOBAL ) */ count(*) 2 from partitioned 3 where timestamp between sysdate-50 and sysdate; select /*+ index( partitioned PARTITIONED_IDX_GLOBAL ) */ count(*) * ERROR at line 1: ORA-01502: index 'OPS$TKYTE.PARTITIONED_IDX_GLOBAL' or partition of such index is in unusable state ops$tkyte@ORA10G> select count(*) 2 from partitioned 3 where timestamp between sysdate-50 and sysdate; COUNT(*) ---------- 6750 Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=59 Card=1 Bytes=9) 1 0 SORT (AGGREGATE) 2 1 FILTER 3 2 PARTITION RANGE (ITERATOR) (Cost=59 Card=7234 Bytes=65106) 4 3 TABLE ACCESS (FULL) OF 'PARTITIONED' (TABLE) (Cost=59 Card=7234 ops$tkyte@ORA10G> set autotrace off So, our choices after performing this partition operation with global indexes are • Skip the index, either transparently as Oracle 10g is doing in this example or by setting the session parameter SKIP_UNUSABLE_INDEXES=TRUE in 9i (Oracle 10g defaults this setting to TRUE). But then we lose the performance the index was giving us. • Have the query receive an error, as it would in 9i unless SKIP_UNUSABLE_INDEXES were set to FALSE, and as would any query in 10g that explicitly requests to use a hint. We need to rebuild this index to make the data truly usable again. The sliding window process, which so far has resulted in virtually no downtime, will now take a very long time to complete while we rebuild the global index. Runtime query performance of queries that relied on these indexes will be negatively affected during this time—either

CHAPTER 13 ■ PARTITIONING 595<br />

Now we’re ready to update the “live” data using an exchange partition:<br />

ops$tkyte@ORA10G> alter table partitioned<br />

2 exchange partition fy_2004<br />

3 with table fy_2004<br />

4 including indexes<br />

5 without validation<br />

6 /<br />

Table altered.<br />

ops$tkyte@ORA10G> alter table partitioned<br />

2 drop partition fy_2004<br />

3 /<br />

Table altered.<br />

This is all we need to do to “age” the old data out. We turned the partition into a full<br />

table <strong>and</strong> the empty table into a partition. This was a simple data dictionary update. No large<br />

amount of I/O took place—it just happened. We can now export that FY_2004 table (perhaps<br />

using a transportable tablespace) out of our database for archival purposes. We could reattach<br />

it quickly if we ever needed to.<br />

Next, we want to slide in the new data:<br />

ops$tkyte@ORA10G> alter table partitioned<br />

2 add partition fy_2006<br />

3 values less than ( to_date('01-jan-2007','dd-mon-yyyy') )<br />

4 /<br />

Table altered.<br />

ops$tkyte@ORA10G> alter table partitioned<br />

2 exchange partition fy_2006<br />

3 with table fy_2006<br />

4 including indexes<br />

5 without validation<br />

6 /<br />

Table altered.<br />

Again, this was instantaneous; it was accomplished via simple data dictionary updates.<br />

Adding the empty partition took very little time to process. Then, we exchange the newly created<br />

empty partition with the full table, <strong>and</strong> the full table with the empty partition, <strong>and</strong> that<br />

operation is performed quickly as well. The new data is online.<br />

Looking at our indexes, however, we’ll find the following:<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 UNUSABLE

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

Saved successfully!

Ooh no, something went wrong!