PostgreSQL Source Code git master
Loading...
Searching...
No Matches
rewriteManip.c File Reference
#include "postgres.h"
#include "access/attmap.h"
#include "catalog/pg_type.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "nodes/pathnodes.h"
#include "nodes/plannodes.h"
#include "parser/parse_coerce.h"
#include "parser/parse_relation.h"
#include "parser/parsetree.h"
#include "rewrite/rewriteManip.h"
#include "utils/lsyscache.h"
Include dependency graph for rewriteManip.c:

Go to the source code of this file.

Data Structures

struct  contain_aggs_of_level_context
 
struct  locate_agg_of_level_context
 
struct  locate_windowfunc_context
 
struct  add_nulling_relids_context
 
struct  remove_nulling_relids_context
 
struct  OffsetVarNodes_context
 
struct  IncrementVarSublevelsUp_context
 
struct  SetVarReturningType_context
 
struct  rangeTableEntry_used_context
 
struct  map_variable_attnos_context
 
struct  ReplaceVarsFromTargetList_context
 

Functions

static bool contain_aggs_of_level_walker (Node *node, contain_aggs_of_level_context *context)
 
static bool locate_agg_of_level_walker (Node *node, locate_agg_of_level_context *context)
 
static bool contain_windowfuncs_walker (Node *node, void *context)
 
static bool locate_windowfunc_walker (Node *node, locate_windowfunc_context *context)
 
static bool checkExprHasSubLink_walker (Node *node, void *context)
 
static Nodeadd_nulling_relids_mutator (Node *node, add_nulling_relids_context *context)
 
static Noderemove_nulling_relids_mutator (Node *node, remove_nulling_relids_context *context)
 
bool contain_aggs_of_level (Node *node, int levelsup)
 
int locate_agg_of_level (Node *node, int levelsup)
 
bool contain_windowfuncs (Node *node)
 
int locate_windowfunc (Node *node)
 
bool checkExprHasSubLink (Node *node)
 
static bool contains_multiexpr_param (Node *node, void *context)
 
void CombineRangeTables (List **dst_rtable, List **dst_perminfos, List *src_rtable, List *src_perminfos)
 
static bool OffsetVarNodes_walker (Node *node, OffsetVarNodes_context *context)
 
void OffsetVarNodes (Node *node, int offset, int sublevels_up)
 
static bool ChangeVarNodes_walker (Node *node, ChangeVarNodes_context *context)
 
void ChangeVarNodesExtended (Node *node, int rt_index, int new_index, int sublevels_up, ChangeVarNodes_callback callback)
 
void ChangeVarNodes (Node *node, int rt_index, int new_index, int sublevels_up)
 
bool ChangeVarNodesWalkExpression (Node *node, ChangeVarNodes_context *context)
 
Relids adjust_relid_set (Relids relids, int oldrelid, int newrelid)
 
static bool IncrementVarSublevelsUp_walker (Node *node, IncrementVarSublevelsUp_context *context)
 
void IncrementVarSublevelsUp (Node *node, int delta_sublevels_up, int min_sublevels_up)
 
void IncrementVarSublevelsUp_rtable (List *rtable, int delta_sublevels_up, int min_sublevels_up)
 
static bool SetVarReturningType_walker (Node *node, SetVarReturningType_context *context)
 
static void SetVarReturningType (Node *node, int result_relation, int sublevels_up, VarReturningType returning_type)
 
static bool rangeTableEntry_used_walker (Node *node, rangeTableEntry_used_context *context)
 
bool rangeTableEntry_used (Node *node, int rt_index, int sublevels_up)
 
QuerygetInsertSelectQuery (Query *parsetree, Query ***subquery_ptr)
 
void AddQual (Query *parsetree, Node *qual)
 
void AddInvertedQual (Query *parsetree, Node *qual)
 
Nodeadd_nulling_relids (Node *node, const Bitmapset *target_relids, const Bitmapset *added_relids)
 
Noderemove_nulling_relids (Node *node, const Bitmapset *removable_relids, const Bitmapset *except_relids)
 
Nodereplace_rte_variables (Node *node, int target_varno, int sublevels_up, replace_rte_variables_callback callback, void *callback_arg, bool *outer_hasSubLinks)
 
Nodereplace_rte_variables_mutator (Node *node, replace_rte_variables_context *context)
 
static Nodemap_variable_attnos_mutator (Node *node, map_variable_attnos_context *context)
 
Nodemap_variable_attnos (Node *node, int target_varno, int sublevels_up, const AttrMap *attno_map, Oid to_rowtype, bool *found_whole_row)
 
static NodeReplaceVarsFromTargetList_callback (const Var *var, replace_rte_variables_context *context)
 
NodeReplaceVarFromTargetList (const Var *var, RangeTblEntry *target_rte, List *targetlist, int result_relation, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno)
 
NodeReplaceVarsFromTargetList (Node *node, int target_varno, int sublevels_up, RangeTblEntry *target_rte, List *targetlist, int result_relation, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno, bool *outer_hasSubLinks)
 

Function Documentation

◆ add_nulling_relids()

Node * add_nulling_relids ( Node node,
const Bitmapset target_relids,
const Bitmapset added_relids 
)

Definition at line 1239 of file rewriteManip.c.

1242{
1244
1245 context.target_relids = target_relids;
1246 context.added_relids = added_relids;
1247 context.sublevels_up = 0;
1250 &context,
1251 0);
1252}
#define query_or_expression_tree_mutator(n, m, c, f)
Definition nodeFuncs.h:173
static Node * add_nulling_relids_mutator(Node *node, add_nulling_relids_context *context)
const Bitmapset * target_relids
const Bitmapset * added_relids

References add_nulling_relids_mutator(), add_nulling_relids_context::added_relids, query_or_expression_tree_mutator, add_nulling_relids_context::sublevels_up, and add_nulling_relids_context::target_relids.

Referenced by deconstruct_distribute_oj_quals(), mark_nullable_by_grouping(), pullup_replace_vars_callback(), and transform_MERGE_to_join().

◆ add_nulling_relids_mutator()

static Node * add_nulling_relids_mutator ( Node node,
add_nulling_relids_context context 
)
static

Definition at line 1255 of file rewriteManip.c.

1257{
1258 if (node == NULL)
1259 return NULL;
1260 if (IsA(node, Var))
1261 {
1262 Var *var = (Var *) node;
1263
1264 if (var->varlevelsup == context->sublevels_up &&
1265 (context->target_relids == NULL ||
1266 bms_is_member(var->varno, context->target_relids)))
1267 {
1268 Relids newnullingrels = bms_union(var->varnullingrels,
1269 context->added_relids);
1270
1271 /* Copy the Var ... */
1272 var = copyObject(var);
1273 /* ... and replace the copy's varnullingrels field */
1274 var->varnullingrels = newnullingrels;
1275 return (Node *) var;
1276 }
1277 /* Otherwise fall through to copy the Var normally */
1278 }
1279 else if (IsA(node, PlaceHolderVar))
1280 {
1281 PlaceHolderVar *phv = (PlaceHolderVar *) node;
1282
1283 if (phv->phlevelsup == context->sublevels_up &&
1284 (context->target_relids == NULL ||
1285 bms_overlap(phv->phrels, context->target_relids)))
1286 {
1287 Relids newnullingrels = bms_union(phv->phnullingrels,
1288 context->added_relids);
1289
1290 /*
1291 * We don't modify the contents of the PHV's expression, only add
1292 * to phnullingrels. This corresponds to assuming that the PHV
1293 * will be evaluated at the same level as before, then perhaps be
1294 * nulled as it bubbles up. Hence, just flat-copy the node ...
1295 */
1297 memcpy(phv, node, sizeof(PlaceHolderVar));
1298 /* ... and replace the copy's phnullingrels field */
1299 phv->phnullingrels = newnullingrels;
1300 return (Node *) phv;
1301 }
1302 /* Otherwise fall through to copy the PlaceHolderVar normally */
1303 }
1304 else if (IsA(node, Query))
1305 {
1306 /* Recurse into RTE or sublink subquery */
1307 Query *newnode;
1308
1309 context->sublevels_up++;
1310 newnode = query_tree_mutator((Query *) node,
1312 context,
1313 0);
1314 context->sublevels_up--;
1315 return (Node *) newnode;
1316 }
1318}
bool bms_is_member(int x, const Bitmapset *a)
Definition bitmapset.c:645
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:252
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:710
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define expression_tree_mutator(n, m, c)
Definition nodeFuncs.h:155
#define query_tree_mutator(q, m, c, f)
Definition nodeFuncs.h:160
#define IsA(nodeptr, _type_)
Definition nodes.h:162
#define copyObject(obj)
Definition nodes.h:230
#define makeNode(_type_)
Definition nodes.h:159
static int fb(int x)
Definition nodes.h:133
int varno
Definition primnodes.h:270
Index varlevelsup
Definition primnodes.h:295

References add_nulling_relids_mutator(), add_nulling_relids_context::added_relids, bms_is_member(), bms_overlap(), bms_union(), copyObject, expression_tree_mutator, fb(), IsA, makeNode, memcpy(), query_tree_mutator, add_nulling_relids_context::sublevels_up, add_nulling_relids_context::target_relids, Var::varlevelsup, and Var::varno.

Referenced by add_nulling_relids(), and add_nulling_relids_mutator().

◆ AddInvertedQual()

void AddInvertedQual ( Query parsetree,
Node qual 
)

Definition at line 1215 of file rewriteManip.c.

