niXforums Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
·  nixdoc.net ·  man pages ·  Linux HOWTOs ·  FreeBSD Tips ·  Forums
navigation Forum index » Databases » Oracle
Using NonUnique Index to Enforce Uniqueness
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
Author Message
Mark D Powell
*nix forums Guru


Joined: 23 Apr 2005
Posts: 701

PostPosted: Wed Feb 23, 2005 1:41 pm    Post subject: Re: Using NonUnique Index to Enforce Uniqueness Reply with quote

If you use a unique index to enforce the PK constrainst, which is how
all versions prior to version 8 worked, then if you attempt to insert a
duplicate key an error will be generated at the time the index is
updated. On the other hand if you use a non-unique index to support
the PK constraint then Oracle can delay issuing an error message until
the time of commit. This is the mechanism that allows deferrable
constraints. The enforcement of the constraint is deferred until
commit time. As long as all necessary operations are accomplished
within the transaction the transaction will succeed.

This allows design flexibility so that the developer can delete the
parent row that has child rows (FK) first and then delete the child
rows after instead of having to delete the children first and then go
back and delete the parent. It allows inserting child rows that do not
have a parent row first and then creating the parent row.

The mechanics of exactly how Oracle accomplishes this task as not
described in the documentation, but obviously the rdbms has a means of
keeping a record of which rows have been changed and for which the
constraints need to be checked.

In the version 8 manual Oracle recommended that all indexes be created
as non-unique and the constraints defined to use the existing indexes.
I do not think this recommendation appears in the newer manuals though
in the 10g manual Oracle does recommend expliciting creating the
indexes used to support constraint prior to defining the constraint.

If Oracle inserts a row into a table and then updates an index it
discovers if the key alreadys exists in the index when the index is
updated. All if takes is a simple logic check of "is there a PK or UK
constraint on this" and if so then indicate a duplicate condition which
can then be signaled either immediately or at commit depending on if
the constraint is deferred.

HTH -- Mark D Powell --
Back to top
dd
*nix forums beginner


Joined: 08 Jun 2005
Posts: 14

PostPosted: Wed Feb 23, 2005 7:46 am    Post subject: Using NonUnique Index to Enforce Uniqueness Reply with quote

Oracle manual describes using non unique index to enforce unique constraint
so that the index will not be dropped with constraint is diabled.

But I dont understand why non unique index can enforce uniqueness?
Back to top
Google

Back to top
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 1 [2 Posts] View previous topic :: View next topic
The time now is Thu Jan 08, 2009 6:15 am | All times are GMT
navigation Forum index » Databases » Oracle
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts container for insert/delete + fast index Neal Becker C++ 1 Fri Jul 21, 2006 12:57 pm
No new posts (secondary) index-only scans Ryan Berkeley DB 1 Thu Jul 20, 2006 8:32 pm
No new posts Create index hanging Claire McLister PostgreSQL 7 Thu Jul 20, 2006 8:11 pm
No new posts VACUUM and index DANTE Alexandra PostgreSQL 3 Wed Jul 19, 2006 1:03 pm
No new posts number of distinct values in tsearch2 gist index Kevin Murphy PostgreSQL 0 Tue Jul 18, 2006 5:24 pm

Debt Consolidation | Debt Consolidation | Secured Loans | Personal Finance | Mortgages
Copyright © 2004-2005 DeniX Solutions SRL
 
Other DeniX Solutions sites: Unix/Linux blog |  electronics forum |  medicine forum |  science forum | 
Privacy Policy


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1383s ][ Queries: 20 (0.0680s) ][ GZIP on - Debug on ]