"Todd A. Cook" <tcook@xxxxxxxxxxxxxxxxxxxxx> writes: "Todd A. Cook" <tcook@xxxxxxxxxxxxxxxxxxxxx> writes: > QUERY PLAN > ------------------------------------------------------------------------- > HashAggregate (cost=1163446.13..1163448.63 rows=200 width=4) > -> Seq Scan on oom_tab (cost=0.00..867748.42 rows=59139542 width=4) > > The row estimitate for oom_tab is close to the actual value. Most of > the values are unique, however, so the result should have around 59M > rows too. ouch. it's estimating 200 distinct values. The estimates for distinct values are known to be unreliable but they shouldn't be *that* bad. Do you have a few hundred extremely common values and then a few million other values? What does this say: select * from pg_statistic where starelid = (select oid from pg_class where relname = 'oom_tab') You may need to reanalyze and maybe increase the statistics target (possibly by a lot). It may be interesting to compare the results of the above query before and after analyzing too. -- greg