PostgreSQL Source Code  git master
paramassign.c File Reference
Include dependency graph for paramassign.c:

Go to the source code of this file.

Functions

static int assign_param_for_var (PlannerInfo *root, Var *var)
 
Paramreplace_outer_var (PlannerInfo *root, Var *var)
 
static int assign_param_for_placeholdervar (PlannerInfo *root, PlaceHolderVar *phv)
 
Paramreplace_outer_placeholdervar (PlannerInfo *root, PlaceHolderVar *phv)
 
Paramreplace_outer_agg (PlannerInfo *root, Aggref *agg)
 
Paramreplace_outer_grouping (PlannerInfo *root, GroupingFunc *grp)
 
Paramreplace_nestloop_param_var (PlannerInfo *root, Var *var)
 
Paramreplace_nestloop_param_placeholdervar (PlannerInfo *root, PlaceHolderVar *phv)
 
void process_subquery_nestloop_params (PlannerInfo *root, List *subplan_params)
 
Listidentify_current_nestloop_params (PlannerInfo *root, Relids leftrelids)
 
Paramgenerate_new_exec_param (PlannerInfo *root, Oid paramtype, int32 paramtypmod, Oid paramcollation)
 
int assign_special_exec_param (PlannerInfo *root)
 

Function Documentation

◆ assign_param_for_placeholdervar()

static int assign_param_for_placeholdervar ( PlannerInfo root,
PlaceHolderVar phv 
)
static

Definition at line 148 of file paramassign.c.

References Assert, copyObject, exprType(), PlannerInfo::glob, IncrementVarSublevelsUp(), IsA, PlannerParamItem::item, lappend(), lappend_oid(), lfirst, list_length(), makeNode, PlannerGlobal::paramExecTypes, PlannerParamItem::paramId, PlannerInfo::parent_root, PlaceHolderVar::phid, PlaceHolderVar::phlevelsup, and PlannerInfo::plan_params.

Referenced by replace_outer_placeholdervar().

149 {
150  ListCell *ppl;
151  PlannerParamItem *pitem;
152  Index levelsup;
153 
154  /* Find the query level the PHV belongs to */
155  for (levelsup = phv->phlevelsup; levelsup > 0; levelsup--)
156  root = root->parent_root;
157 
158  /* If there's already a matching PlannerParamItem there, just use it */
159  foreach(ppl, root->plan_params)
160  {
161  pitem = (PlannerParamItem *) lfirst(ppl);
162  if (IsA(pitem->item, PlaceHolderVar))
163  {
164  PlaceHolderVar *pphv = (PlaceHolderVar *) pitem->item;
165 
166  /* We assume comparing the PHIDs is sufficient */
167  if (pphv->phid == phv->phid)
168  return pitem->paramId;
169  }
170  }
171 
172  /* Nope, so make a new one */
173  phv = copyObject(phv);
174  IncrementVarSublevelsUp((Node *) phv, -((int) phv->phlevelsup), 0);
175  Assert(phv->phlevelsup == 0);
176 
177  pitem = makeNode(PlannerParamItem);
178  pitem->item = (Node *) phv;
179  pitem->paramId = list_length(root->glob->paramExecTypes);
181  exprType((Node *) phv->phexpr));
182 
183  root->plan_params = lappend(root->plan_params, pitem);
184 
185  return pitem->paramId;
186 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
List * plan_params
Definition: pathnodes.h:193
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
Definition: rewriteManip.c:776
PlannerInfo * parent_root
Definition: pathnodes.h:185
Definition: nodes.h:525
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
List * paramExecTypes
Definition: pathnodes.h:131
PlannerGlobal * glob
Definition: pathnodes.h:181
List * lappend(List *list, void *datum)
Definition: list.c:322
unsigned int Index
Definition: c.h:475
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:738
#define lfirst(lc)
Definition: pg_list.h:190
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
static int list_length(const List *l)
Definition: pg_list.h:169
Index phlevelsup
Definition: pathnodes.h:2069
#define copyObject(obj)
Definition: nodes.h:641

