Skip to content
Advertisement

JOIN is MUCH slower than a UNION, even with indexes

I have a query:

All tables have indexes.

Why is this query taking 4.5s across 6000 rows? Explain analyze output below:

I have a UNION query that does the same thing, but is much quicker (0.001s). I want to know more about why my JOIN query is so much slower:

Advertisement

Answer

OR is always difficult for the optimiser(s). Since you dont need any fields from the report table, you could tuck that away into an EXISTS() subquery, this will probably result in a bitmap-index scan.:


User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement