Sie sind auf Seite 1von 4

Oracle 11g New Features Tips

Reference partitioning is a new partitioning option in Oracle 11g that allows the
partitioning of two related tables to be based on a referential constraint. In other
words, when there is a parent-child relationship between two tables, the parent
table can be defined with its partitions. Subsequently, the child table can be
equipartitioned by defining the child table to inherit the partitioning key from the
parent table, without the need to duplicate the partition key columns. This logical
partitioning is achieved by the inheritance of the parents partitioning scheme
through a referential constraint in the child table. This feature enhances the
manageability of the child table because all partition maintenance operations on
the parent table automatically cascade to the child table. Additionally, this
relieves the DBA of the responsibility of maintaining duplicate columns, and
partitions in the child table, in order to achieve the same objective.
Using Reference Partitioning
In a relational database, there are a countless number of situations where parentchild relationships exist. Consider the abundance of parent-child table
relationships in Oracle schemas that support online transaction processing or data
warehousing. For example, consider the following two tables based on an order
management schema.
The table order_headers is a parent table that stores the header level information
about a sales order. The business has made the decision to partition this table by
sales regions North, East, South, and West. The table is created with the following
statement:
create table
order_headers (
header_id number primary key,
order_date date,
sales_region varchar2(1) not null
)
partition by
list (sales_region)
(
partition pN values ('N'),
partition pE values ('E'),
partition pS values ('S'),
partition pW values ('W')
);

The table order_lines is a child table of the order_headers table and has a foreign
key constraint fk_lines_0 on header_id with its parent table. The order_lines table
is defined as:
create table
order_lines (
line_id number primary key,
header_id number not null,
customer_id number,
product_id number,
quantity number,
price number,
constraint fk_lines_0
foreign key (header_id)
references order_headers
);
Given the child-parent relationship of order_lines with order_headers, it would be
best to partition order_lines by sales_region in order to take full advantage of
partition-wise joins and enhances the manageability of these tables. However, this
column is not included in the child table. Prior to 11g, this would be accomplished
by duplicating the sales_region column in the order_lines table. The DBA would
then be forced to define and manage the partitions from both tables independently.
However, by using reference partitioning in Oracle 11g, it is easy to equi-partition
order_lines with its parent by using the foreign key constraint as such:
create table
order_lines (
line_id number primary key,
header_id number not null,
customer_id number,
product_id number,
quantity number,
price number,
constraint fk_lines_0
foreign key (header_id)
references order_headers
)
partition by
reference (fk_lines_0);
This table now inherits the partitioning scheme from its parent table by reference

without needing to include sales_region in the order_lines table. The partitions for
order_lines are created identical to its parent. Order_headers, and any maintenance
operations on the partitions of order_headers, will automatically cascade to its
child table, order_lines. To view the partitions created for order_lines, use the
dictionary views dba_part_tables and dba_tab_partitions:
select
table_name,
partition_count,
ref_ptn_constraint_name
from
dba_part_tables
where
table_name = 'ORDER_LINES';
TABLE_NAME
PARTITION_COUNT
REF_PTN_CONSTRAINT_NAME
------------- ---------------------------------------ORDER_LINES
4
FK_LINES_0
select
partition_name
from
dba_tab_partitions
where
table_name = 'ORDER_LINES';
PARTITION_NAME
-------------PE
PS
PW
PN
Limitations of reference partitioning cannot be used when the parent table uses
interval partitioning. Referential constraint on child table must be defined on a
NOT NULL parent column and a virtual column cannot be part of the partitioning
foreign key. Violating any of these limitations will cause an error such as:
ORA-14652: reference partitioning foreign key is not
supported

Reference partitioning improves and simplifies the partitioning of tables that have
a parent-child relationship. It also allows the DBA to maintain both sets of
partitions by only managing partitions on the parent table. This removes the
necessity for managing the partitions on the child table. Similarly, reference
partitioning also eliminates the need to include unnecessary duplicate columns
from the parent table to enable equi-partitioning of the child table.

Das könnte Ihnen auch gefallen