Richard Rowell <richard(dot)rowell(at)gmail(dot)com> writes:
> I'm no backend guru, so I was hoping someone could explain what the original
> query-plan was doing. If all you need to know is if a row exists, why loop
> over all 3M rows? It seems very simplistic to assume the a LIMIT 1 clause
> on the end of all EXISTS subqueries would be a general case optimization...
[ squint... ] It should be assuming that already.
It looks like your case might have something to do with using or not
using a partial index. Can you extract a reproducible test case?
And what PG version is this exactly?
regards, tom lane