Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TR6Ms-0004aK-Mo for pgsql-performance@postgresql.org; Wed, 24 Oct 2012 19:11:54 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TR6Mn-0004W1-Th for pgsql-performance@postgresql.org; Wed, 24 Oct 2012 19:11:54 +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 q9OJBmNv006669; Wed, 24 Oct 2012 15:11:48 -0400 (EDT) From: Tom Lane To: sthomas@optionshouse.com cc: "pgsql-performance@postgresql.org" Subject: Re: Setting Statistics on Functional Indexes In-reply-to: <50881D73.100@optionshouse.com> References: <50881D73.100@optionshouse.com> Comments: In-reply-to Shaun Thomas message dated "Wed, 24 Oct 2012 11:55:15 -0500" Date: Wed, 24 Oct 2012 15:11:48 -0400 Message-ID: <6668.1351105908@sss.pgh.pa.us> X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201210/298 X-Sequence-Number: 48257 Shaun Thomas writes: > 1. Is there any way to specifically set stats on a functional index? Sure, the same way you would for a table. regression=# create table foo (f1 int, f2 int); CREATE TABLE regression=# create index fooi on foo ((f1 + f2)); CREATE INDEX regression=# \d fooi Index "public.fooi" Column | Type | Definition --------+---------+------------ expr | integer | (f1 + f2) btree, for table "public.foo" regression=# alter index fooi alter column expr set statistics 5000; ALTER INDEX The weak spot in this, and the reason this isn't "officially" supported, is that the column name for an index expression isn't set in stone. But as long as you check what it's called you can set its target. > 2. Why is the planner so ridiculously optimistic with functional > indexes, even in the case of much higher selectivity as reported by > pg_stats on the named columns? It's not particularly (not that you've even defined what you think "optimistic" is, much less mentioned what baseline you're comparing to). I tried your example on HEAD and I got what seemed pretty decent rowcount estimates ... regards, tom lane