Jérome Knöbl <jknobl@mandanet.ch> writes:
> I have some trouble with a very long query.
The amount of time taken by the optimizer goes up exponentially with
the number of tables being joined. If you are using a pre-6.5
version of Postgres then I'd recommend updating to 6.5; its optimizer
is considerably faster and less memory-hungry than prior releases.
You could also try reducing the GEQO threshold, which is the number
of tables at which the system stops trying to do exhaustive optimization
and changes to a heuristic planning method.
regards, tom lane