"Michal Dvoracek" <michal.dvoracek@capitol.cz> writes:
> this query runs very long time - after hour i cancelled it.
The EXPLAIN output is just about unreadable as you've posted it ---
could you fix that and repost? Also please provide EXPLAIN ANALYZE
output for all the cases that do finish in a reasonable amount of
time, especially the one where you made temporary tables. Also,
what are the table schemas (particularly, what indexes do they have)?
regards, tom lane