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 579 14 PARTITION part_2 15 VALUES LESS THAN(to_date('01/01/2006','dd/mm/yyyy')) 16 (subpartition part_2_sub_1 values ( 1, 3 ), 17 subpartition part_2_sub_2 values ( 5, 7 ), 18 subpartition part_2_sub_3 values ( 2, 4, 6, 8 ) 19 ) 20 ) 21 / Table created. Here you end up with five partitions altogether: two subpartitions for partition PART_1 and three for partition PART_2. Row Movement You might wonder what would happen if the column used to determine the partition is modified in any of the preceding partitioning schemes. There are two cases to consider: • The modification would not cause a different partition to be used; the row would still belong in this partition. This is supported in all cases. • The modification would cause the row to move across partitions. This is supported if row movement is enabled for the table; otherwise, an error will be raised. We can observe these behaviors easily. In the previous example, we inserted a pair of rows into PART_1 of the RANGE_EXAMPLE table: ops$tkyte@ORA10G> insert into range_example 2 ( range_key_column, data ) 3 values 4 ( to_date( '15-dec-2004 00:00:00', 5 'dd-mon-yyyy hh24:mi:ss' ), 6 'application data...' ); 1 row created. ops$tkyte@ORA10G> insert into range_example 2 ( range_key_column, data ) 3 values 4 ( to_date( '01-jan-2005 00:00:00', 5 'dd-mon-yyyy hh24:mi:ss' )-1/24/60/60, 6 'application data...' ); 1 row created. ops$tkyte@ORA10G> select * from range_example partition(part_1); RANGE_KEY DATA --------- -------------------- 15-DEC-04 application data... 31-DEC-04 application data...

580 CHAPTER 13 ■ PARTITIONING We take one of the rows and update the value in its RANGE_KEY_COLUMN such that it can remain in PART_1: ops$tkyte@ORA10G> update range_example 2 set range_key_column = trunc(range_key_column) 3 where range_key_column = 4 to_date( '31-dec-2004 23:59:59', 5 'dd-mon-yyyy hh24:mi:ss' ); 1 row updated. As expected, this succeeds: the row remains in partition PART_1. Next, we update the RANGE_KEY_COLUMN to a value that would cause it to belong in PART_2: ops$tkyte@ORA10G> update range_example 2 set range_key_column = to_date('02-jan-2005','dd-mon-yyyy') 3 where range_key_column = to_date('31-dec-2004','dd-mon-yyyy'); update range_example * ERROR at line 1: ORA-14402: updating partition key column would cause a partition change That immediately raises an error, since we did not explicitly enable row movement. In Oracle8i and later releases, we can enable row movement on this table to allow the row to move from partition to partition. ■Note The row movement functionality is not available on Oracle 8.0; you must delete the row and reinsert it in that release. You should be aware of a subtle side effect of doing this, however; namely that the ROWID of a row will change as the result of the update: ops$tkyte@ORA10G> select rowid 2 from range_example 3 where range_key_column = to_date('31-dec-2004','dd-mon-yyyy'); ROWID ------------------ AAARmfAAKAAAI+aAAB ops$tkyte@ORA10G> alter table range_example 2 enable row movement; Table altered. ops$tkyte@ORA10G> update range_example 2 set range_key_column = to_date('02-jan-2005','dd-mon-yyyy') 3 where range_key_column = to_date('31-dec-2004','dd-mon-yyyy'); 1 row updated.

CHAPTER 13 ■ PARTITIONING 579<br />

14 PARTITION part_2<br />

15 VALUES LESS THAN(to_date('01/01/2006','dd/mm/yyyy'))<br />

16 (subpartition part_2_sub_1 values ( 1, 3 ),<br />

17 subpartition part_2_sub_2 values ( 5, 7 ),<br />

18 subpartition part_2_sub_3 values ( 2, 4, 6, 8 )<br />

19 )<br />

20 )<br />

21 /<br />

Table created.<br />

Here you end up with five partitions altogether: two subpartitions for partition PART_1 <strong>and</strong><br />

three for partition PART_2.<br />

Row Movement<br />

You might wonder what would happen if the column used to determine the partition is modified<br />

in any of the preceding partitioning schemes. There are two cases to consider:<br />

• The modification would not cause a different partition to be used; the row would still<br />

belong in this partition. This is supported in all cases.<br />

• The modification would cause the row to move across partitions. This is supported if<br />

row movement is enabled for the table; otherwise, an error will be raised.<br />

We can observe these behaviors easily. In the previous example, we inserted a pair of rows<br />

into PART_1 of the RANGE_EXAMPLE table:<br />

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

2 ( range_key_column, data )<br />

3 values<br />

4 ( to_date( '15-dec-2004 00:00:00',<br />

5 'dd-mon-yyyy hh24:mi:ss' ),<br />

6 'application data...' );<br />

1 row created.<br />

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

2 ( range_key_column, data )<br />

3 values<br />

4 ( to_date( '01-jan-2005 00:00:00',<br />

5 'dd-mon-yyyy hh24:mi:ss' )-1/24/60/60,<br />

6 'application data...' );<br />

1 row created.<br />

ops$tkyte@ORA10G> select * from range_example partition(part_1);<br />

RANGE_KEY DATA<br />

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

15-DEC-04 application data...<br />

31-DEC-04 application data...

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

Saved successfully!

Ooh no, something went wrong!