Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
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
- Page 576 and 577: CHAPTER 12 ■ DATATYPES 531 DT TS
- Page 578 and 579: CHAPTER 12 ■ DATATYPES 533 ops$tk
- Page 580 and 581: CHAPTER 12 ■ DATATYPES 535 Since
- Page 582 and 583: CHAPTER 12 ■ DATATYPES 537 ops$tk
- Page 584 and 585: CHAPTER 12 ■ DATATYPES 539 ops$tk
- Page 586 and 587: CHAPTER 12 ■ DATATYPES 541 suppor
- 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 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 638 and 639: CHAPTER 13 ■ PARTITIONING 593 •
- 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
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.