Clustering on Non-Autoincrement Field – Impact on Inserts

auto-incrementazure-sql-databaseclustered-index

I have a table with an id column which is auto-incremented, and various other informational columns. Rows are inserted into this table very frequently. When the data is read back, the majority of queries filter by a foreign key and a date range.

Currently, there is a clustered index on the id column, and a non-clustered index on the two columns of importance (TrackerId and DateRecorded). If I were to swap the indexes, our queries will run a lot faster. Would this negatively affect insert times?

Best Answer

In your actual design you have unique, static,narrow, ever-increasing clustered index key that causes no page splits when rows are inserted.

If you create your clustered index on TrackerId and DateRecorded (you want to use these columns in this order, right? because your seek predicate has an equality on TrackerId and range on DateRecorded) you'll get non-increasing clustered key that will cause page splits on INSERT.

It will be wider and maybe not unique.

But final decision is up to you. We don't know if this table has more reads or writes, and page splits can be mitigated by choosing appropriate Fill Factor and regular index rebuild.

Here your can read more on it: Mitigating Index Fragmentation by Paul Randal