You can try creating a temporary table, insert your values to it and use the table instead in the IN
predicate.
AFAIK, SQL Server 2000
cannot build a hash table of the set of constants, which deprives the optimizer of possibility to use a HASH SEMI JOIN
.
This will help only if you don't have an index on FieldW
(which you should have).
You can also try to include your FieldX
and FieldY
columns into the index:
CREATE INDEX ix_a_wxy ON a (FieldW, FieldX, FieldY)
so that the query could be served only by using the index.
SQL Server 2000
lacks INCLUDE
option for CREATE INDEX
and this may degrade DML
performance a little but improve the query performance.
Update:
From your execution plan I see than you need a composite index on (SettingsID, SectionID)
SQL Server 2000
indeed can built a hash table out of a constant list (and does it), but Hash Semi Join
most probably will be less efficient than a Nested Loop
for query query.
And just a side note: if you need to know the count of rows satisfying the WHERE
condition, don't use COUNT(column)
, use COUNT(*)
instead.
A COUNT(column)
does not count the rows for which the column
value is NULL
.
This means that, first, you can get the results you didn't expect, and, second, the optimizer will need to do an extra Key Lookup
/ Bookmark Lookup
if your column is not covered by an index that serves the WHERE
condition.
Since ThreadId
seems to be a CLUSTERED PRIMARY KEY
, it's all right for this very query, but try to avoid it in general.