1216{
1218
1219 if (qual == NULL)
1220 return;
1221
1222 /* Need not copy input qual, because AddQual will... */
1224 invqual->arg = (Expr *) qual;
1225 invqual->booltesttype = IS_NOT_TRUE;
1226 invqual->location = -1;
1227
1228 AddQual(parsetree, (Node *) invqual);
1229}
@ IS_NOT_TRUE
Definition primnodes.h:1999
void AddQual(Query *parsetree, Node *qual)

References AddQual(), fb(), IS_NOT_TRUE, and makeNode.

Referenced by CopyAndAddInvertedQual().

◆ AddQual()

void AddQual ( Query parsetree,
Node qual 
)

Definition at line 1147 of file rewriteManip.c.

1148{
1149 Node *copy;
1150
1151 if (qual == NULL)
1152 return;
1153
1154 if (parsetree->commandType == CMD_UTILITY)
1155 {
1156 /*
1157 * There's noplace to put the qual on a utility statement.
1158 *
1159 * If it's a NOTIFY, silently ignore the qual; this means that the
1160 * NOTIFY will execute, whether or not there are any qualifying rows.
1161 * While clearly wrong, this is much more useful than refusing to
1162 * execute the rule at all, and extra NOTIFY events are harmless for
1163 * typical uses of NOTIFY.
1164 *
1165 * If it isn't a NOTIFY, error out, since unconditional execution of
1166 * other utility stmts is unlikely to be wanted. (This case is not
1167 * currently allowed anyway, but keep the test for safety.)
1168 */
1169 if (parsetree->utilityStmt && IsA(parsetree->utilityStmt, NotifyStmt))
1170 return;
1171 else
1172 ereport(ERROR,
1174 errmsg("conditional utility statements are not implemented")));
1175 }
1176
1177 if (parsetree->setOperations != NULL)
1178 {
1179 /*
1180 * There's noplace to put the qual on a setop statement, either. (This
1181 * could be fixed, but right now the planner simply ignores any qual
1182 * condition on a setop query.)
1183 */
1184 ereport(ERROR,
1186 errmsg("conditional UNION/INTERSECT/EXCEPT statements are not implemented")));
1187 }
1188
1189 /* INTERSECT wants the original, but we need to copy - Jan */
1190 copy = copyObject(qual);
1191
1192 parsetree->jointree->quals = make_and_qual(parsetree->jointree->quals,
1193 copy);
1194
1195 /*
1196 * We had better not have stuck an aggregate into the WHERE clause.
1197 */
1199
1200 /*
1201 * Make sure query is marked correctly if added qual has sublinks. Need
1202 * not search qual when query is already marked.
1203 */
1204 if (!parsetree->hasSubLinks)
1205 parsetree->hasSubLinks = checkExprHasSubLink(copy);
1206}
#define Assert(condition)
Definition c.h:1002
int errcode(int sqlerrcode)
Definition elog.c:875
#define ERROR
Definition elog.h:40
#define ereport(elevel,...)
Definition elog.h:152
Node * make_and_qual(Node *qual1, Node *qual2)
Definition makefuncs.c:780
@ CMD_UTILITY
Definition nodes.h:278
static char * errmsg
bool checkExprHasSubLink(Node *node)
bool contain_aggs_of_level(Node *node, int levelsup)
Node * quals
Definition primnodes.h:2380
FromExpr * jointree
Definition parsenodes.h:187
Node * setOperations
Definition parsenodes.h:240
CmdType commandType
Definition parsenodes.h:124
Node * utilityStmt
Definition parsenodes.h:144

References Assert, checkExprHasSubLink(), CMD_UTILITY, Query::commandType, contain_aggs_of_level(), copyObject, ereport, errcode(), errmsg, ERROR, fb(), IsA, Query::jointree, make_and_qual(), FromExpr::quals, Query::setOperations, and Query::utilityStmt.

Referenced by AddInvertedQual(), RewriteQuery(), rewriteRuleAction(), and rewriteTargetView().

◆ adjust_relid_set()

Relids adjust_relid_set ( Relids  relids,
int  oldrelid,
int  newrelid 
)

Definition at line 760 of file rewriteManip.c.

761{
763 {
764 /* Ensure we have a modifiable copy */
765 relids = bms_copy(relids);
766 /* Remove old, add new */
767 relids = bms_del_member(relids, oldrelid);
769 relids = bms_add_member(relids, newrelid);
770 }
771 return relids;
772}
Bitmapset * bms_del_member(Bitmapset *a, int x)
Definition bitmapset.c:987
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition bitmapset.c:934
Bitmapset * bms_copy(const Bitmapset *a)
Definition bitmapset.c:123
#define IS_SPECIAL_VARNO(varno)
Definition primnodes.h:248

References bms_add_member(), bms_copy(), bms_del_member(), bms_is_member(), fb(), and IS_SPECIAL_VARNO.

Referenced by ChangeVarNodes_walker(), remove_rel_from_query(), remove_self_join_rel(), replace_relid_callback(), and update_eclasses().

◆ ChangeVarNodes()

◆ ChangeVarNodes_walker()

static bool ChangeVarNodes_walker ( Node node,
ChangeVarNodes_context context 
)
static

Definition at line 540 of file rewriteManip.c.

541{
542 if (node == NULL)
543 return false;
544
545 if (context->callback && context->callback(node, context))
546 return false;
547
548 if (IsA(node, Var))
549 {
550 Var *var = (Var *) node;
551
552 if (var->varlevelsup == context->sublevels_up)
553 {
554 if (var->varno == context->rt_index)
555 var->varno = context->new_index;
556 var->varnullingrels = adjust_relid_set(var->varnullingrels,
557 context->rt_index,
558 context->new_index);
559 if (var->varnosyn == context->rt_index)
560 var->varnosyn = context->new_index;
561 }
562 return false;
563 }
564 if (IsA(node, CurrentOfExpr))
565 {
566 CurrentOfExpr *cexpr = (CurrentOfExpr *) node;
567
568 if (context->sublevels_up == 0 &&
569 cexpr->cvarno == context->rt_index)
570 cexpr->cvarno = context->new_index;
571 return false;
572 }
573 if (IsA(node, RangeTblRef))
574 {
575 RangeTblRef *rtr = (RangeTblRef *) node;
576
577 if (context->sublevels_up == 0 &&
578 rtr->rtindex == context->rt_index)
579 rtr->rtindex = context->new_index;
580 /* the subquery itself is visited separately */
581 return false;
582 }
583 if (IsA(node, JoinExpr))
584 {
585 JoinExpr *j = (JoinExpr *) node;
586
587 if (context->sublevels_up == 0 &&
588 j->rtindex == context->rt_index)
589 j->rtindex = context->new_index;
590 /* fall through to examine children */
591 }
592 if (IsA(node, PlaceHolderVar))
593 {
595
596 if (phv->phlevelsup == context->sublevels_up)
597 {
598 phv->phrels = adjust_relid_set(phv->phrels,
599 context->rt_index,
600 context->new_index);
601 phv->phnullingrels = adjust_relid_set(phv->phnullingrels,
602 context->rt_index,
603 context->new_index);
604 }
605 /* fall through to examine children */
606 }
607 if (IsA(node, PlanRowMark))
608 {
609 PlanRowMark *rowmark = (PlanRowMark *) node;
610
611 if (context->sublevels_up == 0)
612 {
613 if (rowmark->rti == context->rt_index)
614 rowmark->rti = context->new_index;
615 if (rowmark->prti == context->rt_index)
616 rowmark->prti = context->new_index;
617 }
618 return false;
619 }
620 if (IsA(node, AppendRelInfo))
621 {
623
624 if (context->sublevels_up == 0)
625 {
626 if (appinfo->parent_relid == context->rt_index)
627 appinfo->parent_relid = context->new_index;
628 if (appinfo->child_relid == context->rt_index)
629 appinfo->child_relid = context->new_index;
630 }
631 /* fall through to examine children */
632 }
633 /* Shouldn't need to handle other planner auxiliary nodes here */
634 Assert(!IsA(node, SpecialJoinInfo));
635 Assert(!IsA(node, PlaceHolderInfo));
636 Assert(!IsA(node, MinMaxAggInfo));
637
638 if (IsA(node, Query))
639 {
640 /* Recurse into subselects */
641 bool result;
642
643 context->sublevels_up++;
645 context, 0);
646 context->sublevels_up--;
647 return result;
648 }
649 return expression_tree_walker(node, ChangeVarNodes_walker, context);
650}
uint32 result
int j
Definition isn.c:78
#define query_tree_walker(q, w, c, f)
Definition nodeFuncs.h:158
#define expression_tree_walker(n, w, c)
Definition nodeFuncs.h:153
Relids adjust_relid_set(Relids relids, int oldrelid, int newrelid)
static bool ChangeVarNodes_walker(Node *node, ChangeVarNodes_context *context)
Index parent_relid
Definition pathnodes.h:3301
ChangeVarNodes_callback callback
int rtindex
Definition primnodes.h:2364

References adjust_relid_set(), Assert, ChangeVarNodes_context::callback, ChangeVarNodes_walker(), CurrentOfExpr::cvarno, expression_tree_walker, fb(), IsA, j, ChangeVarNodes_context::new_index, PlanRowMark::prti, query_tree_walker, result, ChangeVarNodes_context::rt_index, PlanRowMark::rti, ChangeVarNodes_context::sublevels_up, Var::varlevelsup, and Var::varno.

