select *
from table
where
columnA = ? -- uniqueidentifier
and columnB is not null -- uniqueidentifier
and columnC = 'O'
and columnD is null
order by columnB -- uniqueidentifier
columnA, columnB, columnC and columnD are indexed
For a the particular value of columnA the query returns
approx 11,000 rows
You may think it odd to order by a uniqueidentifier but
all I need is to group the sets of rows together
for my processing
When fired through QueryAnalyzer (with the ? filled in
with the actual value) the response is fine taking just
a few seconds to begin returning values
When I run my program using Openlink multi-tier drivers
the response is also fine (but we're trying to get away
from using these which is why I am using the MS drivers)
When I run my program using MS drivers it takes 1hr20min
to get the results back
Observing sqlserver.exe using TaskManager on the server I
see that it rapidly proceeds to use up all available
memory (about 1.3Gbytes) on my server and then sit there
(possibly paging?) consuming very little cpu
I have found a temporary workaround which is to add an
inconsequential column to the order by clause :
order by columnB, columnE
which restores the performance to normal
Many other queries on this table and many others on other
tables, large and small, in the database using the MS
drivers work fine
Has anyone seen this kind of behaviour before?
Can anybody work out what SQLServer is doing and how I can
prevent it happening in future?