◆ assign_param_for_var()

static int assign_param_for_var ( PlannerInfo root,
Var var 
)
static

Definition at line 66 of file paramassign.c.

References copyObject, PlannerInfo::glob, IsA, PlannerParamItem::item, lappend(), lappend_oid(), lfirst, list_length(), makeNode, PlannerGlobal::paramExecTypes, PlannerParamItem::paramId, PlannerInfo::parent_root, PlannerInfo::plan_params, Var::varattno, Var::varcollid, Var::varlevelsup, Var::varno, Var::vartype, and Var::vartypmod.

Referenced by replace_outer_var().

67 {
68  ListCell *ppl;
69  PlannerParamItem *pitem;
71 
72  /* Find the query level the Var belongs to */
73  for (levelsup = var->varlevelsup; levelsup > 0; levelsup--)
74  root = root->parent_root;
75 
76  /* If there's already a matching PlannerParamItem there, just use it */
77  foreach(ppl, root->plan_params)
78  {
79  pitem = (PlannerParamItem *) lfirst(ppl);
80  if (IsA(pitem->item, Var))
81  {
82  Var *pvar = (Var *) pitem->item;
83 
84  /*
85  * This comparison must match _equalVar(), except for ignoring
86  * varlevelsup. Note that _equalVar() ignores varnosyn,
87  * varattnosyn, and location, so this does too.
88  */
89  if (pvar->varno == var->varno &&
90  pvar->varattno == var->varattno &&
91  pvar->vartype == var->vartype &&
92  pvar->vartypmod == var->vartypmod &&
93  pvar->varcollid == var->varcollid)
94  return pitem->paramId;
95  }
96  }
97 
98  /* Nope, so make a new one */
99  var = copyObject(var);
100  var->varlevelsup = 0;
101 
102  pitem = makeNode(PlannerParamItem);
103  pitem->item = (Node *) var;
104  pitem->paramId = list_length(root->glob->paramExecTypes);
106  var->vartype);
107 
108  root->plan_params = lappend(root->plan_params, pitem);
109 
110  return pitem->paramId;
111 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Index varlevelsup
Definition: primnodes.h:191
List * plan_params
Definition: pathnodes.h:193
PlannerInfo * parent_root
Definition: pathnodes.h:185
Definition: nodes.h:525
AttrNumber varattno
Definition: primnodes.h:186
Definition: primnodes.h:181
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
List * paramExecTypes
Definition: pathnodes.h:131
Oid vartype
Definition: primnodes.h:188
PlannerGlobal * glob
Definition: pathnodes.h:181
List * lappend(List *list, void *datum)
Definition: list.c:322
Index varno
Definition: primnodes.h:184
unsigned int Index
Definition: c.h:475
#define makeNode(_type_)
Definition: nodes.h:573
#define lfirst(lc)
Definition: pg_list.h:190
static int list_length(const List *l)
Definition: pg_list.h:169
Oid varcollid
Definition: primnodes.h:190
#define copyObject(obj)
Definition: nodes.h:641
int32 vartypmod
Definition: primnodes.h:189

◆ assign_special_exec_param()

int assign_special_exec_param ( PlannerInfo root)

Definition at line 584 of file paramassign.c.

References PlannerInfo::glob, InvalidOid, lappend_oid(), list_length(), and PlannerGlobal::paramExecTypes.

Referenced by create_gather_merge_plan(), create_gather_plan(), grouping_planner(), inheritance_planner(), SS_process_ctes(), and subquery_planner().

585 {
586  int paramId = list_length(root->glob->paramExecTypes);
587 
589  InvalidOid);
590  return paramId;
591 }
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
List * paramExecTypes
Definition: pathnodes.h:131
PlannerGlobal * glob
Definition: pathnodes.h:181
#define InvalidOid
Definition: postgres_ext.h:36
static int list_length(const List *l)
Definition: pg_list.h:169

◆ generate_new_exec_param()