Referenced by ChangeVarNodes_walker(), ChangeVarNodesExtended(), and ChangeVarNodesWalkExpression().

◆ ChangeVarNodesExtended()

void ChangeVarNodesExtended ( Node node,
int  rt_index,
int  new_index,
int  sublevels_up,
ChangeVarNodes_callback  callback 
)

Definition at line 665 of file rewriteManip.c.

667{
669
670 context.rt_index = rt_index;
671 context.new_index = new_index;
672 context.sublevels_up = sublevels_up;
673 context.callback = callback;
674
675 /*
676 * Must be prepared to start with a Query or a bare expression tree; if
677 * it's a Query, go straight to query_tree_walker to make sure that
678 * sublevels_up doesn't get incremented prematurely.
679 */
680 if (node && IsA(node, Query))
681 {
682 Query *qry = (Query *) node;
683
684 /*
685 * If we are starting at a Query, and sublevels_up is zero, then we
686 * must also fix rangetable indexes in the Query itself --- namely
687 * resultRelation, mergeTargetRelation, exclRelIndex and rowMarks
688 * entries. sublevels_up cannot be zero when recursing into a
689 * subquery, so there's no need to have the same logic inside
690 * ChangeVarNodes_walker.
691 */
692 if (sublevels_up == 0)
693 {
694 ListCell *l;
695
696 if (qry->resultRelation == rt_index)
697 qry->resultRelation = new_index;
698
699 if (qry->mergeTargetRelation == rt_index)
700 qry->mergeTargetRelation = new_index;
701
702 /* this is unlikely to ever be used, but ... */
703 if (qry->onConflict && qry->onConflict->exclRelIndex == rt_index)
704 qry->onConflict->exclRelIndex = new_index;
705
706 foreach(l, qry->rowMarks)
707 {
709
710 if (rc->rti == rt_index)
711 rc->rti = new_index;
712 }
713 }
714 query_tree_walker(qry, ChangeVarNodes_walker, &context, 0);
715 }
716 else
717 ChangeVarNodes_walker(node, &context);
718}
#define lfirst(lc)
Definition pg_list.h:172
List * rowMarks
Definition parsenodes.h:238
OnConflictExpr * onConflict
Definition parsenodes.h:208
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)

References ChangeVarNodes_context::callback, callback(), ChangeVarNodes_walker(), OnConflictExpr::exclRelIndex, IsA, lfirst, ChangeVarNodes_context::new_index, Query::onConflict, query_tree_walker, Query::rowMarks, ChangeVarNodes_context::rt_index, RowMarkClause::rti, and ChangeVarNodes_context::sublevels_up.

Referenced by ChangeVarNodes(), match_unique_clauses(), remove_rel_from_query(), remove_self_join_rel(), split_selfjoin_quals(), and update_eclasses().

◆ ChangeVarNodesWalkExpression()

bool ChangeVarNodesWalkExpression ( Node node,
ChangeVarNodes_context context 
)

Definition at line 745 of file rewriteManip.c.

746{
747 return ChangeVarNodes_walker(node, context);
748}

References ChangeVarNodes_walker().

Referenced by replace_relid_callback().

◆ checkExprHasSubLink()

bool checkExprHasSubLink ( Node node)

Definition at line 292 of file rewriteManip.c.

293{
294 /*
295 * If a Query is passed, examine it --- but we should not recurse into
296 * sub-Queries that are in its rangetable or CTE list.
297 */
300 NULL,
302}
#define query_or_expression_tree_walker(n, w, c, f)
Definition nodeFuncs.h:171
#define QTW_IGNORE_RC_SUBQUERIES
Definition nodeFuncs.h:24
static bool checkExprHasSubLink_walker(Node *node, void *context)

References checkExprHasSubLink_walker(), fb(), QTW_IGNORE_RC_SUBQUERIES, and query_or_expression_tree_walker.

Referenced by AddQual(), flatten_group_exprs_mutator(), flatten_join_alias_vars_mutator(), RelationBuildRowSecurity(), replace_rte_variables_mutator(), rewriteRuleAction(), and rewriteTargetView().

◆ checkExprHasSubLink_walker()

static bool checkExprHasSubLink_walker ( Node node,
void context 
)
static

Definition at line 305 of file rewriteManip.c.

306{
307 if (node == NULL)
308 return false;
309 if (IsA(node, SubLink))
310 return true; /* abort the tree traversal and return true */
312}

References checkExprHasSubLink_walker(), expression_tree_walker, fb(), and IsA.

Referenced by checkExprHasSubLink(), and checkExprHasSubLink_walker().

◆ CombineRangeTables()

void CombineRangeTables ( List **  dst_rtable,
List **  dst_perminfos,
List src_rtable,
List src_perminfos 
)

Definition at line 347 of file rewriteManip.c.

349{
350 ListCell *l;
351 int offset = list_length(*dst_perminfos);
352
353 if (offset > 0)
354 {
355 foreach(l, src_rtable)
356 {
358
359 if (rte->perminfoindex > 0)
360 rte->perminfoindex += offset;
361 }
362 }
363
366}
List * list_concat(List *list1, const List *list2)
Definition list.c:561
#define lfirst_node(type, lc)
Definition pg_list.h:176
static int list_length(const List *l)
Definition pg_list.h:152

References fb(), lfirst_node, list_concat(), and list_length().

Referenced by convert_EXISTS_sublink_to_join(), pull_up_simple_subquery(), pull_up_simple_union_all(), and rewriteRuleAction().

◆ contain_aggs_of_level()

bool contain_aggs_of_level ( Node node,
int  levelsup 
)

Definition at line 85 of file rewriteManip.c.

86{
88
89 context.sublevels_up = levelsup;
90
91 /*
92 * Must be prepared to start with a Query or a bare expression tree; if
93 * it's a Query, we don't want to increment sublevels_up.
94 */
97 &context,
98 0);
99}
static bool contain_aggs_of_level_walker(Node *node, contain_aggs_of_level_context *context)

References contain_aggs_of_level_walker(), query_or_expression_tree_walker, and contain_aggs_of_level_context::sublevels_up.

Referenced by AddQual(), checkTargetlistEntrySQL92(), and convert_EXISTS_to_ANY().

◆ contain_aggs_of_level_walker()

static bool contain_aggs_of_level_walker ( Node node,
contain_aggs_of_level_context context 
)
static

Definition at line 102 of file rewriteManip.c.

104{
105 if (node == NULL)
106 return false;
107 if (IsA(node, Aggref))
108 {
109 if (((Aggref *) node)->agglevelsup == context->sublevels_up)
110 return true; /* abort the tree traversal and return true */
111 /* else fall through to examine argument */
112 }
113 if (IsA(node, GroupingFunc))
114 {
115 if (((GroupingFunc *) node)->agglevelsup == context->sublevels_up)
116 return true;
117 /* else fall through to examine argument */
118 }
119 if (IsA(node, Query))
120 {
121 /* Recurse into subselects */
122 bool result;
123
124 context->sublevels_up++;
125 result = query_tree_walker((Query *) node,
127 context, 0);
128 context->sublevels_up--;
129 return result;
130 }
132 context);
133}

References contain_aggs_of_level_walker(), expression_tree_walker, fb(), IsA, query_tree_walker, result, and contain_aggs_of_level_context::sublevels_up.

Referenced by contain_aggs_of_level(), and contain_aggs_of_level_walker().

◆ contain_windowfuncs()

bool contain_windowfuncs ( Node node)

Definition at line 214 of file rewriteManip.c.

215{
216 /*
217 * Must be prepared to start with a Query or a bare expression tree; if
218 * it's a Query, we don't want to increment sublevels_up.
219 */
222 NULL,
223 0);
224}
static bool contain_windowfuncs_walker(Node *node, void *context)

References contain_windowfuncs_walker(), fb(), and query_or_expression_tree_walker.

Referenced by checkTargetlistEntrySQL92(), contain_window_function(), and transformWindowFuncCall().

◆ contain_windowfuncs_walker()

static bool contain_windowfuncs_walker ( Node node,
void context 
)
static

Definition at line 227 of file rewriteManip.c.

228{
229 if (node == NULL)
230 return false;
231 if (IsA(node, WindowFunc))
232 return true; /* abort the tree traversal and return true */
233 /* Mustn't recurse into subselects */
235}

References contain_windowfuncs_walker(), expression_tree_walker, fb(), and IsA.

Referenced by contain_windowfuncs(), and contain_windowfuncs_walker().

◆ contains_multiexpr_param()

static bool contains_multiexpr_param ( Node node,
void context 
)
static

Definition at line 321 of file rewriteManip.c.

322{
323 if (node == NULL)
324 return false;
325 if (IsA(node, Param))
326 {
327 if (((Param *) node)->paramkind == PARAM_MULTIEXPR)
328 return true; /* abort the tree traversal and return true */
329 return false;
330 }
332}
@ PARAM_MULTIEXPR
Definition primnodes.h:388
static bool contains_multiexpr_param(Node *node, void *context)

References contains_multiexpr_param(), expression_tree_walker, fb(), IsA, and PARAM_MULTIEXPR.

Referenced by contains_multiexpr_param(), and ReplaceVarFromTargetList().

◆ getInsertSelectQuery()

Query * getInsertSelectQuery ( Query parsetree,
Query ***  subquery_ptr 
)

Definition at line 1089 of file rewriteManip.c.

