Background info – I have a table that stores Job information with a unique JobID
(PK) and a ClientID
(one client can have many jobs), as well as bunch of columns that are heaped data.
I have ran sp_BlitzIndex
and it returned this:
dbo.Job.PK_Job_1 (1): Row lock waits: 399; total duration: 21 minutes;
avg duration: 3 seconds; Page lock waits: 171; total duration: 2
minutes; avg duration: 1 seconds; Lock escalation attempts: 125,805;
Actual Escalations: 0.
This table only has 35K rows in it, but it is heavily used and updated every few seconds. The current index is on the PK which is a unique value. I do not know much about index tuning, but if I remove this index and create a nonclustered index for the JobID + ClientID
, am I on the right track to reducing the aggressiveness of the index? Or am I making it worse?
Best Answer
We don't have the full picture about the table or the queries that access the table or the load in the database/server but from what we know:
JobID
and aPRIMARY KEY
constraint (and therefore an index on it).ClientID
which is an (explicit or implicit) foreign key toClient
.FOREIGN KEY
constraint defined. Is aFOREIGN KEY
defined?(JobID)
is clustered or not (the "heaped data" suggests not but we can't be sure). Is the table clustered or a heap?CREATE TABLE
statement with all the indexes.WHERE
conditions and expect (usually) no problems and likely improvements.(JobID, ClientID)
is likely useless, considering there is already a unique index on(JobID)
.(ClientID)
on the other hand will likely help some queries (that have joins toClient
). SinceClientID
is an FK, it is also likely that you have such queries.Still, adding an index blindly may give you no performance gain (and even make things worse), so test, test, test, before and after the index.