Param* generate_new_exec_param ( PlannerInfo root,
Oid  paramtype,
int32  paramtypmod,
Oid  paramcollation 
)

Definition at line 557 of file paramassign.c.

References PlannerInfo::glob, lappend_oid(), list_length(), Param::location, makeNode, PARAM_EXEC, Param::paramcollid, PlannerGlobal::paramExecTypes, Param::paramid, Param::paramkind, Param::paramtype, and Param::paramtypmod.

Referenced by build_subplan(), convert_EXISTS_to_ANY(), generate_subquery_params(), replace_nestloop_param_placeholdervar(), replace_nestloop_param_var(), and SS_make_initplan_output_param().

559 {
560  Param *retval;
561 
562  retval = makeNode(Param);
563  retval->paramkind = PARAM_EXEC;
564  retval->paramid = list_length(root->glob->paramExecTypes);
566  paramtype);
567  retval->paramtype = paramtype;
568  retval->paramtypmod = paramtypmod;
569  retval->paramcollid = paramcollation;
570  retval->location = -1;
571 
572  return retval;
573 }
ParamKind paramkind
Definition: primnodes.h:262
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
List * paramExecTypes
Definition: pathnodes.h:131
Oid paramcollid
Definition: primnodes.h:266
int location
Definition: primnodes.h:267
PlannerGlobal * glob
Definition: pathnodes.h:181
int32 paramtypmod
Definition: primnodes.h:265
#define makeNode(_type_)
Definition: nodes.h:573
int paramid
Definition: primnodes.h:263
static int list_length(const List *l)
Definition: pg_list.h:169
Oid paramtype
Definition: primnodes.h:264

◆ identify_current_nestloop_params()

List* identify_current_nestloop_params ( PlannerInfo root,
Relids  leftrelids 
)

Definition at line 508 of file paramassign.c.

References bms_is_member(), bms_is_subset(), bms_overlap(), PlannerInfo::curOuterParams, find_placeholder_info(), foreach_delete_current, IsA, lappend(), lfirst, NIL, NestLoopParam::paramval, PlaceHolderInfo::ph_eval_at, and Var::varno.

Referenced by create_nestloop_plan().

509 {
510  List *result;
511  ListCell *cell;
512 
513  result = NIL;
514  foreach(cell, root->curOuterParams)
515  {
516  NestLoopParam *nlp = (NestLoopParam *) lfirst(cell);
517 
518  /*
519  * We are looking for Vars and PHVs that can be supplied by the
520  * lefthand rels. The "bms_overlap" test is just an optimization to
521  * allow skipping find_placeholder_info() if the PHV couldn't match.
522  */
523  if (IsA(nlp->paramval, Var) &&
524  bms_is_member(nlp->paramval->varno, leftrelids))
525  {
527  cell);
528  result = lappend(result, nlp);
529  }
530  else if (IsA(nlp->paramval, PlaceHolderVar) &&
531  bms_overlap(((PlaceHolderVar *) nlp->paramval)->phrels,
532  leftrelids) &&
534  (PlaceHolderVar *) nlp->paramval,
535  false)->ph_eval_at,
536  leftrelids))
537  {
539  cell);
540  result = lappend(result, nlp);
541  }
542  }
543  return result;
544 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Relids ph_eval_at
Definition: pathnodes.h:2270
Definition: primnodes.h:181
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:368
Var * paramval
Definition: plannodes.h:710
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:315
List * curOuterParams
Definition: pathnodes.h:358
PlaceHolderInfo * find_placeholder_info(PlannerInfo *root, PlaceHolderVar *phv, bool create_new_ph)
Definition: placeholder.c:69
List * lappend(List *list, void *datum)
Definition: list.c:322
Index varno
Definition: primnodes.h:184
#define lfirst(lc)
Definition: pg_list.h:190
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494
Definition: pg_list.h:50
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427

◆ process_subquery_nestloop_params()

void process_subquery_nestloop_params ( PlannerInfo root,
List subplan_params 
)

Definition at line 428 of file paramassign.c.

