Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

unique versus non-unique index in terms of performance Expand / Collapse
Author
Message
Posted Friday, February 6, 2009 6:29 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 7, 2014 10:07 PM
Points: 48, Visits: 101
In terms of performance which one should be created between unique and non-unique index. Let us say I want to make a Non clustered index on columns which is idenetity column. As I alredy know this columns value is unique so if I create a non-unique index will that have any significant performance over the unique index.

My concern is as unique index will check for any duplicate existing row for every new entry and I have some 70000 records added to the table every day so will my upload into the table will take more time after I create this unique index. Also which index will have better query performance.
Post #651562
Posted Friday, February 6, 2009 8:08 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 5:37 AM
Points: 15,662, Visits: 28,054
It depends on the queries being run. The optimizer will take into account when an index is unique and it can improve performance, but it really does depend on the query. It might not affect things at all.

It will slow down inserts slightly, but probably not enough to notice. It doesn't have to check everything single record against every other record. It's going to use the index itself for the check which will be quite fast.

In general, if you've determined that an index will help and the data being indexed is going to be unique, I'd say go ahead and make it a unique index. It won't cost much and you will receive benefits.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #651695
Posted Friday, February 6, 2009 8:49 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Monday, July 7, 2014 10:07 PM
Points: 48, Visits: 101
Thanks Grant
Post #651754
Posted Friday, February 6, 2009 9:04 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Thursday, August 28, 2014 4:00 AM
Points: 21,397, Visits: 9,612
I'd go the complete opposite. If the data requiresa unique index (for data quality), then go ahead and create the index. I wouldn't do a unique index just because it might go faster and not consider wheter or not it could bug the applications using it.
Post #651767
Posted Friday, February 6, 2009 9:08 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 5:37 AM
Points: 15,662, Visits: 28,054
Oh no, if it's going to bug the apps, then clearly the data is not guaranteed unique. I'm just saying if the data is going to be unique, there's no reason to not make the index unique and several reasons to make it that way.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #651774
Posted Monday, February 9, 2009 9:05 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Monday, October 25, 2010 6:09 AM
Points: 1,621, Visits: 409
I Agree with Ninja's decision. If the data requires to have Unique Index then we should have Unique Index. In this world anything can happen with Data Quality. So always impose contraints on this to avoid any future Data Quality Issues.

Thanks -- Vijaya Kadiyala
http://dotnetvj.blogspot.com


Thanks -- Vijaya Kadiyala
www.dotnetvj.com
SQL Server Articles For Beginers



Post #652904
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse