Hi, On 30 August 2011 15:36, Szymon Kosok <szymon@xxxxxx> wrote: > Hello, > > I asked that question on StackOverflow, but didn't get any valuable > response, so I'll ask it here. :) > > I have such query: Could you please re-post your explain using this web site: http://explain.depesz.com/ and post links to Stackoverflow question? What is your Postgres version? Database settings? I see huge discrepancy between predicted and actual row numbers (like 1264420 vs 485). I would try the following: - check column statistics (pg_stasts) and focus on the following columns: n_distinct, null_frac, most_common_vals. If they are way-off from the actual values then you should tweak (auto)analyze process: run manual/auto analyse more often (check pg_stat_user_tables), increase default_statistics_target (per column or global) - try to disable nested loop join (set enable_nestloop=off) -- Ondrej Ivanic (ondrej.ivanic@xxxxxxxxx) -- Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance