Skip to Main Content
  • Questions
  • Replication FK constraints & indexes, UK constraints & indexes

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question.

Asked: March 15, 2001 - 11:40 am UTC

Last updated: September 22, 2005 - 1:20 pm UTC

Version: 8.1.7

Viewed 1000+ times

You Asked

I am fairly new to Oracle and am already setting up replication for a State application. So far, so good! I understand about how PK keys and SET COLUMNs are used - no problem. However, I am confused about how foreign key & indexes and unique key & indexes are managed on the snapshot site. There is little to no documentation discussing this subject. Are these constraints and indexes applied to the snapshot as if you were building a new database?

and Tom said...

On snapshots, foreign keys and all other constraints should be defined as DEFERABLE. All deferable constraints will be defered during a snapshot refresh and validated upon commit.

You may place any indexes on a snapshot with the exception of a unique index (you may have a unique constraint on a snapshot but make it deferable. that'll use a non-unique index).

You would also need to create a snapshot group to logically collect together all tables related by declaritive integrity constraints into one group. This group of objects will be refreshed in an atomic fashion.

The reason this is so is because snapshots refresh a table at a time. If you have the EMP and DEPT table -- and you have deleted a departement and its employees and added a deptartment with new employees, the following events will occur:

1) emp is refreshed. you will now have rows in EMP that have no dept.
2) dept is refreshed. your EMP rows now have a dept
3) commit; the changes are permanent

step 1 shows why constraints must be deferable -- during the refresh process, the data is "not consistent". No one will see these inconsistencies and when we commit, everything is OK.

step 2 shows why we need a snapshot group. if we committed each snapshot individually, the emp refresh would never work (emps without a valid DEPT). Additionally, the refresh of DEPT would never work either (we need to delete a DEPT but there are employees assigned to it).




Rating

  (6 ratings)

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

Comments

Lise, March 15, 2001 - 4:33 pm UTC


ANONYMOUS, March 16, 2001 - 4:36 pm UTC


Helena Markova, March 28, 2001 - 3:06 am UTC


Nuno Souto, May 17, 2001 - 11:20 pm UTC


vijaya, August 23, 2001 - 4:05 pm UTC


Does the no unique index ban apply to the primary key?

A reader, September 21, 2005 - 8:28 pm UTC

Does the no unique index ban apply to the primary key on materialized views that are updated based on primary key, i.e. with the following refresh clause:

REFRESH FAST
ON DEMAND
START WITH SYSDATE
NEXT SYSDATE + 1
WITH PRIMARY KEY


Tom Kyte
September 22, 2005 - 1:20 pm UTC

you should use a deferrable unique constraint, as the refresh process will "defer" the validation of uniqueness until after the refresh is done - since the refresh is a row by row operation (a process, not a single sql statement), you cannot be sure any sort of integrity constraint like that could not be violated for a brief moment of time during the refresh.