Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit fa400cc

Browse files
ashutosh-bapatCommitfest Bot
authored and
Commitfest Bot
committed
Handle ConvertRowtypeExprs in pull_vars_clause().
This is a preparatory patch to fix the unresolved ConvertRowtypeExpr references in the targetlists. The patch allows pull_vars_clause() to return ConvertRowtypeExprs without recursing into those. Because of the recent work to support indexes and triggers on partitioned table, every caller of pull_var_clause() can encounter a ConvertRowtype embedding a whole-row reference. Current behavior is unchanged. Callers which don't need to recurse to ConvertRowtypeExprs should explicitly pass PVC_INCLUDE_CONVERTROWTYPES. The patch is taken from https://www.postgresql.org/message-id/CAFjFpRc8ZoDm0%2Bzhx%2BMckwGyEqkOzWcpVqbvjaxwdGarZSNrmA%40mail.gmail.com
1 parent a9a174c commit fa400cc

File tree

5 files changed

+53
-32
lines changed

5 files changed

+53
-32
lines changed

src/backend/nodes/nodeFuncs.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,3 +4840,35 @@ planstate_walk_members(PlanState **planstates, int nplans,
48404840

48414841
return false;
48424842
}
4843+
4844+
/*
4845+
* is_converted_whole_row_reference
4846+
* If the given node is a ConvertRowtypeExpr encapsulating a whole-row
4847+
* reference as implicit cast (i.e a parent's whole row reference
4848+
* translated by adjust_appendrel_attrs()), return true. Otherwise return
4849+
* false.
4850+
*/
4851+
bool
4852+
is_converted_whole_row_reference(Node *node)
4853+
{
4854+
ConvertRowtypeExpr *convexpr;
4855+
4856+
if (!node || !IsA(node, ConvertRowtypeExpr))
4857+
return false;
4858+
4859+
/* Traverse nested ConvertRowtypeExpr's. */
4860+
convexpr = castNode(ConvertRowtypeExpr, node);
4861+
while (convexpr->convertformat == COERCE_IMPLICIT_CAST &&
4862+
IsA(convexpr->arg, ConvertRowtypeExpr))
4863+
convexpr = castNode(ConvertRowtypeExpr, convexpr->arg);
4864+
4865+
if (IsA(convexpr->arg, Var))
4866+
{
4867+
Var *var = castNode(Var, convexpr->arg);
4868+
4869+
if (var->varattno == 0)
4870+
return true;
4871+
}
4872+
4873+
return false;
4874+
}

src/backend/optimizer/plan/setrefs.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ static List *set_windowagg_runcondition_references(PlannerInfo *root,
214214
List *runcondition,
215215
Plan *plan);
216216

217-
static bool is_converted_whole_row_reference(Node *node);
218-
219217
/*****************************************************************************
220218
*
221219
* SUBPLAN REFERENCES
@@ -3714,33 +3712,3 @@ extract_query_dependencies_walker(Node *node, PlannerInfo *context)
37143712
return expression_tree_walker(node, extract_query_dependencies_walker,
37153713
context);
37163714
}
3717-
3718-
/*
3719-
* is_converted_whole_row_reference
3720-
* If the given node is a ConvertRowtypeExpr encapsulating a whole-row
3721-
* reference as implicit cast, return true. Otherwise return false.
3722-
*/
3723-
static bool
3724-
is_converted_whole_row_reference(Node *node)
3725-
{
3726-
ConvertRowtypeExpr *convexpr;
3727-
3728-
if (!node || !IsA(node, ConvertRowtypeExpr))
3729-
return false;
3730-
3731-
/* Traverse nested ConvertRowtypeExpr's. */
3732-
convexpr = castNode(ConvertRowtypeExpr, node);
3733-
while (convexpr->convertformat == COERCE_IMPLICIT_CAST &&
3734-
IsA(convexpr->arg, ConvertRowtypeExpr))
3735-
convexpr = castNode(ConvertRowtypeExpr, convexpr->arg);
3736-
3737-
if (IsA(convexpr->arg, Var))
3738-
{
3739-
Var *var = castNode(Var, convexpr->arg);
3740-
3741-
if (var->varattno == 0)
3742-
return true;
3743-
}
3744-
3745-
return false;
3746-
}

src/backend/optimizer/util/var.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,11 @@ locate_var_of_level_walker(Node *node,
635635
* Vars within a PHV's expression are included in the result only
636636
* when PVC_RECURSE_PLACEHOLDERS is specified.
637637
*
638+
* ConvertRowtypeExprs encapsulating whole row references are handled
639+
* according to these bits in 'flags':
640+
* PVC_INCLUDE_CONVERTROWTYPES include ConvertRowtypeExprs in output list
641+
* by default - recurse into ConvertRowtypeExprs arguments
642+
*
638643
* GroupingFuncs are treated exactly like Aggrefs, and so do not need
639644
* their own flag bits.
640645
*
@@ -748,6 +753,19 @@ pull_var_clause_walker(Node *node, pull_var_clause_context *context)
748753
else
749754
elog(ERROR, "PlaceHolderVar found where not expected");
750755
}
756+
else if (is_converted_whole_row_reference(node))
757+
{
758+
if (context->flags & PVC_INCLUDE_CONVERTROWTYPES)
759+
{
760+
context->varlist = lappend(context->varlist, node);
761+
/* we do NOT descend into the contained expression */
762+
return false;
763+
}
764+
else
765+
{
766+
/* fall through to recurse into the ConvertRowtype's argument. */
767+
}
768+
}
751769
return expression_tree_walker(node, pull_var_clause_walker, context);
752770
}
753771

src/include/nodes/nodeFuncs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,5 @@ extern bool planstate_tree_walker_impl(struct PlanState *planstate,
221221
planstate_tree_walker_callback walker,
222222
void *context);
223223

224+
extern bool is_converted_whole_row_reference(Node *node);
224225
#endif /* NODEFUNCS_H */

src/include/optimizer/optimizer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ extern SortGroupClause *get_sortgroupref_clause_noerr(Index sortref,
192192
* output list */
193193
#define PVC_RECURSE_PLACEHOLDERS 0x0020 /* recurse into PlaceHolderVar
194194
* arguments */
195+
#define PVC_INCLUDE_CONVERTROWTYPES 0x0040 /* include ConvertRowtypeExprs in
196+
* output list */
195197

196198
extern Bitmapset *pull_varnos(PlannerInfo *root, Node *node);
197199
extern Bitmapset *pull_varnos_of_level(PlannerInfo *root, Node *node, int levelsup);

0 commit comments

Comments
 (0)