Slow query with unexpected scan
Posted
by zerkms
on Stack Overflow
See other posts from Stack Overflow
or by zerkms
Published on 2010-03-17T23:25:52Z
Indexed on
2010/03/17
23:31 UTC
Read the original article
Hit count: 242
Hello
I have this query:
SELECT *
FROM SAMPLE SAMPLE
INNER JOIN TEST TEST ON SAMPLE.SAMPLE_NUMBER = TEST.SAMPLE_NUMBER
INNER JOIN RESULT RESULT ON TEST.TEST_NUMBER = RESULT . TEST_NUMBER
WHERE SAMPLED_DATE BETWEEN '2010-03-17 09:00' AND '2010-03-17 12:00'
the biggest table here is RESULT, contains 11.1M records. The left 2 tables about 1M.
this query works slowly (more than 10 minutes) and returns about 800 records. executing plan shows clustered index scan over all 11M records. RESULT.TEST_NUMBER is a clustered primary key.
if I change 2010-03-17 09:00 to 2010-03-17 10:00 - i get about 40 records. it executes for 300ms. and plan shows clustered index seek
if i replace * in SELECT clause to RESULT.TEST_NUMBER (covered with index) - then all become fast in first case too. this points to hdd io issues, but doesn't clarifies changing plan.
so, any ideas?
© Stack Overflow or respective owner