Peter Eisentraut <peter_e@gmx.net> writes:
> Yes, that is what autovacuum does. It detects changes in the database
> and runs analyze if failing to do so would cause PostgreSQL to behave
> badly. I don't know why it's not turned on by default.
Conservatism. It may well be on by default in some future release,
but that's not happening in the first release where the code exists
at all.
autovacuum isn't a 100% solution to the sort of problems Mark is
complaining about anyway: on a freshly-loaded table you could get bad
plans because autovacuum hadn't gotten to it yet.
One thing we could consider doing is boosting up the default no-stats
assumption about the number of distinct values in a column, to the point
where the planner wouldn't try a hash aggregate unless it had actual
stats. However, I'm unsure what negative side-effects that might have.
regards, tom lane