1090{
1094
1095 if (subquery_ptr)
1096 *subquery_ptr = NULL;
1097
1098 if (parsetree == NULL)
1099 return parsetree;
1100 if (parsetree->commandType != CMD_INSERT)
1101 return parsetree;
1102
1103 /*
1104 * Currently, this is ONLY applied to rule-action queries, and so we
1105 * expect to find the OLD and NEW placeholder entries in the given query.
1106 * If they're not there, it must be an INSERT/SELECT in which they've been
1107 * pushed down to the SELECT.
1108 */
1109 if (list_length(parsetree->rtable) >= 2 &&
1110 strcmp(rt_fetch(PRS2_OLD_VARNO, parsetree->rtable)->eref->aliasname,
1111 "old") == 0 &&
1112 strcmp(rt_fetch(PRS2_NEW_VARNO, parsetree->rtable)->eref->aliasname,
1113 "new") == 0)
1114 return parsetree;
1115 Assert(parsetree->jointree && IsA(parsetree->jointree, FromExpr));
1116 if (list_length(parsetree->jointree->fromlist) != 1)
1117 elog(ERROR, "expected to find SELECT subquery");
1118 rtr = (RangeTblRef *) linitial(parsetree->jointree->fromlist);
1119 if (!IsA(rtr, RangeTblRef))
1120 elog(ERROR, "expected to find SELECT subquery");
1121 selectrte = rt_fetch(rtr->rtindex, parsetree->rtable);
1122 if (!(selectrte->rtekind == RTE_SUBQUERY &&
1123 selectrte->subquery &&
1124 IsA(selectrte->subquery, Query) &&
1125 selectrte->subquery->commandType == CMD_SELECT))
1126 elog(ERROR, "expected to find SELECT subquery");
1127 selectquery = selectrte->subquery;
1128 if (list_length(selectquery->rtable) >= 2 &&
1129 strcmp(rt_fetch(PRS2_OLD_VARNO, selectquery->rtable)->eref->aliasname,
1130 "old") == 0 &&
1131 strcmp(rt_fetch(PRS2_NEW_VARNO, selectquery->rtable)->eref->aliasname,
1132 "new") == 0)
1133 {
1134 if (subquery_ptr)
1135 *subquery_ptr = &(selectrte->subquery);
1136 return selectquery;
1137 }
1138 elog(ERROR, "could not find rule placeholders");
1139 return NULL; /* not reached */
1140}
#define elog(elevel,...)
Definition elog.h:228
@ CMD_INSERT
Definition nodes.h:275
@ CMD_SELECT
Definition nodes.h:273
@ RTE_SUBQUERY
#define rt_fetch(rangetable_index, rangetable)
Definition parsetree.h:31
#define linitial(l)
Definition pg_list.h:178
#define PRS2_OLD_VARNO
Definition primnodes.h:251
#define PRS2_NEW_VARNO
Definition primnodes.h:252
List * fromlist
Definition primnodes.h:2379
List * rtable
Definition parsenodes.h:180

References Assert, CMD_INSERT, CMD_SELECT, Query::commandType, elog, ERROR, fb(), FromExpr::fromlist, IsA, Query::jointree, linitial, list_length(), PRS2_NEW_VARNO, PRS2_OLD_VARNO, rt_fetch, Query::rtable, and RTE_SUBQUERY.

Referenced by DefineQueryRewrite(), InsertRule(), make_ruledef(), rewriteRuleAction(), and transformRuleStmt().

◆ IncrementVarSublevelsUp()

void IncrementVarSublevelsUp ( Node node,
int  delta_sublevels_up,
int  min_sublevels_up 
)

Definition at line 880 of file rewriteManip.c.

882{
884
885 context.delta_sublevels_up = delta_sublevels_up;
886 context.min_sublevels_up = min_sublevels_up;
887
888 /*
889 * Must be prepared to start with a Query or a bare expression tree; if
890 * it's a Query, we don't want to increment sublevels_up.
891 */
894 &context,
896}
#define QTW_EXAMINE_RTES_BEFORE
Definition nodeFuncs.h:27
static bool IncrementVarSublevelsUp_walker(Node *node, IncrementVarSublevelsUp_context *context)

References IncrementVarSublevelsUp_context::delta_sublevels_up, IncrementVarSublevelsUp_walker(), IncrementVarSublevelsUp_context::min_sublevels_up, QTW_EXAMINE_RTES_BEFORE, and query_or_expression_tree_walker.

Referenced by assign_param_for_placeholdervar(), build_minmax_path(), convert_EXISTS_sublink_to_join(), convert_EXISTS_to_ANY(), extract_lateral_references(), finalize_grouping_exprs_walker(), flatten_group_exprs_mutator(), flatten_join_alias_vars_mutator(), generate_setop_from_pathqueries(), inline_cte_walker(), pull_up_simple_subquery(), pullup_replace_vars_callback(), replace_outer_agg(), replace_outer_grouping(), replace_outer_returning(), ReplaceVarsFromTargetList_callback(), rewriteSearchAndCycle(), substitute_actual_parameters_in_from_mutator(), and substitute_grouped_columns_mutator().

◆ IncrementVarSublevelsUp_rtable()

void IncrementVarSublevelsUp_rtable ( List rtable,
int  delta_sublevels_up,
int  min_sublevels_up 
)

Definition at line 903 of file rewriteManip.c.

905{
907
908 context.delta_sublevels_up = delta_sublevels_up;
909 context.min_sublevels_up = min_sublevels_up;
910
911 range_table_walker(rtable,
913 &context,
915}
#define range_table_walker(rt, w, c, f)
Definition nodeFuncs.h:163

References IncrementVarSublevelsUp_context::delta_sublevels_up, IncrementVarSublevelsUp_walker(), IncrementVarSublevelsUp_context::min_sublevels_up, QTW_EXAMINE_RTES_BEFORE, and range_table_walker.

Referenced by pull_up_simple_union_all().

◆ IncrementVarSublevelsUp_walker()

static bool IncrementVarSublevelsUp_walker ( Node node,
IncrementVarSublevelsUp_context context 
)
static

Definition at line 800 of file rewriteManip.c.

802{
803 if (node == NULL)
804 return false;
805 if (IsA(node, Var))
806 {
807 Var *var = (Var *) node;
808
809 if (var->varlevelsup >= context->min_sublevels_up)
810 var->varlevelsup += context->delta_sublevels_up;
811 return false; /* done here */
812 }
813 if (IsA(node, CurrentOfExpr))
814 {
815 /* this should not happen */
816 if (context->min_sublevels_up == 0)
817 elog(ERROR, "cannot push down CurrentOfExpr");
818 return false;
819 }
820 if (IsA(node, Aggref))
821 {
822 Aggref *agg = (Aggref *) node;
823
824 if (agg->agglevelsup >= context->min_sublevels_up)
825 agg->agglevelsup += context->delta_sublevels_up;
826 /* fall through to recurse into argument */
827 }
828 if (IsA(node, GroupingFunc))
829 {
830 GroupingFunc *grp = (GroupingFunc *) node;
831
832 if (grp->agglevelsup >= context->min_sublevels_up)
834 /* fall through to recurse into argument */
835 }
836 if (IsA(node, PlaceHolderVar))
837 {
839
840 if (phv->phlevelsup >= context->min_sublevels_up)
841 phv->phlevelsup += context->delta_sublevels_up;
842 /* fall through to recurse into argument */
843 }
844 if (IsA(node, ReturningExpr))
845 {
846 ReturningExpr *rexpr = (ReturningExpr *) node;
847
848 if (rexpr->retlevelsup >= context->min_sublevels_up)
849 rexpr->retlevelsup += context->delta_sublevels_up;
850 /* fall through to recurse into argument */
851 }
852 if (IsA(node, RangeTblEntry))
853 {
854 RangeTblEntry *rte = (RangeTblEntry *) node;
855
856 if (rte->rtekind == RTE_CTE)
857 {
858 if (rte->ctelevelsup >= context->min_sublevels_up)
860 }
861 return false; /* allow range_table_walker to continue */
862 }
863 if (IsA(node, Query))
864 {
865 /* Recurse into subselects */
866 bool result;
867
868 context->min_sublevels_up++;
869 result = query_tree_walker((Query *) node,
871 context,
873 context->min_sublevels_up--;
874 return result;
875 }
877}
@ RTE_CTE
Index agglevelsup
Definition primnodes.h:565

References IncrementVarSublevelsUp_context::delta_sublevels_up, elog, ERROR, expression_tree_walker, fb(), IncrementVarSublevelsUp_walker(), IsA, IncrementVarSublevelsUp_context::min_sublevels_up, QTW_EXAMINE_RTES_BEFORE, query_tree_walker, result, ReturningExpr::retlevelsup, RTE_CTE, and Var::varlevelsup.

Referenced by IncrementVarSublevelsUp(), IncrementVarSublevelsUp_rtable(), and IncrementVarSublevelsUp_walker().

◆ locate_agg_of_level()

int locate_agg_of_level ( Node node,
int  levelsup 
)

Definition at line 149 of file rewriteManip.c.

150{
152
153 context.agg_location = -1; /* in case we find nothing */
154 context.sublevels_up = levelsup;
155
156 /*
157 * Must be prepared to start with a Query or a bare expression tree; if
158 * it's a Query, we don't want to increment sublevels_up.
159 */
162 &context,
163 0);
164
165 return context.agg_location;
166}
static bool locate_agg_of_level_walker(Node *node, locate_agg_of_level_context *context)

References locate_agg_of_level_context::agg_location, fb(), locate_agg_of_level_walker(), query_or_expression_tree_walker, and locate_agg_of_level_context::sublevels_up.

Referenced by check_agg_arguments(), checkTargetlistEntrySQL92(), and parseCheckAggregates().

◆ locate_agg_of_level_walker()

static bool locate_agg_of_level_walker ( Node node,
locate_agg_of_level_context context 
)
static

Definition at line 169 of file rewriteManip.c.

171{
172 if (node == NULL)
173 return false;
174 if (IsA(node, Aggref))
175 {
176 if (((Aggref *) node)->agglevelsup == context->sublevels_up &&
177 ((Aggref *) node)->location >= 0)
178 {
179 context->agg_location = ((Aggref *) node)->location;
180 return true; /* abort the tree traversal and return true */
181 }
182 /* else fall through to examine argument */
183 }
184 if (IsA(node, GroupingFunc))
185 {
186 if (((GroupingFunc *) node)->agglevelsup == context->sublevels_up &&
187 ((GroupingFunc *) node)->location >= 0)
188 {
189 context->agg_location = ((GroupingFunc *) node)->location;
190 return true; /* abort the tree traversal and return true */
191 }
192 }
193 if (IsA(node, Query))
194 {
195 /* Recurse into subselects */
196 bool result;
197
198 context->sublevels_up++;
199 result = query_tree_walker((Query *) node,
201 context, 0);
202 context->sublevels_up--;
203 return result;
204 }
206}

References locate_agg_of_level_context::agg_location, expression_tree_walker, fb(), IsA, locate_agg_of_level_walker(), query_tree_walker, result, and locate_agg_of_level_context::sublevels_up.

Referenced by locate_agg_of_level(), and locate_agg_of_level_walker().

◆ locate_windowfunc()

int locate_windowfunc ( Node node)

Definition at line 251 of file rewriteManip.c.

252{
254
255 context.win_location = -1; /* in case we find nothing */
256
257 /*
258 * Must be prepared to start with a Query or a bare expression tree; if
259 * it's a Query, we don't want to increment sublevels_up.
260 */
263 &context,
264 0);
265
266 return context.win_location;
267}
static bool locate_windowfunc_walker(Node *node, locate_windowfunc_context *context)

