Jeremiah,
> Thanks to all, I had already run analyze. But the STATISTICS setting
> seems to have worked. I'm just not sure what it did..? Would anyone care
> to explain.
The STATISTICS setting improves the granularity of statistics kept by the
query planner on that column; increasing the granularity (i.e. more random
samples) can significantly improve things in cases where you have data whose
distribution is significantly skewed. Certainly whenever you see the query
planner using a slow nestloop becuase of a bad row-return estimate, it is one
of the first things to try.
Its drawbacks are 4-fold:
1) to keep it working, you will probably need to run ANALZYE more often than
you have been;
2) these ANALYZEs will take longer, and have the annoying side effect of
flooring your CPU while they do;
3) You will have to be sure that your vacuum plan includes vacuuming the
pg_statistic table as the database superuser, as that table will be getting
updated more often.
4) Currently, pg_dump does *not* back up statistics settings. So you will
need to save a script which does this in preparation for having to restore
your database.
Which is why the stats are set low by default.
--
Josh Berkus
Aglio Database Solutions
San Francisco