Re: An inefficient query caused by unnecessary PlaceHolderVar

From: wenhui qiu <qiuwenhuifx(at)gmail(dot)com>
To: Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>, James Coleman <jtc331(at)gmail(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: An inefficient query caused by unnecessary PlaceHolderVar
Date: 2024-11-27 10:00:33
Message-ID: CAGjGUALA4vPh6xYcSmvPB28f0VaSdWnXobOTmL0y+x8yi2VG6g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Richard
> BTW, since commit cb8e50a4a, we've chosen not to wrap a non-var
> expression if it contains Vars/PHVs of the pulled-up subquery and does
> not contain non-strict constructs. I wonder if we can apply the same
> optimization from this patch to non-var expressions: for a LATERAL
> subquery, if a non-var expression contains Vars/PHVs of the
> lowest_nullable_relids and does not contain non-strict constructs, it
>could also escape being wrapped. Any thoughts?
agree , The path tested and looks good to me,In addition, can the test
case have a multi-layer nested subquery(maybe) ?

Thanks

On Wed, Nov 27, 2024 at 4:46 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:

> On Fri, Nov 22, 2024 at 5:08 AM Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
> wrote:
> > The patch looks good to me, the implementation is concise and clear. I
> can't
> > imagine any visible overhead due to storing lowest_nullable_relids in
> this
> > context. The only nitpick I have is about this commentary:
> >
> > /*
> > * Simple Vars always escape being wrapped, unless they are
> > * lateral references to something outside the subquery being
> > - * pulled up. (Even then, we could omit the PlaceHolderVar if
> > - * the referenced rel is under the same lowest outer join, but
> > - * it doesn't seem worth the trouble to check that.)
> > + * pulled up and the referenced rel is not under the same
> > + * lowest outer join.
> > */
> >
> > It mentions "lowest outer join", as in the original version of the text.
> Would
> > it be more precise to mention nullable side of the outer join as well?
>
> Thank you for your review.
>
> I ended up using 'under the same lowest nulling outer join' to
> keep consistent with the wording used elsewhere. Please see the
> updated patch attached.
>
> BTW, since commit cb8e50a4a, we've chosen not to wrap a non-var
> expression if it contains Vars/PHVs of the pulled-up subquery and does
> not contain non-strict constructs. I wonder if we can apply the same
> optimization from this patch to non-var expressions: for a LATERAL
> subquery, if a non-var expression contains Vars/PHVs of the
> lowest_nullable_relids and does not contain non-strict constructs, it
> could also escape being wrapped. Any thoughts?
>
> Thanks
> Richard
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2024-11-27 10:27:42 Re: Improve the error message for logical replication of regular column to generated column.
Previous Message Anthonin Bonnefoy 2024-11-27 09:50:25 Add Pipelining support in psql