I have the following query which is taking about a minute to run:
SELECT * FROM main_i i JOIN main_p p ON p.item_id=i.id
WHERE COALESCE(p.provider_title_id, i.provider_title_id) = "X"
While this looks like a very easy query, it takes forever to run, and the only way I've been able to solve it is using the following approach:
SELECT * FROM main_i i JOIN main_p p ON p.item_id=i.id
WHERE p.provider_title_id = "X"
UNION
SELECT * FROM main_i i JOIN main_p p ON p.item_id=i.id
WHERE i.provider_title_id = "X" AND p.provider_title_id IS NULL
This finishes instantaneously, however the query seems so stupid that there must be a better way to do this.
What should I be using here?