References Assert, bms_is_member(), bms_is_subset(), castNode, copyObject, PlannerInfo::curOuterParams, PlannerInfo::curOuterRels, elog, equal(), ERROR, find_placeholder_info(), IsA, PlannerParamItem::item, lappend(), lfirst, makeNode, PlannerParamItem::paramId, and Var::varno.

Referenced by create_subqueryscan_plan().

429 {
430  ListCell *lc;
431 
432  foreach(lc, subplan_params)
433  {
435 
436  if (IsA(pitem->item, Var))
437  {
438  Var *var = (Var *) pitem->item;
439  NestLoopParam *nlp;
440  ListCell *lc;
441 
442  /* If not from a nestloop outer rel, complain */
443  if (!bms_is_member(var->varno, root->curOuterRels))
444  elog(ERROR, "non-LATERAL parameter required by subquery");
445 
446  /* Is this param already listed in root->curOuterParams? */
447  foreach(lc, root->curOuterParams)
448  {
449  nlp = (NestLoopParam *) lfirst(lc);
450  if (nlp->paramno == pitem->paramId)
451  {
452  Assert(equal(var, nlp->paramval));
453  /* Present, so nothing to do */
454  break;
455  }
456  }
457  if (lc == NULL)
458  {
459  /* No, so add it */
460  nlp = makeNode(NestLoopParam);
461  nlp->paramno = pitem->paramId;
462  nlp->paramval = copyObject(var);
463  root->curOuterParams = lappend(root->curOuterParams, nlp);
464  }
465  }
466  else if (IsA(pitem->item, PlaceHolderVar))
467  {
468  PlaceHolderVar *phv = (PlaceHolderVar *) pitem->item;
469  NestLoopParam *nlp;
470  ListCell *lc;
471 
472  /* If not from a nestloop outer rel, complain */
473  if (!bms_is_subset(find_placeholder_info(root, phv, false)->ph_eval_at,
474  root->curOuterRels))
475  elog(ERROR, "non-LATERAL parameter required by subquery");
476 
477  /* Is this param already listed in root->curOuterParams? */
478  foreach(lc, root->curOuterParams)
479  {
480  nlp = (NestLoopParam *) lfirst(lc);
481  if (nlp->paramno == pitem->paramId)
482  {
483  Assert(equal(phv, nlp->paramval));
484  /* Present, so nothing to do */
485  break;
486  }
487  }
488  if (lc == NULL)
489  {
490  /* No, so add it */
491  nlp = makeNode(NestLoopParam);
492  nlp->paramno = pitem->paramId;
493  nlp->paramval = (Var *) copyObject(phv);
494  root->curOuterParams = lappend(root->curOuterParams, nlp);
495  }
496  }
497  else
498  elog(ERROR, "unexpected type of subquery parameter");
499  }
500 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
Relids curOuterRels
Definition: pathnodes.h:357
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3018
#define castNode(_type_, nodeptr)
Definition: nodes.h:594
Definition: primnodes.h:181
#define ERROR
Definition: elog.h:43
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:315
List * curOuterParams
Definition: pathnodes.h:358
PlaceHolderInfo * find_placeholder_info(PlannerInfo *root, PlaceHolderVar *phv, bool create_new_ph)
Definition: placeholder.c:69
List * lappend(List *list, void *datum)
Definition: list.c:322
Index varno
Definition: primnodes.h:184
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:738
#define lfirst(lc)
Definition: pg_list.h:190
#define elog(elevel,...)
Definition: elog.h:228
#define copyObject(obj)
Definition: nodes.h:641
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:427

◆ replace_nestloop_param_placeholdervar()

Param* replace_nestloop_param_placeholdervar ( PlannerInfo root,
PlaceHolderVar phv 
)

Definition at line 364 of file paramassign.c.

References copyObject, PlannerInfo::curOuterParams, equal(), exprCollation(), exprType(), exprTypmod(), generate_new_exec_param(), lappend(), lfirst, Param::location, makeNode, PARAM_EXEC, Param::paramcollid, Param::paramid, Param::paramkind, NestLoopParam::paramno, Param::paramtype, Param::paramtypmod, NestLoopParam::paramval, and PlaceHolderVar::phexpr.

Referenced by replace_nestloop_params_mutator().

365 {
366  Param *param;
367  NestLoopParam *nlp;
368  ListCell *lc;
369 
370  /* Is this PHV already listed in root->curOuterParams? */
371  foreach(lc, root->curOuterParams)
372  {
373  nlp = (NestLoopParam *) lfirst(lc);
374  if (equal(phv, nlp->paramval))
375  {
376  /* Yes, so just make a Param referencing this NLP's slot */
377  param = makeNode(Param);
378  param->paramkind = PARAM_EXEC;
379  param->paramid = nlp->paramno;
380  param->paramtype = exprType((Node *) phv->phexpr);
381  param->paramtypmod = exprTypmod((Node *) phv->phexpr);
382  param->paramcollid = exprCollation((Node *) phv->phexpr);
383  param->location = -1;
384  return param;
385  }
386  }
387 
388  /* No, so assign a PARAM_EXEC slot for a new NLP */
389  param = generate_new_exec_param(root,
390  exprType((Node *) phv->phexpr),
391  exprTypmod((Node *) phv->phexpr),
392  exprCollation((Node *) phv->phexpr));
393 
394  /* Add it to the list of required NLPs */
395  nlp = makeNode(NestLoopParam);
396  nlp->paramno = param->paramid;
397  nlp->paramval = (Var *) copyObject(phv);
398  root->curOuterParams = lappend(root->curOuterParams, nlp);
399 
400  /* And return the replacement Param */
401  return param;
402 }
Param * generate_new_exec_param(PlannerInfo *root, Oid paramtype, int32 paramtypmod, Oid paramcollation)
Definition: paramassign.c:557
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3018
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:275
ParamKind paramkind
Definition: primnodes.h:262
Definition: nodes.h:525
Definition: primnodes.h:181
Var * paramval
Definition: plannodes.h:710
Oid paramcollid
Definition: primnodes.h:266
int location
Definition: primnodes.h:267
List * curOuterParams
Definition: pathnodes.h:358
List * lappend(List *list, void *datum)
Definition: list.c:322
int32 paramtypmod
Definition: primnodes.h:265
#define makeNode(_type_)
Definition: nodes.h:573
#define lfirst(lc)
Definition: pg_list.h:190
int paramid
Definition: primnodes.h:263
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:719
#define copyObject(obj)
Definition: nodes.h:641
Oid paramtype
Definition: primnodes.h:264

◆ replace_nestloop_param_var()

Param* replace_nestloop_param_var ( PlannerInfo root,
Var var 
)

Definition at line 315 of file paramassign.c.

References copyObject, PlannerInfo::curOuterParams, equal(), generate_new_exec_param(), lappend(), lfirst, Var::location, Param::location, makeNode, PARAM_EXEC, Param::paramcollid, Param::paramid, Param::paramkind, NestLoopParam::paramno, Param::paramtype, Param::paramtypmod, NestLoopParam::paramval, Var::varcollid, Var::vartype, and Var::vartypmod.

Referenced by replace_nestloop_params_mutator().

316 {
317  Param *param;
318  NestLoopParam *nlp;
319  ListCell *lc;
320 
321  /* Is this Var already listed in root->curOuterParams? */
322  foreach(lc, root->curOuterParams)
323  {
324  nlp = (NestLoopParam *) lfirst(lc);
325  if (equal(var, nlp->paramval))
326  {
327  /* Yes, so just make a Param referencing this NLP's slot */
328  param = makeNode(Param);
329  param->paramkind = PARAM_EXEC;
330  param->paramid = nlp->paramno;
331  param->paramtype = var->vartype;
332  param->paramtypmod = var->vartypmod;
333  param->paramcollid = var->varcollid;
334  param->location = var->location;
335  return param;
336  }
337  }
338 
339  /* No, so assign a PARAM_EXEC slot for a new NLP */
340  param = generate_new_exec_param(root,
341  var->vartype,
342  var->vartypmod,
343  var->varcollid);
344  param->location = var->location;
345 
346  /* Add it to the list of required NLPs */
347  nlp = makeNode(NestLoopParam);
348  nlp->paramno = param->paramid;
349  nlp->paramval = copyObject(var);
350  root->curOuterParams = lappend(root->curOuterParams, nlp);
351 
352  /* And return the replacement Param */
353  return param;
354 }
Param * generate_new_exec_param(PlannerInfo *root, Oid paramtype, int32 paramtypmod, Oid paramcollation)
Definition: paramassign.c:557
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3018
ParamKind paramkind
Definition: primnodes.h:262
Var * paramval
Definition: plannodes.h:710
Oid paramcollid
Definition: primnodes.h:266
int location
Definition: primnodes.h:267
Oid vartype
Definition: primnodes.h:188
int location
Definition: primnodes.h:196
List * curOuterParams
Definition: pathnodes.h:358
List * lappend(List *list, void *datum)
Definition: list.c:322
int32 paramtypmod
Definition: primnodes.h:265
#define makeNode(_type_)
Definition: nodes.h:573
#define lfirst(lc)
Definition: pg_list.h:190
int paramid
Definition: primnodes.h:263
Oid varcollid
Definition: primnodes.h:190
#define copyObject(obj)
Definition: nodes.h:641
Oid paramtype
Definition: primnodes.h:264
int32 vartypmod
Definition: primnodes.h:189

◆ replace_outer_agg()

Param* replace_outer_agg ( PlannerInfo root,
Aggref agg 
)

Definition at line 223 of file paramassign.c.

References Aggref::agglevelsup, Assert, copyObject, PlannerInfo::glob, IncrementVarSublevelsUp(), PlannerParamItem::item, lappend(), lappend_oid(), list_length(), Param::location, makeNode, PARAM_EXEC, Param::paramcollid, PlannerGlobal::paramExecTypes, Param::paramid, PlannerParamItem::paramId, Param::paramkind, Param::paramtype, Param::paramtypmod, PlannerInfo::parent_root, PlannerInfo::plan_params, and PlannerInfo::query_level.

Referenced by replace_correlation_vars_mutator().

224 {
225  Param *retval;
226  PlannerParamItem *pitem;
227  Index levelsup;
228 
229  Assert(agg->agglevelsup > 0 && agg->agglevelsup < root->query_level);
230 
231  /* Find the query level the Aggref belongs to */
232  for (levelsup = agg->agglevelsup; levelsup > 0; levelsup--)
233  root = root->parent_root;
234 
235  /*
236  * It does not seem worthwhile to try to de-duplicate references to outer
237  * aggs. Just make a new slot every time.
238  */
239  agg = copyObject(agg);
240  IncrementVarSublevelsUp((Node *) agg, -((int) agg->agglevelsup), 0);
241  Assert(agg->agglevelsup == 0);
242 
243  pitem = makeNode(PlannerParamItem);
244  pitem->item = (Node *) agg;
245  pitem->paramId = list_length(root->glob->paramExecTypes);
247  agg->aggtype);
248 
249  root->plan_params = lappend(root->plan_params, pitem);
250 
251  retval = makeNode(Param);
252  retval->paramkind = PARAM_EXEC;
253  retval->paramid = pitem->paramId;
254  retval->paramtype = agg->aggtype;
255  retval->paramtypmod = -1;
256  retval->paramcollid = agg->aggcollid;
257  retval->location = agg->location;
258 
259  return retval;
260 }
List * plan_params
Definition: pathnodes.h:193
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
Definition: rewriteManip.c:776
PlannerInfo * parent_root
Definition: pathnodes.h:185
ParamKind paramkind
Definition: primnodes.h:262
Definition: nodes.h:525
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
List * paramExecTypes
Definition: pathnodes.h:131
Oid paramcollid
Definition: primnodes.h:266
int location
Definition: primnodes.h:267
PlannerGlobal * glob
Definition: pathnodes.h:181
Index agglevelsup
Definition: primnodes.h:327
List * lappend(List *list, void *datum)
Definition: list.c:322
unsigned int Index
Definition: c.h:475
int32 paramtypmod
Definition: primnodes.h:265
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:738
int paramid
Definition: primnodes.h:263
static int list_length(const List *l)
Definition: pg_list.h:169
Index query_level
Definition: pathnodes.h:183
#define copyObject(obj)
Definition: nodes.h:641
Oid paramtype
Definition: primnodes.h:264

