Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005
CHAPTER 13 ■ PARTITIONING 567 Table Partitioning Schemes There are currently four methods by which you can partition tables in Oracle: • Range partitioning: You may specify ranges of data that should be stored together. For example, everything that has a timestamp within the month of Jan-2005 will be stored in partition 1, everything with a timestamp within Feb-2005 will be stored in partition 2, and so on. This is probably the most commonly used partitioning mechanism in Oracle. • Hash partitioning: You saw this in the first example in this chapter. A column (or columns) has a hash function applied to it, and the row will be placed into a partition according to the value of this hash. • List partitioning: You specify a discrete set of values, which determines the data that should be stored together. For example, you could specify that rows with a STATUS column value in ( 'A', 'M', 'Z' ) go into partition 1, those with a STATUS value in ( 'D', 'P', 'Q' ) go into partition 2, and so on. • Composite partitioning: This is a combination of range and hash or range and list. It allows you to first apply range partitioning to some data, and then within that range have the final partition be chosen by hash or list. In the following sections, we’ll look at the benefits of each type of partitioning and at the differences between them. We’ll also look at when to apply which schemes to different application types. This section is not intended to present a comprehensive demonstration of the syntax of partitioning and all of the available options. Rather, the examples are simple and illustrative, and designed to give you an overview of how partitioning works and how the different types of partitioning are designed to function. ■Note For full details on partitioning syntax, I refer you to either the Oracle SQL Reference Guide or to the Oracle Administrator’s Guide. Additionally, the Oracle Data Warehousing Guide is an excellent source of information on the partitioning options and is a must-read for anyone planning to implement partitioning. Range Partitioning The first type we will look at is a range partitioned table. The following CREATE TABLE statement creates a range partitioned table using the column RANGE_KEY_COLUMN. All data with a RANGE_ KEY_COLUMN strictly less than 01-JAN-2005 will be placed into the partition PART_1, and all data with a value strictly less than 01-JAN-2006 will go into partition PART_2. Any data not satisfying either of those conditions (e.g., a row with a RANGE_KEY_COLUMN value of 01-JAN-2007) will fail upon insertion, as it cannot be mapped to a partition: ops$tkyte@ORA10GR1> CREATE TABLE range_example 2 ( range_key_column date , 3 data varchar2(20) 4 ) 5 PARTITION BY RANGE (range_key_column)
568 CHAPTER 13 ■ PARTITIONING 6 ( PARTITION part_1 VALUES LESS THAN 7 (to_date('01/01/2005','dd/mm/yyyy')), 8 PARTITION part_2 VALUES LESS THAN 9 (to_date('01/01/2006','dd/mm/yyyy')) 10 ) 11 / Table created. ■Note We are using the date format DD/MM/YYYY in the CREATE TABLE to make this “international.” If we used a format of DD-MON-YYYY, then the CREATE TABLE would fail with ORA-01843: not a valid month if the abbreviation of January was not Jan on your system. The NLS_LANGUAGE setting would affect this. I have used the three-character month abbreviation in the text and inserts, however, to avoid any ambiguity as to which component is the day and which is the month. Figure 13-1 shows that Oracle will inspect the value of the RANGE_KEY_COLUMN and, based on that value, insert it into one of the two partitions. Figure 13-1. Range partition insert example The rows inserted were specifically chosen with the goal of demonstrating that the partition range is strictly less than and not less than or equal to. We first insert the value 15-DEC-2004, which will definitely go into partition PART_1. We also insert a row with a date/time that is one second before 01-JAN-2005—that row will also will go into partition PART_1 since
- Page 562 and 563: CHAPTER 12 ■ DATATYPES 517 Note t
- Page 564 and 565: CHAPTER 12 ■ DATATYPES 519 We are
- Page 566 and 567: CHAPTER 12 ■ DATATYPES 521 Format
- Page 568 and 569: CHAPTER 12 ■ DATATYPES 523 ops$tk
- Page 570 and 571: CHAPTER 12 ■ DATATYPES 525 You ca
- 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 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 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
568<br />
CHAPTER 13 ■ PARTITIONING<br />
6 ( PARTITION part_1 VALUES LESS THAN<br />
7 (to_date('01/01/2005','dd/mm/yyyy')),<br />
8 PARTITION part_2 VALUES LESS THAN<br />
9 (to_date('01/01/2006','dd/mm/yyyy'))<br />
10 )<br />
11 /<br />
Table created.<br />
■Note We are using the date format DD/MM/YYYY in the CREATE TABLE to make this “international.” If we<br />
used a format of DD-MON-YYYY, then the CREATE TABLE would fail with ORA-01843: not a valid month<br />
if the abbreviation of January was not Jan on your system. The NLS_LANGUAGE setting would affect this.<br />
I have used the three-character month abbreviation in the text <strong>and</strong> inserts, however, to avoid any ambiguity<br />
as to which component is the day <strong>and</strong> which is the month.<br />
Figure 13-1 shows that <strong>Oracle</strong> will inspect the value of the RANGE_KEY_COLUMN <strong>and</strong>, based<br />
on that value, insert it into one of the two partitions.<br />
Figure 13-1. Range partition insert example<br />
The rows inserted were specifically chosen with the goal of demonstrating that the<br />
partition range is strictly less than <strong>and</strong> not less than or equal to. We first insert the value<br />
15-DEC-2004, which will definitely go into partition PART_1. We also insert a row with a date/time<br />
that is one second before 01-JAN-2005—that row will also will go into partition PART_1 since