pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeff Janes <jeff.janes@gmail.com>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: Functional indexes with slow functions are misplanned
Date: Tue, 03 Mar 2015 19:48:46 -0500
Message-ID: <13312.1425430126@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMkU=1yqL7vyW2-opqT8B3mctDeC=SXdn-WOKU0Uei-3L8Vhiw@mail.gmail.com>
References: <CAMkU=1yqL7vyW2-opqT8B3mctDeC=SXdn-WOKU0Uei-3L8Vhiw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

Jeff Janes <jeff.janes@gmail.com> 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



view thread (3+ messages)  latest in thread

Message-ID: <13312.1425430126@sss.pgh.pa.us>
Permalink:  ../13312.1425430126@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/13312.1425430126@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jeff.janes@gmail.com
  Subject: Re: Functional indexes with slow functions are misplanned
  In-Reply-To: <13312.1425430126@sss.pgh.pa.us>
  References: <CAMkU=1yqL7vyW2-opqT8B3mctDeC=SXdn-WOKU0Uei-3L8Vhiw@mail.gmail.com> <13312.1425430126@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox