Re: An inefficient query caused by unnecessary PlaceHolderVar

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Dmitry Dolgov <9erthalion6(at)gmail(dot)com>
Cc: 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-12-02 03:46:44
Message-ID: CAMbWs49T36=VrF0mBjiQXRmMCTOGzEsRgFULsiKX6TQMXXHX1g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Nov 27, 2024 at 5:45 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> 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.

Commit e032e4c7d computes the nullingrel data for each leaf RTE, and
we can leverage that to determine if the referenced rel is under the
same lowest nulling outer join: we just need to check if the
nullingrels of the subquery RTE are a subset of those of the lateral
referenced rel. This eliminates the need to introduce
lowest_nullable_side. Please see 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?

I still feel that we can apply a similar optimization to more complex
non-var expressions. I plan to explore that in a separate patch.

Thanks
Richard

Attachment Content-Type Size
v6-0001-Avoid-unnecessary-wrapping-for-Vars-and-PHVs.patch application/octet-stream 11.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2024-12-02 04:14:01 Re: Conflict detection for update_deleted in logical replication
Previous Message Tom Lane 2024-12-02 02:15:23 Re: CREATE SCHEMA ... CREATE DOMAIN support