References fb(), locate_windowfunc_walker(), query_or_expression_tree_walker, and locate_windowfunc_context::win_location.

Referenced by checkTargetlistEntrySQL92(), and transformWindowFuncCall().

◆ locate_windowfunc_walker()

static bool locate_windowfunc_walker ( Node node,
locate_windowfunc_context context 
)
static

Definition at line 270 of file rewriteManip.c.

271{
272 if (node == NULL)
273 return false;
274 if (IsA(node, WindowFunc))
275 {
276 if (((WindowFunc *) node)->location >= 0)
277 {
278 context->win_location = ((WindowFunc *) node)->location;
279 return true; /* abort the tree traversal and return true */
280 }
281 /* else fall through to examine argument */
282 }
283 /* Mustn't recurse into subselects */
285}

References expression_tree_walker, fb(), IsA, locate_windowfunc_walker(), and locate_windowfunc_context::win_location.

Referenced by locate_windowfunc(), and locate_windowfunc_walker().

◆ map_variable_attnos()

Node * map_variable_attnos ( Node node,
int  target_varno,
int  sublevels_up,
const AttrMap attno_map,
Oid  to_rowtype,
bool found_whole_row 
)

Definition at line 1682 of file rewriteManip.c.

1686{
1688
1689 context.target_varno = target_varno;
1690 context.sublevels_up = sublevels_up;
1691 context.attno_map = attno_map;
1692 context.to_rowtype = to_rowtype;
1693 context.found_whole_row = found_whole_row;
1694
1695 *found_whole_row = false;
1696
1697 /*
1698 * Must be prepared to start with a Query or a bare expression tree; if
1699 * it's a Query, we don't want to increment sublevels_up.
1700 */
1703 &context,
1704 0);
1705}
static Node * map_variable_attnos_mutator(Node *node, map_variable_attnos_context *context)

References map_variable_attnos_context::attno_map, map_variable_attnos_context::found_whole_row, map_variable_attnos_mutator(), query_or_expression_tree_mutator, map_variable_attnos_context::sublevels_up, map_variable_attnos_context::target_varno, and map_variable_attnos_context::to_rowtype.

Referenced by ATPrepAlterColumnType(), CompareIndexInfo(), createTableConstraints(), ExecInitMerge(), ExecInitPartitionInfo(), expandTableLikeClause(), generateClonedExtStatsStmt(), generateClonedIndexStmt(), map_partition_varattnos(), and MergeAttributes().

◆ map_variable_attnos_mutator()

static Node * map_variable_attnos_mutator ( Node node,
map_variable_attnos_context context 
)
static

Definition at line 1560 of file rewriteManip.c.

1562{
1563 if (node == NULL)
1564 return NULL;
1565 if (IsA(node, Var))
1566 {
1567 Var *var = (Var *) node;
1568
1569 if (var->varno == context->target_varno &&
1570 var->varlevelsup == context->sublevels_up)
1571 {
1572 /* Found a matching variable, make the substitution */
1574 int attno = var->varattno;
1575
1576 *newvar = *var; /* initially copy all fields of the Var */
1577
1578 if (attno > 0)
1579 {
1580 /* user-defined column, replace attno */
1581 if (attno > context->attno_map->maplen ||
1582 context->attno_map->attnums[attno - 1] == 0)
1583 elog(ERROR, "unexpected varattno %d in expression to be mapped",
1584 attno);
1585 newvar->varattno = context->attno_map->attnums[attno - 1];
1586 /* If the syntactic referent is same RTE, fix it too */
1587 if (newvar->varnosyn == context->target_varno)
1588 newvar->varattnosyn = newvar->varattno;
1589 }
1590 else if (attno == 0)
1591 {
1592 /* whole-row variable, warn caller */
1593 *(context->found_whole_row) = true;
1594
1595 /* If the caller expects us to convert the Var, do so. */
1596 if (OidIsValid(context->to_rowtype) &&
1597 context->to_rowtype != var->vartype)
1598 {
1600
1601 /* This certainly won't work for a RECORD variable. */
1602 Assert(var->vartype != RECORDOID);
1603
1604 /* Var itself is changed to the requested type. */
1605 newvar->vartype = context->to_rowtype;
1606
1607 /*
1608 * Add a conversion node on top to convert back to the
1609 * original type expected by the expression.
1610 */
1612 r->arg = (Expr *) newvar;
1613 r->resulttype = var->vartype;
1614 r->convertformat = COERCE_IMPLICIT_CAST;
1615 r->location = -1;
1616
1617 return (Node *) r;
1618 }
1619 }
1620 return (Node *) newvar;
1621 }
1622 /* otherwise fall through to copy the var normally */
1623 }
1624 else if (IsA(node, ConvertRowtypeExpr))
1625 {
1627 Var *var = (Var *) r->arg;
1628
1629 /*
1630 * If this is coercing a whole-row Var that we need to convert, then
1631 * just convert the Var without adding an extra ConvertRowtypeExpr.
1632 * Effectively we're simplifying var::parenttype::grandparenttype into
1633 * just var::grandparenttype. This avoids building stacks of CREs if
1634 * this function is applied repeatedly.
1635 */
1636 if (IsA(var, Var) &&
1637 var->varno == context->target_varno &&
1638 var->varlevelsup == context->sublevels_up &&
1639 var->varattno == 0 &&
1640 OidIsValid(context->to_rowtype) &&
1641 context->to_rowtype != var->vartype)
1642 {
1645
1646 /* whole-row variable, warn caller */
1647 *(context->found_whole_row) = true;
1648
1649 *newvar = *var; /* initially copy all fields of the Var */
1650
1651 /* This certainly won't work for a RECORD variable. */
1652 Assert(var->vartype != RECORDOID);
1653
1654 /* Var itself is changed to the requested type. */
1655 newvar->vartype = context->to_rowtype;
1656
1658 *newnode = *r; /* initially copy all fields of the CRE */
1659 newnode->arg = (Expr *) newvar;
1660
1661 return (Node *) newnode;
1662 }
1663 /* otherwise fall through to process the expression normally */
1664 }
1665 else if (IsA(node, Query))
1666 {
1667 /* Recurse into RTE subquery or not-yet-planned sublink subquery */
1668 Query *newnode;
1669
1670 context->sublevels_up++;
1671 newnode = query_tree_mutator((Query *) node,
1673 context,
1674 0);
1675 context->sublevels_up--;
1676 return (Node *) newnode;
1677 }
1679}
#define OidIsValid(objectId)
Definition c.h:917
#define palloc_object(type)
Definition fe_memutils.h:89
@ COERCE_IMPLICIT_CAST
Definition primnodes.h:759
int maplen
Definition attmap.h:37
AttrNumber * attnums
Definition attmap.h:36
AttrNumber varattno
Definition primnodes.h:275

References ConvertRowtypeExpr::arg, Assert, map_variable_attnos_context::attno_map, AttrMap::attnums, COERCE_IMPLICIT_CAST, elog, ERROR, expression_tree_mutator, fb(), map_variable_attnos_context::found_whole_row, IsA, ConvertRowtypeExpr::location, makeNode, map_variable_attnos_mutator(), AttrMap::maplen, OidIsValid, palloc_object, query_tree_mutator, ConvertRowtypeExpr::resulttype, map_variable_attnos_context::sublevels_up, map_variable_attnos_context::target_varno, map_variable_attnos_context::to_rowtype, Var::varattno, Var::varlevelsup, and Var::varno.

Referenced by map_variable_attnos(), and map_variable_attnos_mutator().

◆ OffsetVarNodes()

void OffsetVarNodes ( Node node,
int  offset,
int  sublevels_up 
)

Definition at line 476 of file rewriteManip.c.

477{
479
480 context.offset = offset;
481 context.sublevels_up = sublevels_up;
482
483 /*
484 * Must be prepared to start with a Query or a bare expression tree; if
485 * it's a Query, go straight to query_tree_walker to make sure that
486 * sublevels_up doesn't get incremented prematurely.
487 */
488 if (node && IsA(node, Query))
489 {
490 Query *qry = (Query *) node;
491
492 /*
493 * If we are starting at a Query, and sublevels_up is zero, then we
494 * must also fix rangetable indexes in the Query itself --- namely
495 * resultRelation, mergeTargetRelation, exclRelIndex and rowMarks
496 * entries. sublevels_up cannot be zero when recursing into a
497 * subquery, so there's no need to have the same logic inside
498 * OffsetVarNodes_walker.
499 */
500 if (sublevels_up == 0)
501 {
502 ListCell *l;
503
504 if (qry->resultRelation)
505 qry->resultRelation += offset;
506
507 if (qry->mergeTargetRelation)
508 qry->mergeTargetRelation += offset;
509
510 if (qry->onConflict && qry->onConflict->exclRelIndex)
511 qry->onConflict->exclRelIndex += offset;
512
513 foreach(l, qry->rowMarks)
514 {
516
517 rc->rti += offset;
518 }
519 }
520 query_tree_walker(qry, OffsetVarNodes_walker, &context, 0);
521 }
522 else
523 OffsetVarNodes_walker(node, &context);
524}
static bool OffsetVarNodes_walker(Node *node, OffsetVarNodes_context *context)

References OnConflictExpr::exclRelIndex, IsA, lfirst, OffsetVarNodes_context::offset, OffsetVarNodes_walker(), Query::onConflict, query_tree_walker, Query::rowMarks, RowMarkClause::rti, and OffsetVarNodes_context::sublevels_up.

Referenced by convert_EXISTS_sublink_to_join(), pull_up_simple_subquery(), and rewriteRuleAction().

◆ OffsetVarNodes_walker()

static bool OffsetVarNodes_walker ( Node node,
OffsetVarNodes_context context 
)
static

Definition at line 388 of file rewriteManip.c.

389{
390 if (node == NULL)
391 return false;
392 if (IsA(node, Var))
393 {
394 Var *var = (Var *) node;
395
396 if (var->varlevelsup == context->sublevels_up)
397 {
398 var->varno += context->offset;
399 var->varnullingrels = bms_offset_members(var->varnullingrels,
400 context->offset);
401 if (var->varnosyn > 0)
402 var->varnosyn += context->offset;
403 }
404 return false;
405 }
406 if (IsA(node, CurrentOfExpr))
407 {
408 CurrentOfExpr *cexpr = (CurrentOfExpr *) node;
409
410 if (context->sublevels_up == 0)
411 cexpr->cvarno += context->offset;
412 return false;
413 }
414 if (IsA(node, RangeTblRef))
415 {
416 RangeTblRef *rtr = (RangeTblRef *) node;
417
418 if (context->sublevels_up == 0)
419 rtr->rtindex += context->offset;
420 /* the subquery itself is visited separately */
421 return false;
422 }
423 if (IsA(node, JoinExpr))
424 {
425 JoinExpr *j = (JoinExpr *) node;
426
427 if (j->rtindex && context->sublevels_up == 0)
428 j->rtindex += context->offset;
429 /* fall through to examine children */
430 }
431 if (IsA(node, PlaceHolderVar))
432 {
434
435 if (phv->phlevelsup == context->sublevels_up)
436 {
437 phv->phrels = bms_offset_members(phv->phrels,
438 context->offset);
439 phv->phnullingrels = bms_offset_members(phv->phnullingrels,
440 context->offset);
441 }
442 /* fall through to examine children */
443 }
444 if (IsA(node, AppendRelInfo))
445 {
447
448 if (context->sublevels_up == 0)
449 {
450 appinfo->parent_relid += context->offset;
451 appinfo->child_relid += context->offset;
452 }
453 /* fall through to examine children */
454 }
455 /* Shouldn't need to handle other planner auxiliary nodes here */
456 Assert(!IsA(node, PlanRowMark));
457 Assert(!IsA(node, SpecialJoinInfo));
458 Assert(!IsA(node, PlaceHolderInfo));
459 Assert(!IsA(node, MinMaxAggInfo));
460
461 if (IsA(node, Query))
462 {
463 /* Recurse into subselects */
464 bool result;
465
466 context->sublevels_up++;
468 context, 0);
469 context->sublevels_up--;
470 return result;
471 }
472 return expression_tree_walker(node, OffsetVarNodes_walker, context);
473}
Bitmapset * bms_offset_members(const Bitmapset *a, int offset)
Definition bitmapset.c:419

References Assert, bms_offset_members(), CurrentOfExpr::cvarno, expression_tree_walker, fb(), IsA, j, OffsetVarNodes_context::offset, OffsetVarNodes_walker(), query_tree_walker, result, OffsetVarNodes_context::sublevels_up, Var::varlevelsup, and Var::varno.

Referenced by OffsetVarNodes(), and OffsetVarNodes_walker().

◆ rangeTableEntry_used()

bool rangeTableEntry_used ( Node node,
int  rt_index,
int  sublevels_up 
)

Definition at line 1057 of file rewriteManip.c.

1058{
1060
1061 context.rt_index = rt_index;
1062 context.sublevels_up = sublevels_up;
1063
1064 /*
1065 * Must be prepared to start with a Query or a bare expression tree; if
1066 * it's a Query, we don't want to increment sublevels_up.
1067 */
1070 &context,
1071 0);
1072}
static bool rangeTableEntry_used_walker(Node *node, rangeTableEntry_used_context *context)

References query_or_expression_tree_walker, rangeTableEntry_used_walker(), rangeTableEntry_used_context::rt_index, and rangeTableEntry_used_context::sublevels_up.

Referenced by fireRIRrules(), matchLocks(), rewriteRuleAction(), and transformRuleStmt().

◆ rangeTableEntry_used_walker()

static bool rangeTableEntry_used_walker ( Node node,
rangeTableEntry_used_context context 
)
static

Definition at line 991 of file rewriteManip.c.

993{
994 if (node == NULL)
995 return false;
996 if (IsA(node, Var))
997 {
998 Var *var = (Var *) node;
999
1000 if (var->varlevelsup == context->sublevels_up &&
1001 (var->varno == context->rt_index ||
1002 bms_is_member(context->rt_index, var->varnullingrels)))
1003 return true;
1004 return false;
1005 }
1006 if (IsA(node, CurrentOfExpr))
1007 {
1008 CurrentOfExpr *cexpr = (CurrentOfExpr *) node;
1009
1010 if (context->sublevels_up == 0 &&
1011 cexpr->cvarno == context->rt_index)
1012 return true;
1013 return false;
1014 }
1015 if (IsA(node, RangeTblRef))
1016 {
1017 RangeTblRef *rtr = (RangeTblRef *) node;
1018
1019 if (rtr->rtindex == context->rt_index &&
1020 context->sublevels_up == 0)
1021 return true;
1022 /* the subquery itself is visited separately */
1023 return false;
1024 }
1025 if (IsA(node, JoinExpr))
1026 {
1027 JoinExpr *j = (JoinExpr *) node;
1028
1029 if (j->rtindex == context->rt_index &&
1030 context->sublevels_up == 0)
1031 return true;
1032 /* fall through to examine children */
1033 }
1034 /* Shouldn't need to handle planner auxiliary nodes here */
1035 Assert(!IsA(node, PlaceHolderVar));
1036 Assert(!IsA(node, PlanRowMark));
1037 Assert(!IsA(node, SpecialJoinInfo));
1038 Assert(!IsA(node, AppendRelInfo));
1039 Assert(!IsA(node, PlaceHolderInfo));
1040 Assert(!IsA(node, MinMaxAggInfo));
1041
1042 if (IsA(node, Query))
1043 {
1044 /* Recurse into subselects */
1045 bool result;
1046
1047 context->sublevels_up++;
1049 context, 0);
1050 context->sublevels_up--;
1051 return result;
1052 }
1054}

References Assert, bms_is_member(), CurrentOfExpr::cvarno, expression_tree_walker, fb(), IsA, j, query_tree_walker, rangeTableEntry_used_walker(), result, rangeTableEntry_used_context::rt_index, rangeTableEntry_used_context::sublevels_up, Var::varlevelsup, and Var::varno.

Referenced by rangeTableEntry_used(), and rangeTableEntry_used_walker().

◆ remove_nulling_relids()

Node * remove_nulling_relids ( Node node,
const Bitmapset removable_relids,
const Bitmapset except_relids 
)

◆ remove_nulling_relids_mutator()

static Node * remove_nulling_relids_mutator ( Node node,
remove_nulling_relids_context context 
)
static

Definition at line 1343 of file rewriteManip.c.

