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 593 • Attaching the new data: Once the new data is loaded and processed, the table it is in is exchanged with an empty partition in the partitioned table, turning this newly loaded data in a table into a partition of the larger partitioned table. This process is repeated every month, or however often the load process is performed; it could be every day or every week. We will implement this very typical process in this section to show the impact of global partitioned indexes and demonstrate the options we have during partition operations to increase availability, allowing us to implement a sliding window of data and maintain continuous availability of data. We’ll process yearly data in this example and have fiscal years 2004 and 2005 loaded up. The table will be partitioned by the TIMESTAMP column, and it will have two indexes created on it—one is a locally partitioned index on the ID column, and the other is a global index (nonpartitioned, in this case) on the TIMESTAMP column: ops$tkyte@ORA10G> CREATE TABLE partitioned 2 ( timestamp date, 3 id int 4 ) 5 PARTITION BY RANGE (timestamp) 6 ( 7 PARTITION fy_2004 VALUES LESS THAN 8 ( to_date('01-jan-2005','dd-mon-yyyy') ) , 9 PARTITION fy_2005 VALUES LESS THAN 10 ( to_date('01-jan-2006','dd-mon-yyyy') ) 11 ) 12 / Table created. ops$tkyte@ORA10G> insert into partitioned partition(fy_2004) 2 select to_date('31-dec-2004',’dd-mon-yyyy’)-mod(rownum,360), object_id 3 from all_objects 4 / 48514 rows created. ops$tkyte@ORA10G> insert into partitioned partition(fy_2005) 2 select to_date('31-dec-2005',’dd-mon-yyyy’)-mod(rownum,360), object_id 3 from all_objects 4 / 48514 rows created. ops$tkyte@ORA10G> create index partitioned_idx_local 2 on partitioned(id) 3 LOCAL 4 / Index created.

594 CHAPTER 13 ■ PARTITIONING ops$tkyte@ORA10G> create index partitioned_idx_global 2 on partitioned(timestamp) 3 GLOBAL 4 / Index created. This sets up our “warehouse” table. The data is partitioned by fiscal year and we have the last two years’ worth of data online. This table has two indexes: one is LOCAL and the other is GLOBAL. Now it is the end of the year and we would like to do the following: 1. Remove the oldest fiscal year data. We do not want to lose this data forever; we just want to age it out and archive it. 2. Add the newest fiscal year data. It will take a while to load it, transform it, index it, and so on. We would like to do this work without impacting the availability of the current data, if at all possible. The first step we might take would be to set up an empty table for fiscal year 2004 that looks just like the partitioned table. We’ll use this table to exchange with the FY_2004 partition in the partitioned table, turning that partition into a table and in turn emptying out the partition in the partitioned table. The net effect is that the oldest data in the partitioned table will have been, in effect, removed after the exchange: ops$tkyte@ORA10G> create table fy_2004 ( timestamp date, id int ); Table created. ops$tkyte@ORA10G> create index fy_2004_idx on fy_2004(id) 2 / Index created. We’ll do the same to the new data to be loaded. We’ll create and load a table that structurally looks like the existing partitioned table (but that is not itself partitioned): ops$tkyte@ORA10G> create table fy_2006 ( timestamp date, id int ); Table created. ops$tkyte@ORA10G> insert into fy_2006 2 select to_date('31-dec-2006',’dd-mon-yyyy’)-mod(rownum,360), object_id 3 from all_objects 4 / 48521 rows created. ops$tkyte@ORA10G> create index fy_2006_idx on fy_2006(id) nologging 2 / Index created. We’ll turn the current full partition into an empty partition and create a “full” table, with the FY_2004 data in it. Also, we’ve completed all of the work necessary to have the FY_2006 data ready to go. This would have involved verifying the data, transforming it—whatever complex tasks we need to undertake to get it ready.

594<br />

CHAPTER 13 ■ PARTITIONING<br />

ops$tkyte@ORA10G> create index partitioned_idx_global<br />

2 on partitioned(timestamp)<br />

3 GLOBAL<br />

4 /<br />

Index created.<br />

This sets up our “warehouse” table. The data is partitioned by fiscal year <strong>and</strong> we have the<br />

last two years’ worth of data online. This table has two indexes: one is LOCAL <strong>and</strong> the other is<br />

GLOBAL. Now it is the end of the year <strong>and</strong> we would like to do the following:<br />

1. Remove the oldest fiscal year data. We do not want to lose this data forever; we just<br />

want to age it out <strong>and</strong> archive it.<br />

2. Add the newest fiscal year data. It will take a while to load it, transform it, index it, <strong>and</strong><br />

so on. We would like to do this work without impacting the availability of the current<br />

data, if at all possible.<br />

The first step we might take would be to set up an empty table for fiscal year 2004 that<br />

looks just like the partitioned table. We’ll use this table to exchange with the FY_2004 partition<br />

in the partitioned table, turning that partition into a table <strong>and</strong> in turn emptying out the partition<br />

in the partitioned table. The net effect is that the oldest data in the partitioned table will<br />

have been, in effect, removed after the exchange:<br />

ops$tkyte@ORA10G> create table fy_2004 ( timestamp date, id int );<br />

Table created.<br />

ops$tkyte@ORA10G> create index fy_2004_idx on fy_2004(id)<br />

2 /<br />

Index created.<br />

We’ll do the same to the new data to be loaded. We’ll create <strong>and</strong> load a table that structurally<br />

looks like the existing partitioned table (but that is not itself partitioned):<br />

ops$tkyte@ORA10G> create table fy_2006 ( timestamp date, id int );<br />

Table created.<br />

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

2 select to_date('31-dec-2006',’dd-mon-yyyy’)-mod(rownum,360), object_id<br />

3 from all_objects<br />

4 /<br />

48521 rows created.<br />

ops$tkyte@ORA10G> create index fy_2006_idx on fy_2006(id) nologging<br />

2 /<br />

Index created.<br />

We’ll turn the current full partition into an empty partition <strong>and</strong> create a “full” table, with<br />

the FY_2004 data in it. Also, we’ve completed all of the work necessary to have the FY_2006 data<br />

ready to go. This would have involved verifying the data, transforming it—whatever complex<br />

tasks we need to undertake to get it ready.

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

Saved successfully!

Ooh no, something went wrong!