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]
|