Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
CHAPTER 13 ■ PARTITIONING 577 We would have to remove the DEFAULT partition, then add PART_4, and then put the DEFAULT partition back. The reason behind this is that the DEFAULT partition could have had rows with the list partition key value of CA or NM—they would not belong in the DEFAULT partition after adding PART_4. Composite Partitioning Lastly, we’ll look at some examples of composite partitioning, which is a mixture of range and hash or range and list. In composite partitioning, the top-level partitioning scheme is always range partitioning. The secondary level of partitioning is either list or hash (in Oracle9i Release 1 and earlier only hash subpartitioning is supported, not list). It is interesting to note that when you use composite partitioning, there will be no partition segments—there will be only subpartition segments. When using composite partitioning, the partitions themselves do not have segments (much like a partitioned table doesn’t have a segment). The data is physically stored in subpartition segments and the partition becomes a logical container, or a container that points to the actual subpartitions. In our example, we’ll look at a range-hash composite. Here we are using a different set of columns for the range partition from those used for the hash partition. This is not mandatory; we could use the same set of columns for both: ops$tkyte@ORA10G> CREATE TABLE composite_example 2 ( range_key_column date, 3 hash_key_column int, 4 data varchar2(20) 5 ) 6 PARTITION BY RANGE (range_key_column) 7 subpartition by hash(hash_key_column) subpartitions 2 8 ( 9 PARTITION part_1 10 VALUES LESS THAN(to_date('01/01/2005','dd/mm/yyyy')) 11 (subpartition part_1_sub_1, 12 subpartition part_1_sub_2 13 ), 14 PARTITION part_2 15 VALUES LESS THAN(to_date('01/01/2006','dd/mm/yyyy')) 16 (subpartition part_2_sub_1, 17 subpartition part_2_sub_2 18 ) 19 ) 20 / Table created. In range-hash composite partitioning, Oracle will first apply the range partitioning rules to figure out which range the data falls into. Then it will apply the hash function to decide into which physical partition the data should finally be placed. This process is described in Figure 13-4.
578 CHAPTER 13 ■ PARTITIONING Figure 13-4. Range-hash composite partition example So, composite partitioning gives you the ability to break up your data by range and, when a given range is considered too large or further partition elimination could be useful, to break it up further by hash or list. It is interesting to note that each range partition need not have the same number of subpartitions; for example, suppose you were range partitioning on a date column in support of data purging (to remove all old data rapidly and easily). In the year 2004, you had equal amounts of data in “odd” code numbers in the CODE_KEY_COLUMN and in “even” code numbers. But in 2005, you knew the number of records associated with the odd code number was more than double, and you wanted to have more subpartitions for the odd code values. You can achieve that rather easily just by defining more subpartitions: ops$tkyte@ORA10G> CREATE TABLE composite_range_list_example 2 ( range_key_column date, 3 code_key_column int, 4 data varchar2(20) 5 ) 6 PARTITION BY RANGE (range_key_column) 7 subpartition by list(code_key_column) 8 ( 9 PARTITION part_1 10 VALUES LESS THAN(to_date('01/01/2005','dd/mm/yyyy')) 11 (subpartition part_1_sub_1 values( 1, 3, 5, 7 ), 12 subpartition part_1_sub_2 values( 2, 4, 6, 8 )
- Page 572 and 573: CHAPTER 12 ■ DATATYPES 527 month
- Page 574 and 575: CHAPTER 12 ■ DATATYPES 529 DT2-DT
- 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 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 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
578<br />
CHAPTER 13 ■ PARTITIONING<br />
Figure 13-4. Range-hash composite partition example<br />
So, composite partitioning gives you the ability to break up your data by range <strong>and</strong>, when<br />
a given range is considered too large or further partition elimination could be useful, to break<br />
it up further by hash or list. It is interesting to note that each range partition need not have the<br />
same number of subpartitions; for example, suppose you were range partitioning on a date<br />
column in support of data purging (to remove all old data rapidly <strong>and</strong> easily). In the year 2004,<br />
you had equal amounts of data in “odd” code numbers in the CODE_KEY_COLUMN <strong>and</strong> in “even”<br />
code numbers. But in 2005, you knew the number of records associated with the odd code<br />
number was more than double, <strong>and</strong> you wanted to have more subpartitions for the odd code<br />
values. You can achieve that rather easily just by defining more subpartitions:<br />
ops$tkyte@ORA10G> CREATE TABLE composite_range_list_example<br />
2 ( range_key_column date,<br />
3 code_key_column int,<br />
4 data varchar2(20)<br />
5 )<br />
6 PARTITION BY RANGE (range_key_column)<br />
7 subpartition by list(code_key_column)<br />
8 (<br />
9 PARTITION part_1<br />
10 VALUES LESS THAN(to_date('01/01/2005','dd/mm/yyyy'))<br />
11 (subpartition part_1_sub_1 values( 1, 3, 5, 7 ),<br />
12 subpartition part_1_sub_2 values( 2, 4, 6, 8 )