Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
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.
- Page 588 and 589: CHAPTER 12 ■ DATATYPES 543 Concep
- Page 590 and 591: CHAPTER 12 ■ DATATYPES 545 We can
- Page 592 and 593: CHAPTER 12 ■ DATATYPES 547 buffer
- Page 594 and 595: CHAPTER 12 ■ DATATYPES 549 Note t
- Page 596 and 597: CHAPTER 12 ■ DATATYPES 551 13 dbm
- Page 598 and 599: CHAPTER 12 ■ DATATYPES 553 equall
- Page 600 and 601: CHAPTER 12 ■ DATATYPES 555 ROWID/
- Page 602 and 603: CHAPTER 13 ■ ■ ■ Partitioning
- Page 604 and 605: CHAPTER 13 ■ PARTITIONING 559 6 (
- Page 606 and 607: CHAPTER 13 ■ PARTITIONING 561 els
- Page 608 and 609: CHAPTER 13 ■ PARTITIONING 563 BIG
- Page 610 and 611: CHAPTER 13 ■ PARTITIONING 565 Enh
- Page 612 and 613: CHAPTER 13 ■ PARTITIONING 567 Tab
- Page 614 and 615: CHAPTER 13 ■ PARTITIONING 569 tha
- Page 616 and 617: CHAPTER 13 ■ PARTITIONING 571 PAR
- Page 618 and 619: CHAPTER 13 ■ PARTITIONING 573 35
- Page 620 and 621: CHAPTER 13 ■ PARTITIONING 575 If
- Page 622 and 623: CHAPTER 13 ■ PARTITIONING 577 We
- Page 624 and 625: CHAPTER 13 ■ PARTITIONING 579 14
- Page 626 and 627: CHAPTER 13 ■ PARTITIONING 581 ops
- Page 628 and 629: CHAPTER 13 ■ PARTITIONING 583 In
- Page 630 and 631: CHAPTER 13 ■ PARTITIONING 585 ops
- Page 632 and 633: CHAPTER 13 ■ PARTITIONING 587 | S
- Page 634 and 635: CHAPTER 13 ■ PARTITIONING 589 12
- Page 636 and 637: CHAPTER 13 ■ PARTITIONING 591 ops
- Page 640 and 641: CHAPTER 13 ■ PARTITIONING 595 Now
- Page 642 and 643: CHAPTER 13 ■ PARTITIONING 597 the
- Page 644 and 645: CHAPTER 13 ■ PARTITIONING 599 imp
- Page 646 and 647: CHAPTER 13 ■ PARTITIONING 601 OLT
- Page 648 and 649: CHAPTER 13 ■ PARTITIONING 603 5 s
- Page 650 and 651: CHAPTER 13 ■ PARTITIONING 605 Sur
- Page 652 and 653: CHAPTER 13 ■ PARTITIONING 607 On
- Page 654 and 655: CHAPTER 13 ■ PARTITIONING 609 Row
- Page 656 and 657: CHAPTER 13 ■ PARTITIONING 611 So,
- Page 658 and 659: CHAPTER 13 ■ PARTITIONING 613 Aud
- Page 660 and 661: CHAPTER 14 ■ ■ ■ Parallel Exe
- Page 662 and 663: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 664 and 665: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 666 and 667: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 668 and 669: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 670 and 671: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 672 and 673: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 674 and 675: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 676 and 677: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 678 and 679: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 680 and 681: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 682 and 683: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 684 and 685: CHAPTER 14 ■ PARALLEL EXECUTION 6
- Page 686 and 687: CHAPTER 14 ■ PARALLEL EXECUTION 6
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.