3 ms·
I've always understood that IN clauses are hard on query optimizers and should be re-written as correlated subqueries with EXISTS/NOT EXISTS, often for giant sp
by pjungwir 14y ago
I've always understood that IN clauses are hard on query optimizers and should be re-written as correlated subqueries with EXISTS/NOT EXISTS, often for giant speedups. But I've met lots of developers who have never seen this pattern before and get scared by it. Of course if you can also re-write it as a join, that's even easier.
- gaius 14y agoYou don't have to assume it, just look at the query plans! It's unlikely to be as simple as "IN bad, JOIN good". Edit: Ah, now I see that this article should really be titled "Working around Django's ORM with Postgres".