Re: An inefficient query caused by unnecessary PlaceHolderVar - Mailing list pgsql-hackers

From Richard Guo
Subject Re: An inefficient query caused by unnecessary PlaceHolderVar
Date
Msg-id CAMbWs48e4D-6vtqytrLnao-Qob=T1menGbb2Qo9uRsSjJRUtLA@mail.gmail.com
Whole thread Raw
In response to Re: An inefficient query caused by unnecessary PlaceHolderVar  (Richard Guo <guofenglinux@gmail.com>)
List pgsql-hackers
On Mon, Jan 15, 2024 at 1:50 PM Richard Guo <guofenglinux@gmail.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

pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: minor doc issue in 9.16.2.1.1. Boolean Predicate Check Expressions
Next
From: Peter Smith
Date:
Subject: Re: Pgoutput not capturing the generated columns