Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YSxUi-0003OA-Kg for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Mar 2015 00:49:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YSxUh-00061i-B8 for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Mar 2015 00:48:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YSxUg-00060s-Er for pgsql-bugs@postgresql.org; Wed, 04 Mar 2015 00:48:58 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YSxUX-0004u8-5l for pgsql-bugs@postgresql.org; Wed, 04 Mar 2015 00:48:57 +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 t240mkOj013313; Tue, 3 Mar 2015 19:48:46 -0500 From: Tom Lane To: Jeff Janes cc: Pg Bugs Subject: Re: Functional indexes with slow functions are misplanned In-reply-to: References: Comments: In-reply-to Jeff Janes message dated "Tue, 03 Mar 2015 14:58:03 -0800" Date: Tue, 03 Mar 2015 19:48:46 -0500 Message-ID: <13312.1425430126@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Jeff Janes writes: > When the results of an expression can be obtained from a functional index, > the expression never needs to be evaluated. But the planner doesn't seem > to know that. It thinks the expression is evaluated not only once per row, > but multiple times, presumably at each step as it descends the btree. Hmm ... there are a lot of things that are not done very well for functional indexes, but at least part of this has nothing to do with that. cost_index() thinks it can use list_difference_ptr() against the indexquals list to separate out which restriction conditions will be applied as filter conditions; but that hasn't worked reliably since the equivalence class machinery was invented. So there's about a 50-50 chance that equality index conditions will be charged as though they had to be evaluated at each row returned by the indexscan, though of course they are not. Usually this means no worse than one extra cpu_operator_cost per row, but with an expensive qual condition it could mean a lot more. I think that fully duplicating the logic to identify redundant quals that's in create_indexscan_plan() would likely be a mistake: the effort to prove quals redundant shouldn't be spent on what are only hypothetical index paths. But we could introduce the is_redundant_derived_clause check relatively cheaply, and that's what would matter far more of the time than the other things. Arguably this is a bug fix, but I'm nervous about possibly destabilizing plan choices in the back branches, so I'm inclined to change it in HEAD only. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs