Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do non-clustered indexes slow down inserts?

I'm working in Sql Server 2005. I have an event log table that tracks user actions, and I want to make sure that inserts into the table are as fast as possible. Currently the table doesn't have any indexes. Does adding a single non-clustered index slow down inserts at all? Or is it only clustered indexes that slow down inserts? Or should I just add a clustered index and not worry about it?

like image 215
Mike Comstock Avatar asked May 24 '10 21:05

Mike Comstock


2 Answers

Indexes, clustered or non-clustered,will always slow down inserts as SQL has to maintain both the table and index. This slowdown is in an "absolute" sense and you may not notice it. I would add whatever indexes are necessary to retrieve your data.

like image 99
Josef Richberg Avatar answered Sep 29 '22 06:09

Josef Richberg


Yes, any index will take a little bit of time to keep up to date when doing INSERT, UPDATE, DELETE operations. The more indices you have, the more time we're talking about.

But ultimately it depends on what's more important to you - good query performance (then add indices as needed), or good insert performance (then have as few indices as possible).

Which operation do you perform more often??

like image 41
marc_s Avatar answered Sep 29 '22 07:09

marc_s