Skip to Main Content
  • Questions
  • how indexes handled by reference partitioning

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Mohammad.

Asked: May 16, 2017 - 8:53 pm UTC

Last updated: May 17, 2017 - 4:13 pm UTC

Version: 12C

Viewed 1000+ times

You Asked

when we have parent child tables partitioned by reference something like
CREATE TABLE orders
    ( order_id           NUMBER(12),
      order_date         date,
      order_mode         VARCHAR2(8),
      customer_id        NUMBER(6),
      order_status       NUMBER(2),
      order_total        NUMBER(8,2),
      sales_rep_id       NUMBER(6),
      promotion_id       NUMBER(6),
      CONSTRAINT orders_pk PRIMARY KEY(order_id)
    )
  PARTITION BY RANGE(order_date)
    ( PARTITION Q1_2005 VALUES LESS THAN (TO_DATE('01-APR-2005','DD-MON-YYYY')),
      PARTITION Q2_2005 VALUES LESS THAN (TO_DATE('01-JUL-2005','DD-MON-YYYY')),
      PARTITION Q3_2005 VALUES LESS THAN (TO_DATE('01-OCT-2005','DD-MON-YYYY')),
      PARTITION Q4_2005 VALUES LESS THAN (TO_DATE('01-JAN-2006','DD-MON-YYYY'))
    )ENABLE ROW MOVEMENT;

CREATE INDEX year_idx
on orders (order_date)
LOCAL
(PARTITION Q1_2005,
(PARTITION Q2_2005,
(PARTITION Q3_2005,
 PARTITION Q4_2005);

 

  CREATE TABLE order_items
    ( order_id           NUMBER(12) NOT NULL,
      line_item_id       NUMBER(3)  NOT NULL,
      product_id         NUMBER(6)  NOT NULL,
      unit_price         NUMBER(8,2),
      quantity           NUMBER(8),
      CONSTRAINT order_items_fk
      FOREIGN KEY(order_id) REFERENCES orders(order_id) on delete cascade 
    )
    PARTITION BY REFERENCE(order_items_fk)
    ENABLE ROW MOVEMENT;



1. do we need to implement indexes on the child table or the structure changes on the parent will be reflected on the child automatically.
2. in case we need them how to implement'em on the partitions of the child.
CREATE INDEX Item_idx
on order_items (order_id,product_id,quantity)
(PARTITION Q1_2005,
(PARTITION Q2_2005,
(PARTITION Q3_2005,
 PARTITION Q4_2005);

the index above will be implemented on the table order_items but not on the partitions, if you check dba_ind_partitions you won't find any indexes.

best regards

and Connor said...

"1. do we need to implement indexes on the child table or the structure changes on the parent will be reflected on the child automatically."

If you need indexes on the child (which is likely) you add them explicitly. We dont inherit any *indexes* from the parent.

"2. in case we need them how to implement'em on the partitions of the child."

You simply create them as local indexes

SQL> CREATE INDEX Item_idx
  2  on order_items (order_id,product_id,quantity)
  3  local;

Index created.




Is this answer out of date? If it is, please let us know via a Comment

More to Explore

VLDB

If you are new to partitioning, check out Connor McDonald's introduction series here.

VLDB

Documentation set on VLDB and Partitioning.