◆ replace_outer_grouping()

Param* replace_outer_grouping ( PlannerInfo root,
GroupingFunc grp 
)

Definition at line 269 of file paramassign.c.

References Assert, copyObject, exprType(), PlannerInfo::glob, IncrementVarSublevelsUp(), InvalidOid, PlannerParamItem::item, lappend(), lappend_oid(), list_length(), Param::location, makeNode, PARAM_EXEC, Param::paramcollid, PlannerGlobal::paramExecTypes, Param::paramid, PlannerParamItem::paramId, Param::paramkind, Param::paramtype, Param::paramtypmod, PlannerInfo::parent_root, PlannerInfo::plan_params, and PlannerInfo::query_level.

Referenced by replace_correlation_vars_mutator().

270 {
271  Param *retval;
272  PlannerParamItem *pitem;
273  Index levelsup;
274  Oid ptype = exprType((Node *) grp);
275 
276  Assert(grp->agglevelsup > 0 && grp->agglevelsup < root->query_level);
277 
278  /* Find the query level the GroupingFunc belongs to */
279  for (levelsup = grp->agglevelsup; levelsup > 0; levelsup--)
280  root = root->parent_root;
281 
282  /*
283  * It does not seem worthwhile to try to de-duplicate references to outer
284  * aggs. Just make a new slot every time.
285  */
286  grp = copyObject(grp);
287  IncrementVarSublevelsUp((Node *) grp, -((int) grp->agglevelsup), 0);
288  Assert(grp->agglevelsup == 0);
289 
290  pitem = makeNode(PlannerParamItem);
291  pitem->item = (Node *) grp;
292  pitem->paramId = list_length(root->glob->paramExecTypes);
294  ptype);
295 
296  root->plan_params = lappend(root->plan_params, pitem);
297 
298  retval = makeNode(Param);
299  retval->paramkind = PARAM_EXEC;
300  retval->paramid = pitem->paramId;
301  retval->paramtype = ptype;
302  retval->paramtypmod = -1;
303  retval->paramcollid = InvalidOid;
304  retval->location = grp->location;
305 
306  return retval;
307 }
List * plan_params
Definition: pathnodes.h:193
void IncrementVarSublevelsUp(Node *node, int delta_sublevels_up, int min_sublevels_up)
Definition: rewriteManip.c:776
PlannerInfo * parent_root
Definition: pathnodes.h:185
ParamKind paramkind
Definition: primnodes.h:262
Definition: nodes.h:525
unsigned int Oid
Definition: postgres_ext.h:31
List * lappend_oid(List *list, Oid datum)
Definition: list.c:358
List * paramExecTypes
Definition: pathnodes.h:131
Oid paramcollid
Definition: primnodes.h:266
int location
Definition: primnodes.h:267
PlannerGlobal * glob
Definition: pathnodes.h:181
List * lappend(List *list, void *datum)
Definition: list.c:322
Index agglevelsup
Definition: primnodes.h:363
unsigned int Index
Definition: c.h:475
#define InvalidOid
Definition: postgres_ext.h:36
int32 paramtypmod
Definition: primnodes.h:265
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:738
int paramid
Definition: primnodes.h:263
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
static int list_length(const List *l)
Definition: pg_list.h:169
Index query_level
Definition: pathnodes.h:183
#define copyObject(obj)
Definition: nodes.h:641
Oid paramtype
Definition: primnodes.h:264

