On Mon, Jan 15, 2024 at 1:50 PM Richard Guo <guofengli...@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
v4-0001-Avoid-unnecessary-wrapping-for-Vars-and-PHVs.patch
Description: Binary data