You are here: Re: Tough Correlated Subquery issue « MsSQL Server « IT news, forums, messages
Re: Tough Correlated Subquery issue

Posted by Alexander Kuznetsov on 08/29/06 18:11

it might be that the optimizer underestimates the cardinality of the
subquery:

SELECT TOP 1 mi.id FROM messages mi
INNER JOIN identities i ON i.id=mi.identityid
INNER JOIN licenses l on i.licenseid=l.id
WHERE l.licenseKey = t1.licenseKey AND category = 'usage'
ORDER BY mi.created DESC

and comes up with a plan more appropriate for a small number of orws.
How many rows are there in the temporary table?
Are licenseKey AND category columns in one and the same table?
If yes, you could try to create a computed column named
licenseKey_category AS CAST(licenseKey AS VARCHAR(...)) + ' ' +
category,
create an index on it, and rewrite your subquery instead of

WHERE l.licenseKey = t1.licenseKey AND category = 'usage'

try to use

WHERE l1.licenseKey_category = CAST(licenseKey AS
VARCHAR(...)) + ' usage'

That's just one possibility.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация