Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TRryH-0000D4-N9 for pgsql-performance@postgresql.org; Fri, 26 Oct 2012 22:01:41 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TRryG-0005fT-Hg for pgsql-performance@postgresql.org; Fri, 26 Oct 2012 22:01:41 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id q9QM1cOp003990; Fri, 26 Oct 2012 18:01:38 -0400 (EDT) From: Tom Lane To: Claudio Freire cc: sthomas@optionshouse.com, "pgsql-performance@postgresql.org" Subject: Re: Setting Statistics on Functional Indexes In-reply-to: References: <50881D73.100@optionshouse.com> <6668.1351105908@sss.pgh.pa.us> <508841FF.9040303@optionshouse.com> <5088478C.6000905@optionshouse.com> <1511.1351280130@sss.pgh.pa.us> <508AEB1A.2040001@optionshouse.com> <3040.1351285698@sss.pgh.pa.us> Comments: In-reply-to Claudio Freire message dated "Fri, 26 Oct 2012 18:19:05 -0300" Date: Fri, 26 Oct 2012 18:01:38 -0400 Message-ID: <3989.1351288898@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201210/329 X-Sequence-Number: 48288 Claudio Freire writes: > Because once you've accessed that last index page, it would be rather > trivial finding out how many duplicate tids are in that page and, with > a small CPU cost (no disk access if you don't query other index pages) > you could verify the assumption of near-uniqueness. I thought about that too, but I'm not sure how promising the idea is. In the first place, it's not clear when to stop counting duplicates, and in the second, I'm not sure we could get away with not visiting the heap to check for tuple liveness. There might be a lot of apparent duplicates in the index that just represent unreaped old versions of a frequently-updated endpoint tuple. (The existing code is capable of returning a "wrong" answer if the endpoint tuple is dead, but I don't think it matters much in most cases. I'm less sure such an argument could be made for dup-counting.) regards, tom lane