Gregory Stark <stark@enterprisedb.com> writes:
> The structure of your query is a whole series of left outer joins, the result
> of which is then (inner) joined with one more table. The outer joins return a
> whole lot of records but the inner join is only going to match a few of them.
Hmmm ... actually I see 6 tables inside the join-tree and four more
loose in the FROM-clause, ten relations altogether. Which means the OP
is falling foul of from_collapse_limit, and it's not investigating every
possible join order. Try setting from_collapse_limit to more than 10.
regards, tom lane