Trying to run this query to find the intersection of two sets (users who post on one page and users who post on another). Unfortunately, this takes ridiculous amounts of time to complete (10+ minutes). Is there any way to reduce its complexity?
SELECT DISTINCT (user_id)
FROM facebook_post_comments
WHERE page_id = some_page_id
AND user_id IN ( SELECT DISTINCT(user_id)
FROM facebook_post_comments
WHERE page_id = some_other_page_id )
There’s a bug in MySQL where IN with a subquery sometimes gives very poor performance (fixed in MySQL 5.6).
Try this query using a
JOINinstead: