Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xjqg9-0002jt-5w for pgsql-admin@arkaria.postgresql.org; Thu, 30 Oct 2014 14:26:21 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xjqg8-0004cI-HA for pgsql-admin@arkaria.postgresql.org; Thu, 30 Oct 2014 14:26:20 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xjqg7-0004c8-Oc for pgsql-admin@postgresql.org; Thu, 30 Oct 2014 14:26:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xjqfz-0001Vh-UB for pgsql-admin@postgresql.org; Thu, 30 Oct 2014 14:26:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id s9UEPwvr019885; Thu, 30 Oct 2014 10:25:58 -0400 From: Tom Lane To: Rural Hunter cc: pgsql-admin@postgresql.org Subject: Re: wrong count estimation in query plan In-reply-to: <5451E60A.60009@gmail.com> References: <5451E60A.60009@gmail.com> Comments: In-reply-to Rural Hunter message dated "Thu, 30 Oct 2014 15:17:30 +0800" Date: Thu, 30 Oct 2014 10:25:57 -0400 Message-ID: <19884.1414679157@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org Rural Hunter 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 -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin