Skip to content

Commit cff60f2

Browse files
committed
Avoid creating PlaceHolderVars immediately within PlaceHolderVars.
Such a construction is useless since the lower PlaceHolderVar is already nullable; no need to make it more so. Noted while pursuing bug #6154. This is just a minor planner efficiency improvement, since the final plan will come out the same anyway after PHVs are flattened. So not worth the risk of back-patching.
1 parent f4a9da0 commit cff60f2

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/backend/optimizer/prep/prepjointree.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1411,6 +1411,12 @@ pullup_replace_vars_callback(Var *var,
14111411
/* Simple Vars always escape being wrapped */
14121412
wrap = false;
14131413
}
1414+
else if (newnode && IsA(newnode, PlaceHolderVar) &&
1415+
((PlaceHolderVar *) newnode)->phlevelsup == 0)
1416+
{
1417+
/* No need to wrap a PlaceHolderVar with another one, either */
1418+
wrap = false;
1419+
}
14141420
else if (rcon->wrap_non_vars)
14151421
{
14161422
/* Wrap all non-Vars in a PlaceHolderVar */
@@ -1420,10 +1426,16 @@ pullup_replace_vars_callback(Var *var,
14201426
{
14211427
/*
14221428
* If it contains a Var of current level, and does not contain
1423-
* any non-strict constructs, then it's certainly nullable and
1424-
* we don't need to insert a PlaceHolderVar. (Note: in future
1425-
* maybe we should insert PlaceHolderVars anyway, when a tlist
1426-
* item is expensive to evaluate?
1429+
* any non-strict constructs, then it's certainly nullable so
1430+
* we don't need to insert a PlaceHolderVar.
1431+
*
1432+
* This analysis could be tighter: in particular, a non-strict
1433+
* construct hidden within a lower-level PlaceHolderVar is not
1434+
* reason to add another PHV. But for now it doesn't seem
1435+
* worth the code to be more exact.
1436+
*
1437+
* Note: in future maybe we should insert a PlaceHolderVar
1438+
* anyway, if the tlist item is expensive to evaluate?
14271439
*/
14281440
if (contain_vars_of_level((Node *) newnode, 0) &&
14291441
!contain_nonstrict_functions((Node *) newnode))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy