pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Clive Evans <cliveevans@ntlworld.com>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #14715: Constraint exclusion isn't used in function using language sql
Date: Fri, 23 Jun 2017 08:59:32 +0000
Message-ID: <bb9fb937-4b03-c004-e701-1fc6efcecb31@ntlworld.com> (raw)
In-Reply-To: <20170623.103957.31224862.horiguchi.kyotaro@lab.ntt.co.jp>
References: <20170621140056.27883.82221@wrigleys.postgresql.org>
	<20170623.103957.31224862.horiguchi.kyotaro@lab.ntt.co.jp>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <br>
    <br>
    <div class="moz-cite-prefix">On 23/06/17 01:39, Kyotaro HORIGUCHI
      wrote:<br>
    </div>
    <blockquote type="cite"
      cite="mid:20170623.103957.31224862.horiguchi.kyotaro@lab.ntt.co.jp">
      <pre wrap="">Hello,

At Wed, 21 Jun 2017 14:00:56 +0000, <a class="moz-txt-link-abbreviated" href="mailto:cliveevans@ntlworld.com">cliveevans@ntlworld.com</a> wrote in <a class="moz-txt-link-rfc2396E" href="mailto:20170621140056.27883.82221@wrigleys.postgresql.org">&lt;20170621140056.27883.82221@wrigleys.postgresql.org&gt;</a>
</pre>
      <blockquote type="cite">
        <pre wrap="">PostgreSQL version: 9.6.3
</pre>
      </blockquote>
      <pre wrap="">...
</pre>
      <blockquote type="cite">
        <pre wrap="">The same query written using PL/PGSQL will only scan the expected partition
tables.
</pre>
      </blockquote>
      <pre wrap="">
The two are different in that the parameters of the PL/PgSQL
function are regarded as constants at the time of planning of the
inner SQL statement, while those of the SQL function are
not. Constraint exclusion is considered while planning so the SQL
function doesn't get benefit of it.</pre>
    </blockquote>
    <br>
    I understand this, and I understand why. You can't plan based on
    what you don't yet know. I'm not entirely clear why the inner query
    can treat the parameter as a constant, whereas the outer one is
    forced to treat it as dynamic.<br>
    <br>
    I assume it's something to do with when the plan is created.
    Possibly it's an attempt to save the planning time and re-use the
    plan in the case of a 'normal' SQL function, although this seems
    like a trade off that may well have significant downsides - in this
    case obviously, but also others.<br>
    <br>
    Perhaps I'm looking for a new feature, rather than reporting a bug.
    Something that allows lazy planning, where there's a good chance
    that treating the parameters as constants is likely to improve the
    produced plan sufficiently to offset the additional overhead of
    repeatedly planning.<br>
    <br>
    thanks,<br>
    -- <br>
    Clive Evans<br>
  </body>
</html>




view thread (4+ messages)  latest in thread

Message-ID: <bb9fb937-4b03-c004-e701-1fc6efcecb31@ntlworld.com>
Permalink:  ../bb9fb937-4b03-c004-e701-1fc6efcecb31@ntlworld.com/
Also on:    postgresql.org/message-id/bb9fb937-4b03-c004-e701-1fc6efcecb31@ntlworld.com

 · 

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: cliveevans@ntlworld.com
  Subject: Re: BUG #14715: Constraint exclusion isn't used in function using language sql
  In-Reply-To: <bb9fb937-4b03-c004-e701-1fc6efcecb31@ntlworld.com>
  References: <20170621140056.27883.82221@wrigleys.postgresql.org> <20170623.103957.31224862.horiguchi.kyotaro@lab.ntt.co.jp> <bb9fb937-4b03-c004-e701-1fc6efcecb31@ntlworld.com>

* 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