1345{
1346 if (node == NULL)
1347 return NULL;
1348 if (IsA(node, Var))
1349 {
1350 Var *var = (Var *) node;
1351
1352 if (var->varlevelsup == context->sublevels_up &&
1353 !bms_is_member(var->varno, context->except_relids) &&
1354 bms_overlap(var->varnullingrels, context->removable_relids))
1355 {
1356 /* Copy the Var ... */
1357 var = copyObject(var);
1358 /* ... and replace the copy's varnullingrels field */
1359 var->varnullingrels = bms_difference(var->varnullingrels,
1360 context->removable_relids);
1361 return (Node *) var;
1362 }
1363 /* Otherwise fall through to copy the Var normally */
1364 }
1365 else if (IsA(node, PlaceHolderVar))
1366 {
1367 PlaceHolderVar *phv = (PlaceHolderVar *) node;
1368
1369 if (phv->phlevelsup == context->sublevels_up &&
1370 !bms_overlap(phv->phrels, context->except_relids))
1371 {
1372 /*
1373 * Note: it might seem desirable to remove the PHV altogether if
1374 * phnullingrels goes to empty. Currently we dare not do that
1375 * because we use PHVs in some cases to enforce separate identity
1376 * of subexpressions; see wrap_option usages in prepjointree.c.
1377 */
1378 /* Copy the PlaceHolderVar and mutate what's below ... */
1379 phv = (PlaceHolderVar *)
1382 context);
1383 /* ... and replace the copy's phnullingrels field */
1384 phv->phnullingrels = bms_difference(phv->phnullingrels,
1385 context->removable_relids);
1386 /* We must also update phrels, if it contains a removable RTI */
1387 phv->phrels = bms_difference(phv->phrels,
1388 context->removable_relids);
1389 Assert(!bms_is_empty(phv->phrels));
1390 return (Node *) phv;
1391 }
1392 /* Otherwise fall through to copy the PlaceHolderVar normally */
1393 }
1394 else if (IsA(node, Query))
1395 {
1396 /* Recurse into RTE or sublink subquery */
1397 Query *newnode;
1398
1399 context->sublevels_up++;
1400 newnode = query_tree_mutator((Query *) node,
1402 context,
1403 0);
1404 context->sublevels_up--;
1405 return (Node *) newnode;
1406 }
1408}
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
Definition bitmapset.c:347
#define bms_is_empty(a)
Definition bitmapset.h:119
Relids phnullingrels
Definition pathnodes.h:3128

References Assert, bms_difference(), bms_is_empty, bms_is_member(), bms_overlap(), copyObject, remove_nulling_relids_context::except_relids, expression_tree_mutator, fb(), IsA, query_tree_mutator, remove_nulling_relids_context::removable_relids, remove_nulling_relids_mutator(), remove_nulling_relids_context::sublevels_up, Var::varlevelsup, and Var::varno.

Referenced by remove_nulling_relids(), and remove_nulling_relids_mutator().

◆ replace_rte_variables()

Node * replace_rte_variables ( Node node,
int  target_varno,
int  sublevels_up,
replace_rte_variables_callback  callback,
void callback_arg,
bool outer_hasSubLinks 
)

Definition at line 1434 of file rewriteManip.c.

1438{
1439 Node *result;
1441
1442 context.callback = callback;
1443 context.callback_arg = callback_arg;
1444 context.target_varno = target_varno;
1445 context.sublevels_up = sublevels_up;
1446
1447 /*
1448 * We try to initialize inserted_sublink to true if there is no need to
1449 * detect new sublinks because the query already has some.
1450 */
1451 if (node && IsA(node, Query))
1452 context.inserted_sublink = ((Query *) node)->hasSubLinks;
1453 else if (outer_hasSubLinks)
1454 context.inserted_sublink = *outer_hasSubLinks;
1455 else
1456 context.inserted_sublink = false;
1457
1458 /*
1459 * Must be prepared to start with a Query or a bare expression tree; if
1460 * it's a Query, we don't want to increment sublevels_up.
1461 */
1464 &context,
1465 0);
1466
1467 if (context.inserted_sublink)
1468 {
1469 if (result && IsA(result, Query))
1470 ((Query *) result)->hasSubLinks = true;
1471 else if (outer_hasSubLinks)
1472 *outer_hasSubLinks = true;
1473 else
1474 elog(ERROR, "replace_rte_variables inserted a SubLink, but has noplace to record it");
1475 }
1476
1477 return result;
1478}
Node * replace_rte_variables_mutator(Node *node, replace_rte_variables_context *context)
replace_rte_variables_callback callback

References replace_rte_variables_context::callback, callback(), replace_rte_variables_context::callback_arg, elog, ERROR, replace_rte_variables_context::inserted_sublink, IsA, query_or_expression_tree_mutator, replace_rte_variables_mutator(), result, replace_rte_variables_context::sublevels_up, and replace_rte_variables_context::target_varno.

Referenced by pullup_replace_vars(), pullup_replace_vars_subquery(), and ReplaceVarsFromTargetList().

◆ replace_rte_variables_mutator()

Node * replace_rte_variables_mutator ( Node node,
replace_rte_variables_context context 
)

Definition at line 1481 of file rewriteManip.c.

1483{
1484 if (node == NULL)
1485 return NULL;
1486 if (IsA(node, Var))
1487 {
1488 Var *var = (Var *) node;
1489
1490 if (var->varno == context->target_varno &&
1491 var->varlevelsup == context->sublevels_up)
1492 {
1493 /* Found a matching variable, make the substitution */
1494 Node *newnode;
1495
1496 newnode = context->callback(var, context);
1497 /* Detect if we are adding a sublink to query */
1498 if (!context->inserted_sublink)
1500 return newnode;
1501 }
1502 /* otherwise fall through to copy the var normally */
1503 }
1504 else if (IsA(node, Query))
1505 {
1506 /* Recurse into RTE subquery or not-yet-planned sublink subquery */
1507 Query *newnode;
1509
1510 context->sublevels_up++;
1512 context->inserted_sublink = ((Query *) node)->hasSubLinks;
1513 newnode = query_tree_mutator((Query *) node,
1515 context,
1516 0);
1517 newnode->hasSubLinks |= context->inserted_sublink;
1519 context->sublevels_up--;
1520 return (Node *) newnode;
1521 }
1523}

References replace_rte_variables_context::callback, checkExprHasSubLink(), expression_tree_mutator, fb(), replace_rte_variables_context::inserted_sublink, IsA, query_tree_mutator, replace_rte_variables_mutator(), replace_rte_variables_context::sublevels_up, replace_rte_variables_context::target_varno, Var::varlevelsup, and Var::varno.

Referenced by replace_rte_variables(), and replace_rte_variables_mutator().

◆ ReplaceVarFromTargetList()

Node * ReplaceVarFromTargetList ( const Var var,
RangeTblEntry target_rte,
List targetlist,
int  result_relation,
ReplaceVarsNoMatchOption  nomatch_option,
int  nomatch_varno 
)

Definition at line 1772 of file rewriteManip.c.