◆ replace_outer_placeholdervar()

Param* replace_outer_placeholdervar ( PlannerInfo root,
PlaceHolderVar phv 
)

Definition at line 196 of file paramassign.c.

References Assert, assign_param_for_placeholdervar(), exprCollation(), exprType(), exprTypmod(), i, Param::location, makeNode, PARAM_EXEC, Param::paramcollid, Param::paramid, Param::paramkind, Param::paramtype, Param::paramtypmod, PlaceHolderVar::phexpr, PlaceHolderVar::phlevelsup, and PlannerInfo::query_level.

Referenced by replace_correlation_vars_mutator().

197 {
198  Param *retval;
199  int i;
200 
201  Assert(phv->phlevelsup > 0 && phv->phlevelsup < root->query_level);
202 
203  /* Find the PHV in the appropriate plan_params, or add it if not present */
204  i = assign_param_for_placeholdervar(root, phv);
205 
206  retval = makeNode(Param);
207  retval->paramkind = PARAM_EXEC;
208  retval->paramid = i;
209  retval->paramtype = exprType((Node *) phv->phexpr);
210  retval->paramtypmod = exprTypmod((Node *) phv->phexpr);
211  retval->paramcollid = exprCollation((Node *) phv->phexpr);
212  retval->location = -1;
213 
214  return retval;
215 }
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:275
ParamKind paramkind
Definition: primnodes.h:262
Definition: nodes.h:525
Oid paramcollid
Definition: primnodes.h:266
int location
Definition: primnodes.h:267
int32 paramtypmod
Definition: primnodes.h:265
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:738
int paramid
Definition: primnodes.h:263
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:41
Oid exprCollation(const Node *expr)
Definition: nodeFuncs.c:719
Index query_level
Definition: pathnodes.h:183
static int assign_param_for_placeholdervar(PlannerInfo *root, PlaceHolderVar *phv)
Definition: paramassign.c:148
Index phlevelsup
Definition: pathnodes.h:2069
int i
Oid paramtype
Definition: primnodes.h:264

