Avoid OR for better PostgreSQL query performance
PostgreSQL query tuning is our daily bread at Cybertec, and once you have done some of that, you’ll start bristling whenever you see an
OR
in a query, because they are usually the cause for bad query performance.Of course there is a reason why there is an
OR
in SQL, and if you cannot avoid it, you have to use it. But you should be aware of the performance implications.In this article I’ll explore “good” and “bad”
OR
s and what you can do to avoid the latter.
Source: avoid OR for better PostgreSQL query performance, an article by Laurenz Albe.