sql server 2005 - What would make a table "slow?" -
what make 1 table substantially slower another? easiest illustrate:
query 1:
select top 1000 * call c join call_task ct on c.call_no=ct.call_no left join memo_clt m on m.doc_ref=ct.record , m.doc_type='clt' , m.line_no=1 left join memo_clt m2 on m2.doc_ref=ct.record , m2.doc_type='clt' , m2.line_no=2
query 2:
select top 1000 * call c left join ext_document_detail edd on edd.doc_type='clh' , edd.doc_ext_no=21 , edd.doc_ref=c.record left join ext_document_detail edsource on edsource.doc_type='clh' , edsource.doc_ext_no=22 , edsource.doc_ref=c.record
the structure of tables similar, , i'm accessing ext_document_detail similar join compared memo_clt table. yet second query takes 40 seconds, while other 1 takes 0 seconds.
both have clustered index on 3 keys i'm using join. memo_clt table has non-clustered index on it's record column though... that's difference can spot , don't think make big difference.
so why difference in speed here?
edit: since martin asked, here results of set statistics io on query 1:
table 'memo_clt'. scan count 2000, logical reads 6454, physical reads 0, read-ahead reads 0, lob logical reads 2385, lob physical reads 0, lob read-ahead reads 0. table 'call_task'. scan count 1, logical reads 39, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. table 'call'. scan count 1, logical reads 25, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
query 2:
table 'worktable'. scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. table 'ext_document_detail'. scan count 1001, logical reads 1507004, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. table 'call'. scan count 1, logical reads 24, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
right off bat 2 things striking me. first there no such table "worktable." second absolutely huge number of logical reads... cause that?
it's not tables causing differences in speed. structures of joins , supporting indexes on tables being queried.
to give reason difference in speed i'd need see execution plan. suspect 1 query utilizes indexes better another.
a place start see if have table scans. if have these , can optimize see increase in performance.
i give this article read. it's worth checking out , understanding..
Comments
Post a Comment