SQL Server, very busy table, holds activity for around 6-10K users at any time and have inserts/updates/deletes on each hit.
I didn’t use index on this table as any data written doesn’t stay more than 10 minutes.
But while watching activity monitor I’ve noticed that SQL Server suggests adding an index to that table.
I know keeping index on a table has its costs do you think I should add index?
Update about details:
SQL 2008 R2
Table
[id] [bigint] IDENTITY(1,1) NOT NULL,
[siteid] [int] NOT NULL,
[last_seen] [datetime] NOT NULL,
[ua] [varchar](250) NOT NULL,
[ip] [varchar](15) NOT NULL,
[t_id] [int] NOT NULL
Suggested index
ON [dbo].[onlines] ([ua],[ip],[t_id])
Having a good clustering key can actually speed up even your inserts (read Kimberly Tripp’s excellent blog post The Clustered Index Debate Continues for a great and thorough explanation, why that is so)! And from the looks of it, you have no clustering key at all.
So I would definitely recommend adding a primary/clustering key on your
idcolumn – it’s perfectly suited for a good clustering key: narrow, static, unique, ever-increasing:That should speed up everything – inserts, updates, deletes and select, too.
Whether you need additional indices (and which columns to index) depends on your SELECT queries – since you didn’t really tell us anything about those, we can only guess into the blue…..
Basically, what you need to do:
There’s really no magic formula to decide whether you need an index, what it is, and how much it’ll help your scenario (or how much it’ll hurt INSERT performance) – you need to measure yourself, on your database, your hardware, your environment.