Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2008 indexes - performance gain on queries vs. loss on INSERT/UPDATE

How can you determine if the performance gained on a SELECT by indexing a column will outweigh the performance loss on an INSERT in the same table? Is there a "tipping-point" in the size of the table when the index does more harm than good?

I have table in SQL Server 2008 with 2-3 million rows at any given time. Every time an insert is done on the table, a lookup is also done on the same table using two of its columns. I'm trying to determine if it would be beneficial to add indexes to the two columns used in the lookup.

like image 983
TrailJon Avatar asked Jul 15 '11 18:07

TrailJon


People also ask

Do indexes affect performance of updates and inserts?

If you update a table, the system has to maintain those indexes that are on the columns being updated. So having a lot of indexes can speed up select statements, but slow down inserts, updates, and deletes.

Does indexing improve update performance?

Then yes an index on customer_id will definitely increase the speed since it will find the row to update much quicker. But for improvement, if you have columns (id,customer_id,balance) and customer_id is unique and id is just an auto incremented column get rid of the id column and make customer_id the primary key.

How indexes improve performance in SQL Server?

SQL index is considered as one of the most important factors in the SQL Server performance tuning field. It helps in speeding up the queries by providing swift access to the requested data, called index seek operation, instead of scanning the whole table to retrieve a few records.

Does index affect insert?

The number of indexes on a table is the most dominant factor for insert performance. The more indexes a table has, the slower the execution becomes.


1 Answers

Like everything else SQL-related, it depends:

  • What kind of fields are they? Varchar? Int? Datetime?
  • Are there other indexes on the table?
  • Will you need to include additional fields?
  • What's the clustered index?
  • How many rows are inserted/deleted in a transaction?

The only real way to know is to benchmark it. Put the index(es) in place and do frequent monitoring, or run a trace.

like image 116
JNK Avatar answered Oct 02 '22 23:10

JNK