I have a script of the following structure:
SELECT SUM(CASE WHEN pf.info IS NOT NULL THEN 1 ELSE 0 END)
FROM summary s
LEFT JOIN (SELECT id, info FROM items GROUP BY id) pf ON s.id=pf.id
GROUP BY s.date
What I want is to count those id's which are in 'summary' and present in 'items'. 'items' have same id's repeated several times, that's why I do GROUP BY.
This script works as I want, but it is extremely slow, much slower than just doing straightforward LEFT JOIN (and counting each id several times). This doesn't seem to make sense since I need a smaller subspace of that and it should be easier.
So the question is: how to restructure the query to make it quicker?