1778{
1780
1781 if (var->varattno == InvalidAttrNumber)
1782 {
1783 /* Must expand whole-tuple reference into RowExpr */
1784 RowExpr *rowexpr;
1785 List *colnames;
1786 List *fields;
1787 ListCell *lc;
1788
1789 /*
1790 * If generating an expansion for a var of a named rowtype (ie, this
1791 * is a plain relation RTE), then we must include dummy items for
1792 * dropped columns. If the var is RECORD (ie, this is a JOIN), then
1793 * omit dropped columns. In the latter case, attach column names to
1794 * the RowExpr for use of the executor and ruleutils.c.
1795 *
1796 * In order to be able to cache the results, we always generate the
1797 * expansion with varlevelsup = 0. The caller is responsible for
1798 * adjusting it if needed.
1799 *
1800 * The varreturningtype is copied onto each individual field Var, so
1801 * that it is handled correctly when we recurse.
1802 */
1803 expandRTE(target_rte,
1804 var->varno, 0 /* not varlevelsup */ ,
1805 var->varreturningtype, var->location,
1806 (var->vartype != RECORDOID),
1807 &colnames, &fields);
1808 rowexpr = makeNode(RowExpr);
1809 /* the fields will be set below */
1810 rowexpr->args = NIL;
1811 rowexpr->row_typeid = var->vartype;
1812 rowexpr->row_format = COERCE_IMPLICIT_CAST;
1813 rowexpr->colnames = (var->vartype == RECORDOID) ? colnames : NIL;
1814 rowexpr->location = var->location;
1815 /* Adjust the generated per-field Vars... */
1816 foreach(lc, fields)
1817 {
1818 Node *field = lfirst(lc);
1819
1820 if (field && IsA(field, Var))
1821 field = ReplaceVarFromTargetList((Var *) field,
1822 target_rte,
1823 targetlist,
1824 result_relation,
1825 nomatch_option,
1826 nomatch_varno);
1827 rowexpr->args = lappend(rowexpr->args, field);
1828 }
1829
1830 /* Wrap it in a ReturningExpr, if needed, per comments above */
1832 {
1834
1835 rexpr->retlevelsup = 0;
1836 rexpr->retold = (var->varreturningtype == VAR_RETURNING_OLD);
1837 rexpr->retexpr = (Expr *) rowexpr;
1838
1839 return (Node *) rexpr;
1840 }
1841
1842 return (Node *) rowexpr;
1843 }
1844
1845 /* Normal case referencing one targetlist element */
1846 tle = get_tle_by_resno(targetlist, var->varattno);
1847
1848 if (tle == NULL || tle->resjunk)
1849 {
1850 /* Failed to find column in targetlist */
1851 switch (nomatch_option)
1852 {
1854 /* fall through, throw error below */
1855 break;
1856
1858 {
1859 Var *newvar = copyObject(var);
1860
1861 newvar->varno = nomatch_varno;
1862 newvar->varlevelsup = 0;
1863 /* we leave the syntactic referent alone */
1864 return (Node *) newvar;
1865 }
1866
1868 {
1869 /*
1870 * If Var is of domain type, we must add a CoerceToDomain
1871 * node, in case there is a NOT NULL domain constraint.
1872 */
1874 bool vartypbyval;
1875
1876 get_typlenbyval(var->vartype, &vartyplen, &vartypbyval);
1877 return coerce_null_to_domain(var->vartype,
1878 var->vartypmod,
1879 var->varcollid,
1880 vartyplen,
1881 vartypbyval);
1882 }
1883 }
1884 elog(ERROR, "could not find replacement targetlist entry for attno %d",
1885 var->varattno);
1886 return NULL; /* keep compiler quiet */
1887 }
1888 else
1889 {
1890 /* Make a copy of the tlist item to return */
1891 Expr *newnode = copyObject(tle->expr);
1892
1893 /*
1894 * Check to see if the tlist item contains a PARAM_MULTIEXPR Param,
1895 * and throw error if so. This case could only happen when expanding
1896 * an ON UPDATE rule's NEW variable and the referenced tlist item in
1897 * the original UPDATE command is part of a multiple assignment. There
1898 * seems no practical way to handle such cases without multiple
1899 * evaluation of the multiple assignment's sub-select, which would
1900 * create semantic oddities that users of rules would probably prefer
1901 * not to cope with. So treat it as an unimplemented feature.
1902 */
1904 ereport(ERROR,
1906 errmsg("NEW variables in ON UPDATE rules cannot reference columns that are part of a multiple assignment in the subject UPDATE command")));
1907
1908 /* Handle any OLD/NEW RETURNING list Vars */
1910 {
1911 /*
1912 * Copy varreturningtype onto any Vars in the tlist item that
1913 * refer to result_relation (which had better be non-zero).
1914 */
1915 if (result_relation == 0)
1916 elog(ERROR, "variable returning old/new found outside RETURNING list");
1917
1918 SetVarReturningType((Node *) newnode, result_relation,
1919 0, var->varreturningtype);
1920
1921 /* Wrap it in a ReturningExpr, if needed, per comments above */
1922 if (!IsA(newnode, Var) ||
1923 ((Var *) newnode)->varno != result_relation ||
1924 ((Var *) newnode)->varlevelsup != 0)
1925 {
1927
1928 rexpr->retlevelsup = 0;
1929 rexpr->retold = (var->varreturningtype == VAR_RETURNING_OLD);
1930 rexpr->retexpr = newnode;
1931
1932 newnode = (Expr *) rexpr;
1933 }
1934 }
1935
1936 return (Node *) newnode;
1937 }
1938}
#define InvalidAttrNumber
Definition attnum.h:23
int16_t int16
Definition c.h:678
List * lappend(List *list, void *datum)
Definition list.c:339
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition lsyscache.c:2565
Node * coerce_null_to_domain(Oid typid, int32 typmod, Oid collation, int typlen, bool typbyval)
TargetEntry * get_tle_by_resno(List *tlist, AttrNumber resno)
void expandRTE(RangeTblEntry *rte, int rtindex, int sublevels_up, VarReturningType returning_type, int location, bool include_dropped, List **colnames, List **colvars)
#define NIL
Definition pg_list.h:68
@ VAR_RETURNING_OLD
Definition primnodes.h:258
@ VAR_RETURNING_DEFAULT
Definition primnodes.h:257
static void SetVarReturningType(Node *node, int result_relation, int sublevels_up, VarReturningType returning_type)
Node * ReplaceVarFromTargetList(const Var *var, RangeTblEntry *target_rte, List *targetlist, int result_relation, ReplaceVarsNoMatchOption nomatch_option, int nomatch_varno)
@ REPLACEVARS_SUBSTITUTE_NULL
@ REPLACEVARS_CHANGE_VARNO
@ REPLACEVARS_REPORT_ERROR
Definition pg_list.h:54
List * args
Definition primnodes.h:1431
ParseLoc location
Definition primnodes.h:1455
ParseLoc location
Definition primnodes.h:311
VarReturningType varreturningtype
Definition primnodes.h:298

References RowExpr::args, COERCE_IMPLICIT_CAST, coerce_null_to_domain(), contains_multiexpr_param(), copyObject, elog, ereport, errcode(), errmsg, ERROR, expandRTE(), fb(), get_tle_by_resno(), get_typlenbyval(), InvalidAttrNumber, IsA, lappend(), lfirst, Var::location, RowExpr::location, makeNode, NIL, ReplaceVarFromTargetList(), REPLACEVARS_CHANGE_VARNO, REPLACEVARS_REPORT_ERROR, REPLACEVARS_SUBSTITUTE_NULL, ReturningExpr::retexpr, ReturningExpr::retlevelsup, ReturningExpr::retold, SetVarReturningType(), VAR_RETURNING_DEFAULT, VAR_RETURNING_OLD, Var::varattno, Var::varno, and Var::varreturningtype.

Referenced by pullup_replace_vars_callback(), ReplaceVarFromTargetList(), and ReplaceVarsFromTargetList_callback().

◆ ReplaceVarsFromTargetList()

Node * ReplaceVarsFromTargetList ( Node node,
int  target_varno,
int  sublevels_up,
RangeTblEntry target_rte,
List targetlist,
int  result_relation,
ReplaceVarsNoMatchOption  nomatch_option,
int  nomatch_varno,
bool outer_hasSubLinks 
)

Definition at line 1941 of file rewriteManip.c.

1949{
1951
1952 context.target_rte = target_rte;
1953 context.targetlist = targetlist;
1954 context.result_relation = result_relation;
1955 context.nomatch_option = nomatch_option;
1956 context.nomatch_varno = nomatch_varno;
1957
1958 return replace_rte_variables(node, target_varno, sublevels_up,
1960 &context,
1961 outer_hasSubLinks);
1962}
Node * replace_rte_variables(Node *node, int target_varno, int sublevels_up, replace_rte_variables_callback callback, void *callback_arg, bool *outer_hasSubLinks)
static Node * ReplaceVarsFromTargetList_callback(const Var *var, replace_rte_variables_context *context)
ReplaceVarsNoMatchOption nomatch_option

References ReplaceVarsFromTargetList_context::nomatch_option, ReplaceVarsFromTargetList_context::nomatch_varno, replace_rte_variables(), ReplaceVarsFromTargetList_callback(), ReplaceVarsFromTargetList_context::result_relation, ReplaceVarsFromTargetList_context::target_rte, and ReplaceVarsFromTargetList_context::targetlist.

Referenced by CopyAndAddInvertedQual(), expand_generated_columns_in_expr(), rewriteRuleAction(), rewriteTargetView(), and subquery_push_qual().

◆ ReplaceVarsFromTargetList_callback()

static Node * ReplaceVarsFromTargetList_callback ( const Var var,
replace_rte_variables_context context 
)
static

Definition at line 1751 of file rewriteManip.c.

1753{
1755 Node *newnode;
1756
1758 rcon->target_rte,
1759 rcon->targetlist,
1760 rcon->result_relation,
1761 rcon->nomatch_option,
1762 rcon->nomatch_varno);
1763
1764 /* Must adjust varlevelsup if replaced Var is within a subquery */
1765 if (var->varlevelsup > 0)
1767
1768 return newnode;
1769}
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)

References replace_rte_variables_context::callback_arg, fb(), IncrementVarSublevelsUp(), ReplaceVarFromTargetList(), and Var::varlevelsup.

Referenced by ReplaceVarsFromTargetList().

◆ SetVarReturningType()

static void SetVarReturningType ( Node node,
int  result_relation,
int  sublevels_up,
VarReturningType  returning_type 
)
static

Definition at line 966 of file rewriteManip.c.

968{
970
971 context.result_relation = result_relation;
972 context.sublevels_up = sublevels_up;
973 context.returning_type = returning_type;
974
975 /* Expect to start with an expression */
976 SetVarReturningType_walker(node, &context);
977}
static bool SetVarReturningType_walker(Node *node, SetVarReturningType_context *context)
VarReturningType returning_type

References SetVarReturningType_context::result_relation, SetVarReturningType_context::returning_type, SetVarReturningType_walker(), and SetVarReturningType_context::sublevels_up.

Referenced by ReplaceVarFromTargetList().

◆ SetVarReturningType_walker()

static bool SetVarReturningType_walker ( Node node,
SetVarReturningType_context context 
)
static

Definition at line 936 of file rewriteManip.c.

937{
938 if (node == NULL)
939 return false;
940 if (IsA(node, Var))
941 {
942 Var *var = (Var *) node;
943
944 if (var->varno == context->result_relation &&
945 var->varlevelsup == context->sublevels_up)
946 var->varreturningtype = context->returning_type;
947
948 return false;
949 }
950
951 if (IsA(node, Query))
952 {
953 /* Recurse into subselects */
954 bool result;
955
956 context->sublevels_up++;
958 context, 0);
959 context->sublevels_up--;
960 return result;
961 }
963}

References expression_tree_walker, fb(), IsA, query_tree_walker, result, SetVarReturningType_context::result_relation, SetVarReturningType_context::returning_type, SetVarReturningType_walker(), SetVarReturningType_context::sublevels_up, Var::varlevelsup, Var::varno, and Var::varreturningtype.

Referenced by SetVarReturningType(), and SetVarReturningType_walker().