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 581 ops$tkyte@ORA10G> select rowid 2 from range_example 3 where range_key_column = to_date('02-jan-2005','dd-mon-yyyy'); ROWID ------------------ AAARmgAAKAAAI+iAAC As long as you understand that the ROWID of the row will change on this update, enabling row movement will allow you to update partition keys. ■Note There are other cases where a ROWID can change as a result of an update. It can happen as a result of an update to the primary key of an IOT. The universal ROWID will change for that row, too. The Oracle 10g FLASHBACK TABLE command may also change the ROWID of rows, as might the Oracle 10g ALTER TABLE SHRINK command. You need to understand that, internally, row movement is done as if you had, in fact, deleted the row and reinserted it. It will update every single index on this table, and delete the old entry and insert a new one. It will do the physical work of a DELETE plus an INSERT. However, it is considered an update by Oracle even though it physically deletes and inserts the row—therefore, it won’t cause INSERT and DELETE triggers to fire, just the UPDATE triggers. Additionally, child tables that might prevent a DELETE due to a foreign key constraint won’t. You do have to be prepared, however, for the extra work that will be performed; it is much more expensive than a normal UPDATE. Therefore, it would be a bad design decision to construct a system whereby the partition key was modified frequently and that modification would cause a partition movement. Table Partitioning Schemes Wrap-Up In general, range partitioning is useful when you have data that is logically segregated by some value(s). Time-based data immediately comes to the forefront as a classic example— partitioning by “Sales Quarter,” “Fiscal Year,” or “Month.” Range partitioning is able to take advantage of partition elimination in many cases, including the use of exact equality and ranges (less than, greater than, between, and so on). Hash partitioning is suitable for data that has no natural ranges by which you can partition. For example, if you had to load a table full of census-related data, there might not be an attribute by which it would make sense to range partition by. However, you would still like to take advantage of the administrative, performance, and availability enhancements offered by partitioning. Here, you would simply pick a unique or almost unique set of columns to hash on. This would achieve an even distribution of data across as many partitions as you’d like. Hash partitioned objects can take advantage of partition elimination when exact equality or IN ( value, value, ... ) is used, but not when ranges of data are used. List partitioning is suitable for data that has a column with a discrete set of values, and partitioning by the column makes sense based on the way your application uses it (e.g., it easily permits partition elimination in queries). Classic examples would be a state or region code—or, in fact, many “code” type attributes in general.

582 CHAPTER 13 ■ PARTITIONING Composite partitioning is useful when you have something logical by which you can range partition, but the resulting range partitions are still too large to manage effectively. You can apply the range partitioning and then further divide each range by a hash function or use lists to partition. This will allow you to spread out I/O requests across many disks in any given large partition. Additionally, you may achieve partition elimination at three levels now. If you query on the range partition key, Oracle is able to eliminate any range partitions that do not meet your criteria. If you add the hash or list key to your query, Oracle can eliminate the other hash or list partitions within that range. If you just query on the hash or list key (not using the range partition key), Oracle will query only those hash or list subpartitions that apply from each range partition. It is recommended that, if there is something by which it makes sense to range partition your data, you should use that over hash or list partitioning. Hash and list partitioning add many of the salient benefits of partitioning, but they are not as useful as range partitioning when it comes to partition elimination. Using hash or list partitions within range partitions is advisable when the resulting range partitions are too large to manage, or when you want to use all PDML capabilities or parallel index scanning against a single range partition. Partitioning Indexes Indexes, like tables, may be partitioned. There are two possible methods to partition indexes: • Equipartition the index with the table: This is also known as a locally partitioned index. For every table partition, there will be an index partition that indexes just that table partition. All of the entries in a given index partition point to a single table partition, and all of the rows in a single table partition are represented in a single index partition. • Partition the index by range: This is also known as a globally partitioned index. Here the index is partitioned by range, or optionally in Oracle 10g by hash, and a single index partition may point to any (and all) table partitions. Figure 13-5 demonstrates the difference between a local and a global index. Figure 13-5. Local and global index partitions

CHAPTER 13 ■ PARTITIONING 581<br />

ops$tkyte@ORA10G> select rowid<br />

2 from range_example<br />

3 where range_key_column = to_date('02-jan-2005','dd-mon-yyyy');<br />

ROWID<br />

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

AAARmgAAKAAAI+iAAC<br />

As long as you underst<strong>and</strong> that the ROWID of the row will change on this update, enabling<br />

row movement will allow you to update partition keys.<br />

■Note There are other cases where a ROWID can change as a result of an update. It can happen as a<br />

result of an update to the primary key of an IOT. The universal ROWID will change for that row, too. The<br />

<strong>Oracle</strong> 10g FLASHBACK TABLE comm<strong>and</strong> may also change the ROWID of rows, as might the <strong>Oracle</strong> 10g<br />

ALTER TABLE SHRINK comm<strong>and</strong>.<br />

You need to underst<strong>and</strong> that, internally, row movement is done as if you had, in fact,<br />

deleted the row <strong>and</strong> reinserted it. It will update every single index on this table, <strong>and</strong> delete the<br />

old entry <strong>and</strong> insert a new one. It will do the physical work of a DELETE plus an INSERT. However,<br />

it is considered an update by <strong>Oracle</strong> even though it physically deletes <strong>and</strong> inserts the<br />

row—therefore, it won’t cause INSERT <strong>and</strong> DELETE triggers to fire, just the UPDATE triggers. Additionally,<br />

child tables that might prevent a DELETE due to a foreign key constraint won’t. You<br />

do have to be prepared, however, for the extra work that will be performed; it is much more<br />

expensive than a normal UPDATE. Therefore, it would be a bad design decision to construct a<br />

system whereby the partition key was modified frequently <strong>and</strong> that modification would cause<br />

a partition movement.<br />

Table Partitioning Schemes Wrap-Up<br />

In general, range partitioning is useful when you have data that is logically segregated by<br />

some value(s). Time-based data immediately comes to the forefront as a classic example—<br />

partitioning by “Sales Quarter,” “Fiscal Year,” or “Month.” Range partitioning is able to take<br />

advantage of partition elimination in many cases, including the use of exact equality <strong>and</strong><br />

ranges (less than, greater than, between, <strong>and</strong> so on).<br />

Hash partitioning is suitable for data that has no natural ranges by which you can partition.<br />

For example, if you had to load a table full of census-related data, there might not be an<br />

attribute by which it would make sense to range partition by. However, you would still like to<br />

take advantage of the administrative, performance, <strong>and</strong> availability enhancements offered by<br />

partitioning. Here, you would simply pick a unique or almost unique set of columns to hash<br />

on. This would achieve an even distribution of data across as many partitions as you’d like.<br />

Hash partitioned objects can take advantage of partition elimination when exact equality<br />

or IN ( value, value, ... ) is used, but not when ranges of data are used.<br />

List partitioning is suitable for data that has a column with a discrete set of values, <strong>and</strong><br />

partitioning by the column makes sense based on the way your application uses it (e.g., it<br />

easily permits partition elimination in queries). Classic examples would be a state or region<br />

code—or, in fact, many “code” type attributes in general.

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

Saved successfully!

Ooh no, something went wrong!