Re: wrong count estimation in query plan - Mailing list pgsql-admin

From Tom Lane
Subject Re: wrong count estimation in query plan
Date
Msg-id 19884.1414679157@sss.pgh.pa.us
Whole thread Raw
In response to wrong count estimation in query plan  (Rural Hunter <ruralhunter@gmail.com>)
Responses Re: wrong count estimation in query plan  (Rural Hunter <ruralhunter@gmail.com>)
List pgsql-admin
Rural Hunter <ruralhunter@gmail.com> writes:
> My question is, why I had to run analyze so many times to make the
> estimation be close with the actual count?

If ANALYZE doesn't scan the entire table then it updates the rowcount
estimate using a moving-average approach, rather than assuming that
the blocks it did look at are necessarily completely representative.
That causes the estimate to converge over multiple passes.  Since
it took so many cycles to get close to reality, we can conclude that
the table is several times larger than the number of blocks ANALYZE
is willing to sample ... which, for a table with only 1000 rows in
it, says you've got a bad table-bloat problem.  VACUUM FULL or CLUSTER
might be indicated.

            regards, tom lane


pgsql-admin by date:

Previous
From: Rural Hunter
Date:
Subject: wrong count estimation in query plan
Next
From: Rural Hunter
Date:
Subject: Re: wrong count estimation in query plan