A topics table contains 22k topics (not that much). A topics_ignore table for users contains only 33 topics. I am using this SQL query to get the topic count for each user without the ignored topics.
SELECT
COUNT(t.topic_id) AS num_topics
FROM topics t
LEFT JOIN topics_ignore i ON i.topic_id = t.topic_id AND i.user_id = 2
WHERE t.forum_id = 1
AND i.topic_id IS NULL
I added already two indexes on the topics table (topic_id, forum_id) and one index on topics_ignore table (topic_id)
The elapsed time is still 0.11015 seconds while other queries are in this range 0.00010s.
How can I benefit from using indexes or how to make this query faster?
Thank you
EXPLAIN SELECT ....rest of your query, and show the one that you mention that completes in .0001s along with EXPLAIN output for it, and show output ofSHOW CREATE TABLE topicsandSHOW CREATE TABLE topics_ignore