What I’m trying to do is speed up this query. Currently it’s about 15+ seconds slow. There are indexes on both r.email and v.sent as well as r.id, r.viewed and r.saved. EXPLAIN is showing both keys are in use, however I’m seeing that it’s using Using where; Using temporary; Using filesort.
Any ideas on improving this query?
SELECT r.id, r.top, r.email
FROM request as r
WHERE r.viewed = 0 AND r.saved = 0 AND r.email NOT IN (
SELECT v.sent FROM viewing as v WHERE v.sent = r.email
)
GROUP BY r.email
ORDER BY r.top desc, r.date
LIMIT 100;
MySQL uses a temporary table for multiple records in an
INclause. Try