Re: Does PostgreSQL do bind-peeking? Is `col like '%'` optimized-away by the planner?

From: Dominique Devienne <ddevienne(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Does PostgreSQL do bind-peeking? Is `col like '%'` optimized-away by the planner?
Date: 2022-01-21 17:08:03
Message-ID: CAFCRh-9pxkA=yiSvQZ8F84PphOStyEE7XHcaYjZyOb4EyO+xxQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jan 21, 2022 at 5:47 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Dominique Devienne <ddevienne(at)gmail(dot)com> writes:
> > Will the query planner be able to *peek* into the args, and turn `colN like $N` into a no-op?

Thanks for the replies, David and Tom.

> No. It would not do that even if the pattern were constant '%';
> it doesn't know that much about that particular function.

Interesting. Thanks.

> There is a notion of "custom plans" in which parameter values are
> inserted as constants, precisely to allow simplifications based on
> known constant values. But this particular case isn't implemented.

Where can I read more about this? And is it something the client has
any influence on?

> I am entirely unfamiliar with the terminology "bind-peeking"

I thought it was "standard speak" in the SQL world :)
I don't recall where I picked that up, to be honest.

Here's what seems like an official use in the Oracle PL/SQL doc:
https://oracle.readthedocs.io/en/latest/plsql/bind/bind-peeking.html

But that link does imply that what I thought could happen in Oracle,
i.e. that it could keep several plans for the same prepared statement,
that it would select at runtime based on the actual binds, is NOT
happening in Oracle either...

Thanks, --DD

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2022-01-21 17:22:56 Re: Does PostgreSQL do bind-peeking? Is `col like '%'` optimized-away by the planner?
Previous Message Alanoly Andrews 2022-01-21 17:02:44 RE: Using a different column name in a foreign table