开发者

unique index slows down?

开发者 https://www.devze.com 2022-12-16 02:51 出处:网络
does it slow down the query time to use a lot of unique indexes? i dont have that many im just curious, i think i have heard this some where

does it slow down the query time to use a lot of unique indexes? i dont have that many im just curious, i think i have heard this some where


It depends on the database server software and table/index type you are using. Inserts will be slower any time you have indexes of any sort, but not necessarily by a lot - this will depend on the table size as well.

In general, unique indexes should speed up any SELECT queries you use that are able to take advantage of the index(es)


They will slow down your inserts and updates (since each has to be checked to see if the constraint is violated), but should not slow down selects. In fact, they could speed them up, since there are more choices for the optimizer to use to find your data.


In general, having more indexes will slow down inserts, updates and deletes, but can speed up queries - assuming that you query based on these fields.

If you need a unique index to guarantee consistency in your application then you should usually add it even if it will result in a slight performance hit. It's better to be correct than fast but wrong.


Each time you add a unique key to a database table it adds a non-clustered index. Clustered indexes are on primary keys and sort the data in the table physically by that column(s). Each non-clustered index creates a number of leaves external to the table that sort based off of the unique key. This allows for a much more consistent search on the unique key because a full table scan is no longer required. The down side is every time you insert, update, or delete a row from the table, the server must go back and update all of the leaves external to the table. This is usually not an issue if you have a small number of unique keys but when you have many it can slow down the response times. For more info, read the Wikipedia article here. Msdn also has a good article.


Query time, no. They will slow down INSERT and DELETE time though, since each index value has to be calculated and then inserted, or removed.

0

精彩评论

暂无评论...
验证码 换一张
取 消