Re: An inefficient query caused by unnecessary PlaceHolderVar

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: James Coleman <jtc331(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: An inefficient query caused by unnecessary PlaceHolderVar
Date: 2024-06-21 02:35:30
Message-ID: CAMbWs48e4D-6vtqytrLnao-Qob=T1menGbb2Qo9uRsSjJRUtLA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Jan 15, 2024 at 1:50 PM Richard Guo <guofenglinux(at)gmail(dot)com> wrote:
> Updated this patch over 29f114b6ff, which indicates that we should apply
> the same rules for PHVs.

Here is a new rebase of this patch, with some tweaks to comments. I've
also updated the commit message to better explain the context.

To recap, this patch tries to avoid wrapping Vars and PHVs from subquery
output that are lateral references to something outside the subquery.
Typically this kind of wrapping is necessary when the Var/PHV references
the non-nullable side of the outer join from the nullable side, because
we need to ensure that it is evaluated at the right place and hence is
forced to null when the outer join should do so. But if the referenced
rel is under the same lowest nulling outer join, we can actually omit
the wrapping. The PHVs generated from such kind of wrapping imply
lateral dependencies and force us to resort to nestloop joins, so we'd
better get rid of them.

This patch performs this check by remembering the relids of the nullable
side of the lowest outer join the subquery is within. So I think it
improves the overall plan in the related cases with very little extra
cost.

Thanks
Richard

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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2024-06-21 02:52:57 Re: Pgoutput not capturing the generated columns
Previous Message jian he 2024-06-21 02:30:08 minor doc issue in 9.16.2.1.1. Boolean Predicate Check Expressions