unique versus non-unique index in terms of performance

  • 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.

  • 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

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Thanks Grant

  • 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.

  • 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

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • 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

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply