I have a query that runs much slower (~ 5 minutes) when I run it with the default value enable_nestloop = true and enable_nestloop = false (~ 10 seconds).
Explain the result of the analysis for both cases:
Machine A nestloop = true - http://explain.depesz.com/s/nkj0 (~ 5 minutes) Machine A nestloop = false - http://explain.depesz.com/s/wBM (~ 10 seconds)
On another slightly slower machine, copying the database and leaving default to enable_nestloop = true takes ~ 20 seconds.
Machine B nestloop = true - (~ 20 seconds)
For all of the above cases, I guaranteed that I made ANALYZE before executing the queries. Other requests were not executed in parallel.
Both machines work with Postgres 8.4. Machine A runs Ubuntu 10.04 32 bit, while Machine B runs Ubuntu 8.04 32 bit.
Actual request is available here. This is a reporting query with many associations, since the database is mainly used for transaction processing.
Without resorting to creating something like materialized views, what can I do to make the scheduler do what I achieved by setting enable_nestloop = false?
From the research that I did, it seems that the reason the planner selects a seemingly suboptimal query is the huge difference between the estimated and actual lines. How can I approximate this figure?
, ?
, , B. ?