Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xnq8P-0008Ro-9a for pgsql-general@arkaria.postgresql.org; Mon, 10 Nov 2014 14:40:01 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xnq8O-0005va-Qy for pgsql-general@arkaria.postgresql.org; Mon, 10 Nov 2014 14:40:00 +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 1Xnq8N-0005vU-TC for pgsql-general@postgresql.org; Mon, 10 Nov 2014 14:40:00 +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 1Xnq8K-0006Ti-RW for pgsql-general@postgresql.org; Mon, 10 Nov 2014 14:39:58 +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 sAAEdNSb024417; Mon, 10 Nov 2014 09:39:23 -0500 From: Tom Lane To: Jehan-Guillaume de Rorthais cc: "pgsql-general@postgresql.org" Subject: Re: Strange avg value size for index on expression in pg_stats In-reply-to: <20141110115254.2997aaf8@erg> References: <20141110115254.2997aaf8@erg> Comments: In-reply-to Jehan-Guillaume de Rorthais message dated "Mon, 10 Nov 2014 11:52:54 +0100" Date: Mon, 10 Nov 2014 09:39:23 -0500 Message-ID: <24416.1415630363@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-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org Jehan-Guillaume de Rorthais writes: > While investigating about a wrong result with my btree bloat estimation query, > I found a strange stat deviation between the average size of a value in its > table and its average size in one index on the "lower" expression. ANALYZE doesn't look at the physical index at all. For an expression index, it will recompute the index expression at each sampled row, and then take statistics on those values. In the case you've got here, it's re-running the lower() function and looking at the uncompressed result. So that accounts for the discrepancy in average width stats. > This tiny difference is the source of a very bad estimation with the > Btree bloat estimation query when values are around an alignement > boundary. TBH, if that query is relying on ANALYZE width estimates to be accurate to the last byte, its reliability is going to be horrid anyway. regards, tom lane -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general