Is there any difference on performance when an unique-indexed column has also a unique constraint on the related column?
I know that unique indexes and non-unique indexes have differences on performance.
But my question is, will there be any difference on performance if the column has both unique constraint and unique index, and just unique index without a unique constraint?
Another question is, does the column statistics have any affect on unique index usage?
Oracle Database policies unique constraints with (unique) indexes.
When checking for duplicate entries, querying the table, etc. the database will use the index. Not the constraint. So for the most part performance will come out the same:
There is one exception. A unique constraint can be the target of a foreign key. Whereas a unique index (alone) can't:
Provided you created unique and foreign key constraints, this enables the optimizer to eliminate tables in some queries. Which could give large performance benefits:
Table stats will affect whether the optimizer uses the index. If you search for unique values less than 100:
The optimizer is more likely to go for a full table scan if there are only 100 rows in the table. But if there are millions, the index becomes much more attractive.