Karsten P <mr.mister123@hotmail.com> writes:
> i'm sorry i didn't check that first. it just won't work in my real-life
> example.
> though each part of the query is using an index-scan it is than using a
> 'normal' append
> instead of a merge-append, but i don't know why.
The "Subquery Scan" nodes shown in your real-life example indicate
that you're using views that the planner is unable to flatten
completely, and those are preventing detection that the index you want
to use would be helpful. The view you showed originally wouldn't be
that, so there is something you're doing that you left out. It looks
like your actual view contains some WHERE restrictions in the UNION
arms, which I think are enough to cause this problem. Even then,
though, the "Subquery Scan" nodes get optimized away in simple tests,
which means there's an additional optimization blocker. I'd look
closely at whether the output column types of the UNION arms match.
regards, tom lane