◆ replace_outer_var()

Param* replace_outer_var ( PlannerInfo root,
Var var 
)

Definition at line 119 of file paramassign.c.

References Assert, assign_param_for_var(), i, Var::location, Param::location, makeNode, PARAM_EXEC, Param::paramcollid, Param::paramid, Param::paramkind, Param::paramtype, Param::paramtypmod, PlannerInfo::query_level, Var::varcollid, Var::varlevelsup, Var::vartype, and Var::vartypmod.

Referenced by replace_correlation_vars_mutator().

120 {
121  Param *retval;
122  int i;
123 
124  Assert(var->varlevelsup > 0 && var->varlevelsup < root->query_level);
125 
126  /* Find the Var in the appropriate plan_params, or add it if not present */
127  i = assign_param_for_var(root, var);
128 
129  retval = makeNode(Param);
130  retval->paramkind = PARAM_EXEC;
131  retval->paramid = i;
132  retval->paramtype = var->vartype;
133  retval->paramtypmod = var->vartypmod;
134  retval->paramcollid = var->varcollid;
135  retval->location = var->location;
136 
137  return retval;
138 }
Index varlevelsup
Definition: primnodes.h:191
ParamKind paramkind
Definition: primnodes.h:262
static int assign_param_for_var(PlannerInfo *root, Var *var)
Definition: paramassign.c:66
Oid paramcollid
Definition: primnodes.h:266
int location
Definition: primnodes.h:267
Oid vartype
Definition: primnodes.h:188
int location
Definition: primnodes.h:196
int32 paramtypmod
Definition: primnodes.h:265
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:738
int paramid
Definition: primnodes.h:263
Index query_level
Definition: pathnodes.h:183
int i
Oid varcollid
Definition: primnodes.h:190
Oid paramtype
Definition: primnodes.h:264
int32 vartypmod
Definition: primnodes.h:189