 |
|
11g Partitioning Enhancements
Oracle 11g New Features Tips by Burleson
Consulting
June 27, 2008 |
Oracle 11g SQL New Features Tips
Partitioning in Oracle is instrumental in
supporting large databases and data warehousing requirements. While
this feature dramatically improves manageability, performance, and
availability, Oracle relies on the Remote DBA to manually define each
partition. In data warehousing environments, the creation of
new partitions is a monotonous but necessary element of scheduled
maintenance. Oracle 11g has introduced a new partitioning
feature, called Interval Partitioning, that allows Oracle to
automatically create new partitions as data is inserted. While
there are certain limitations to using interval partitioning, it has
proven to be a very effective feature when used in the appropriate
context. This section will demonstrate how to use this
feature, discuss its limitations, and provide recommendations for
making the most of this exciting enhancement.
Partitioning is the division of tables, indexes,
or index-organized tables into smaller pieces. These smaller
pieces are called partitions which can be managed and accessed
independently. This concept is commonly characterized as a
divide-and-conquer approach to managing large tables and indexes.
When defining a partitioned table, one or more columns are used as
keys to match the row into the appropriate partition. Data loads in
partitioned tables will fail if one or more records cannot be
matched to an existing partition.
Interval partitioning is an enhancement to range
partitioning. Range partitioning allows an object to be
partitioned by a specified range on the partitioning key. For
example, if a table was used to store sales data, it might be range
partitioned by a DATE column, with each month in a different
partition. Therefore, every month a new partition would need
to be defined in order to store rows for that month. If a row
was inserted for a new month before a partition was defined for that
month, the following error would result:
ORA-14400:
inserted partition key does not map to any partition
If this situation occurs, data loading will fail
until the new partitions are created. This can cause serious
problems in larger data warehouses where complex reporting has many
steps and dependencies in a batch process. Mission critical
reports might be delayed or incorrect due to this problem.
Interval partitioning can simplify the
manageability by automatically creating the new partitions as
needed by the data. Interval partitioning is enabled in the
table’s definition by defining one or more range partitions and
including a specified interval. For example, consider the
following table:
create
table
pos_data (
start_date DATE,
store_id
NUMBER,
inventory_id NUMBER(6),
qty_sold
NUMBER(3),
)
PARTITION BY RANGE (start_date)
INTERVAL(NUMTOYMINTERVAL(1, 'MONTH'))
(
PARTITION pos_data_p2 VALUES LESS THAN (TO_DATE('1-7-2007', 'DD-MM-YYYY')),
PARTITION pos_data_p3 VALUES LESS THAN (TO_DATE('1-8-2007', 'DD-MM-YYYY'))
);
Here, two partitions have been defined and an
interval of one month has been specified. If data is loaded
into this table with a later date than the greatest defined
partition, Oracle will automatically create a new partition for the
new month. In the table above, the greatest defined interval
is between July 1, 2007 and August 1, 2007. Inserting a row
that has a date later than August 1, 2007 would raise an error with
normal range partitioning. However, with interval
partitioning, Oracle determines the high value of the defined range
partitions, called the transition point, and creates new partitions
for data that is beyond that high value.
insert into
pos_data (start_date, store_id, inventory_id, qty_sold)
values ( '15-AUG-07', 1, 1, 1);
SELECT
TABLE_NAME,
PARTITION_NAME,
PARTITION_POSITION,
HIGH_VALUE
FROM
Remote DBA_TAB_PARTITIONS
WHERE
TABLE_NAME='POS_DATA'
ORDER BY
PARTITION_NAME;
PARTITION_NAME HIGH_VALUE
POS_DATA_P0 TO_DATE(' 2007-07-01
00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
POS_DATA_P1 TO_DATE(' 2007-08-01
00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P81 TO_DATE(' 2007-09-01 00:00:00', 'SYYYY-MM-DD
HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
Notice that a system generated partition named
SYS_P81 has been created upon inserting a row with a partition key
greater than the transition point. Oracle will manage the
creation of new partitions for any value beyond the high value.
Therefore, the values do not need to be inserted in sequence.
 |
This is an
excerpt from the new book
Oracle 11g New Features: Expert Guide to the Important
New Features by John Garmany, Steve Karam, Lutz Hartmann, V. J.
Jain, Brian Carr.
You can buy it direct from the publisher
for 30% off. |