PostgreSQL Source Code  git master
appendinfo.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/table.h"
#include "foreign/fdwapi.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/appendinfo.h"
#include "optimizer/pathnode.h"
#include "optimizer/planmain.h"
#include "parser/parsetree.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/syscache.h"
Include dependency graph for appendinfo.c:

Go to the source code of this file.

Data Structures

struct  adjust_appendrel_attrs_context
 

Functions

static void make_inh_translation_list (Relation oldrelation, Relation newrelation, Index newvarno, AppendRelInfo *appinfo)
 
static Nodeadjust_appendrel_attrs_mutator (Node *node, adjust_appendrel_attrs_context *context)
 
AppendRelInfomake_append_rel_info (Relation parentrel, Relation childrel, Index parentRTindex, Index childRTindex)
 
Nodeadjust_appendrel_attrs (PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
 
Nodeadjust_appendrel_attrs_multilevel (PlannerInfo *root, Node *node, RelOptInfo *childrel, RelOptInfo *parentrel)
 
Relids adjust_child_relids (Relids relids, int nappinfos, AppendRelInfo **appinfos)
 
Relids adjust_child_relids_multilevel (PlannerInfo *root, Relids relids, RelOptInfo *childrel, RelOptInfo *parentrel)
 
Listadjust_inherited_attnums (List *attnums, AppendRelInfo *context)
 
Listadjust_inherited_attnums_multilevel (PlannerInfo *root, List *attnums, Index child_relid, Index top_parent_relid)
 
void get_translated_update_targetlist (PlannerInfo *root, Index relid, List **processed_tlist, List **update_colnos)
 
AppendRelInfo ** find_appinfos_by_relids (PlannerInfo *root, Relids relids, int *nappinfos)
 
void add_row_identity_var (PlannerInfo *root, Var *orig_var, Index rtindex, const char *rowid_name)
 
void add_row_identity_columns (PlannerInfo *root, Index rtindex, RangeTblEntry *target_rte, Relation target_relation)
 
void distribute_row_identity_vars (PlannerInfo *root)
 

Function Documentation

◆ add_row_identity_columns()

void add_row_identity_columns ( PlannerInfo root,
Index  rtindex,
RangeTblEntry target_rte,
Relation  target_relation 
)

Definition at line 884 of file appendinfo.c.

887 {
888  CmdType commandType = root->parse->commandType;
889  char relkind = target_relation->rd_rel->relkind;
890  Var *var;
891 
892  Assert(commandType == CMD_UPDATE || commandType == CMD_DELETE || commandType == CMD_MERGE);
893 
894  if (commandType == CMD_MERGE ||
895  relkind == RELKIND_RELATION ||
896  relkind == RELKIND_MATVIEW ||
897  relkind == RELKIND_PARTITIONED_TABLE)
898  {
899  /*
900  * Emit CTID so that executor can find the row to merge, update or
901  * delete.
902  */
903  var = makeVar(rtindex,
905  TIDOID,
906  -1,
907  InvalidOid,
908  0);
909  add_row_identity_var(root, var, rtindex, "ctid");
910  }
911  else if (relkind == RELKIND_FOREIGN_TABLE)
912  {
913  /*
914  * Let the foreign table's FDW add whatever junk TLEs it wants.
915  */
916  FdwRoutine *fdwroutine;
917 
918  fdwroutine = GetFdwRoutineForRelation(target_relation, false);
919 
920  if (fdwroutine->AddForeignUpdateTargets != NULL)
921  fdwroutine->AddForeignUpdateTargets(root, rtindex,
922  target_rte, target_relation);
923 
924  /*
925  * For UPDATE, we need to make the FDW fetch unchanged columns by
926  * asking it to fetch a whole-row Var. That's because the top-level
927  * targetlist only contains entries for changed columns, but
928  * ExecUpdate will need to build the complete new tuple. (Actually,
929  * we only really need this in UPDATEs that are not pushed to the
930  * remote side, but it's hard to tell if that will be the case at the
931  * point when this function is called.)
932  *
933  * We will also need the whole row if there are any row triggers, so
934  * that the executor will have the "old" row to pass to the trigger.
935  * Alas, this misses system columns.
936  */
937  if (commandType == CMD_UPDATE ||
938  (target_relation->trigdesc &&
939  (target_relation->trigdesc->trig_delete_after_row ||
940  target_relation->trigdesc->trig_delete_before_row)))
941  {
942  var = makeVar(rtindex,
944  RECORDOID,
945  -1,
946  InvalidOid,
947  0);
948  add_row_identity_var(root, var, rtindex, "wholerow");
949  }
950  }
951 }
void add_row_identity_var(PlannerInfo *root, Var *orig_var, Index rtindex, const char *rowid_name)
Definition: appendinfo.c:789
#define InvalidAttrNumber
Definition: attnum.h:23
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:429
Assert(fmt[strlen(fmt) - 1] !='\n')
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:67
CmdType
Definition: nodes.h:274
@ CMD_MERGE
Definition: nodes.h:280
@ CMD_DELETE
Definition: nodes.h:279
@ CMD_UPDATE
Definition: nodes.h:277
#define InvalidOid
Definition: postgres_ext.h:36
AddForeignUpdateTargets_function AddForeignUpdateTargets
Definition: fdwapi.h:229
Query * parse
Definition: pathnodes.h:199
CmdType commandType
Definition: parsenodes.h:127
TriggerDesc * trigdesc
Definition: rel.h:117
Form_pg_class rd_rel
Definition: rel.h:111
bool trig_delete_before_row
Definition: reltrigger.h:66
bool trig_delete_after_row
Definition: reltrigger.h:67
Definition: primnodes.h:226
#define SelfItemPointerAttributeNumber
Definition: sysattr.h:21

References add_row_identity_var(), FdwRoutine::AddForeignUpdateTargets, Assert(), CMD_DELETE, CMD_MERGE, CMD_UPDATE, Query::commandType, GetFdwRoutineForRelation(), InvalidAttrNumber, InvalidOid, makeVar(), PlannerInfo::parse, RelationData::rd_rel, SelfItemPointerAttributeNumber, TriggerDesc::trig_delete_after_row, TriggerDesc::trig_delete_before_row, and RelationData::trigdesc.

Referenced by distribute_row_identity_vars(), expand_single_inheritance_child(), and preprocess_targetlist().

◆ add_row_identity_var()

void add_row_identity_var ( PlannerInfo root,
Var orig_var,
Index  rtindex,
const char *  rowid_name 
)

Definition at line 789 of file appendinfo.c.

791 {
792  TargetEntry *tle;
793  Var *rowid_var;
794  RowIdentityVarInfo *ridinfo;
795  ListCell *lc;
796 
797  /* For now, the argument must be just a Var of the given rtindex */
798  Assert(IsA(orig_var, Var));
799  Assert(orig_var->varno == rtindex);
800  Assert(orig_var->varlevelsup == 0);
801  Assert(orig_var->varnullingrels == NULL);
802 
803  /*
804  * If we're doing non-inherited UPDATE/DELETE/MERGE, there's little need
805  * for ROWID_VAR shenanigans. Just shove the presented Var into the
806  * processed_tlist, and we're done.
807  */
808  if (rtindex == root->parse->resultRelation)
809  {
810  tle = makeTargetEntry((Expr *) orig_var,
811  list_length(root->processed_tlist) + 1,
812  pstrdup(rowid_name),
813  true);
814  root->processed_tlist = lappend(root->processed_tlist, tle);
815  return;
816  }
817 
818  /*
819  * Otherwise, rtindex should reference a leaf target relation that's being
820  * added to the query during expand_inherited_rtentry().
821  */
822  Assert(bms_is_member(rtindex, root->leaf_result_relids));
823  Assert(root->append_rel_array[rtindex] != NULL);
824 
825  /*
826  * We have to find a matching RowIdentityVarInfo, or make one if there is
827  * none. To allow using equal() to match the vars, change the varno to
828  * ROWID_VAR, leaving all else alone.
829  */
830  rowid_var = copyObject(orig_var);
831  /* This could eventually become ChangeVarNodes() */
832  rowid_var->varno = ROWID_VAR;
833 
834  /* Look for an existing row-id column of the same name */
835  foreach(lc, root->row_identity_vars)
836  {
837  ridinfo = (RowIdentityVarInfo *) lfirst(lc);
838  if (strcmp(rowid_name, ridinfo->rowidname) != 0)
839  continue;
840  if (equal(rowid_var, ridinfo->rowidvar))
841  {
842  /* Found a match; we need only record that rtindex needs it too */
843  ridinfo->rowidrels = bms_add_member(ridinfo->rowidrels, rtindex);
844  return;
845  }
846  else
847  {
848  /* Ooops, can't handle this */
849  elog(ERROR, "conflicting uses of row-identity name \"%s\"",
850  rowid_name);
851  }
852  }
853 
854  /* No request yet, so add a new RowIdentityVarInfo */
855  ridinfo = makeNode(RowIdentityVarInfo);
856  ridinfo->rowidvar = copyObject(rowid_var);
857  /* for the moment, estimate width using just the datatype info */
858  ridinfo->rowidwidth = get_typavgwidth(exprType((Node *) rowid_var),
859  exprTypmod((Node *) rowid_var));
860  ridinfo->rowidname = pstrdup(rowid_name);
861  ridinfo->rowidrels = bms_make_singleton(rtindex);
862 
863  root->row_identity_vars = lappend(root->row_identity_vars, ridinfo);
864 
865  /* Change rowid_var into a reference to this row_identity_vars entry */
866  rowid_var->varattno = list_length(root->row_identity_vars);
867 
868  /* Push the ROWID_VAR reference variable into processed_tlist */
869  tle = makeTargetEntry((Expr *) rowid_var,
870  list_length(root->processed_tlist) + 1,
871  pstrdup(rowid_name),
872  true);
873  root->processed_tlist = lappend(root->processed_tlist, tle);
874 }
bool bms_is_member(int x, const Bitmapset *a)
Definition: bitmapset.c:460
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:171
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:753
#define ERROR
Definition: elog.h:39
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
List * lappend(List *list, void *datum)
Definition: list.c:338
int32 get_typavgwidth(Oid typid, int32 typmod)
Definition: lsyscache.c:2560
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Definition: makefuncs.c:241
char * pstrdup(const char *in)
Definition: mcxt.c:1644
Oid exprType(const Node *expr)
Definition: nodeFuncs.c:43
int32 exprTypmod(const Node *expr)
Definition: nodeFuncs.c:282
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
#define copyObject(obj)
Definition: nodes.h:244
#define makeNode(_type_)
Definition: nodes.h:176
#define lfirst(lc)
Definition: pg_list.h:172
static int list_length(const List *l)
Definition: pg_list.h:152
#define ROWID_VAR
Definition: primnodes.h:217
Definition: nodes.h:129
List * processed_tlist
Definition: pathnodes.h:453
List * row_identity_vars
Definition: pathnodes.h:365
Relids leaf_result_relids
Definition: pathnodes.h:353
int varno
Definition: primnodes.h:233
Index varlevelsup
Definition: primnodes.h:258

References Assert(), bms_add_member(), bms_is_member(), bms_make_singleton(), copyObject, elog(), equal(), ERROR, exprType(), exprTypmod(), get_typavgwidth(), IsA, lappend(), PlannerInfo::leaf_result_relids, lfirst, list_length(), makeNode, makeTargetEntry(), PlannerInfo::parse, PlannerInfo::processed_tlist, pstrdup(), PlannerInfo::row_identity_vars, ROWID_VAR, RowIdentityVarInfo::rowidname, RowIdentityVarInfo::rowidrels, RowIdentityVarInfo::rowidvar, RowIdentityVarInfo::rowidwidth, Var::varattno, Var::varlevelsup, and Var::varno.

Referenced by add_row_identity_columns(), expand_single_inheritance_child(), and postgresAddForeignUpdateTargets().

◆ adjust_appendrel_attrs()

Node* adjust_appendrel_attrs ( PlannerInfo root,
Node node,
int  nappinfos,
AppendRelInfo **  appinfos 
)

Definition at line 196 of file appendinfo.c.

198 {
200 
201  context.root = root;
202  context.nappinfos = nappinfos;
203  context.appinfos = appinfos;
204 
205  /* If there's nothing to adjust, don't call this function. */
206  Assert(nappinfos >= 1 && appinfos != NULL);
207 
208  /* Should never be translating a Query tree. */
209  Assert(node == NULL || !IsA(node, Query));
210 
211  return adjust_appendrel_attrs_mutator(node, &context);
212 }
static Node * adjust_appendrel_attrs_mutator(Node *node, adjust_appendrel_attrs_context *context)
Definition: appendinfo.c:215
AppendRelInfo ** appinfos
Definition: appendinfo.c:35

References adjust_appendrel_attrs_mutator(), adjust_appendrel_attrs_context::appinfos, Assert(), IsA, adjust_appendrel_attrs_context::nappinfos, and adjust_appendrel_attrs_context::root.

Referenced by add_child_join_rel_equivalences(), add_child_rel_equivalences(), adjust_appendrel_attrs_multilevel(), apply_child_basequals(), apply_scanjoin_target_to_paths(), build_child_join_rel(), build_child_join_reltarget(), build_child_join_sjinfo(), create_partitionwise_grouping_paths(), make_partitionedrel_pruneinfo(), set_append_rel_size(), and try_partitionwise_join().

◆ adjust_appendrel_attrs_multilevel()

Node* adjust_appendrel_attrs_multilevel ( PlannerInfo root,
Node node,
RelOptInfo childrel,
RelOptInfo parentrel 
)

Definition at line 521 of file appendinfo.c.

524 {
525  AppendRelInfo **appinfos;
526  int nappinfos;
527 
528  /* Recurse if immediate parent is not the top parent. */
529  if (childrel->parent != parentrel)
530  {
531  if (childrel->parent)
532  node = adjust_appendrel_attrs_multilevel(root, node,
533  childrel->parent,
534  parentrel);
535  else
536  elog(ERROR, "childrel is not a child of parentrel");
537  }
538 
539  /* Now translate for this child. */
540  appinfos = find_appinfos_by_relids(root, childrel->relids, &nappinfos);
541 
542  node = adjust_appendrel_attrs(root, node, nappinfos, appinfos);
543 
544  pfree(appinfos);
545 
546  return node;
547 }
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: appendinfo.c:733
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Definition: appendinfo.c:196
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, RelOptInfo *childrel, RelOptInfo *parentrel)
Definition: appendinfo.c:521
void pfree(void *pointer)
Definition: mcxt.c:1456
Relids relids
Definition: pathnodes.h:856

References adjust_appendrel_attrs(), elog(), ERROR, find_appinfos_by_relids(), pfree(), and RelOptInfo::relids.

Referenced by add_child_join_rel_equivalences(), add_child_rel_equivalences(), generate_join_implied_equalities_broken(), get_translated_update_targetlist(), grouping_planner(), and make_partitionedrel_pruneinfo().

◆ adjust_appendrel_attrs_mutator()

static Node * adjust_appendrel_attrs_mutator ( Node node,
adjust_appendrel_attrs_context context 
)
static

Definition at line 215 of file appendinfo.c.

217 {
218  AppendRelInfo **appinfos = context->appinfos;
219  int nappinfos = context->nappinfos;
220  int cnt;
221 
222  if (node == NULL)
223  return NULL;
224  if (IsA(node, Var))
225  {
226  Var *var = (Var *) copyObject(node);
227  AppendRelInfo *appinfo = NULL;
228 
229  if (var->varlevelsup != 0)
230  return (Node *) var; /* no changes needed */
231 
232  /*
233  * You might think we need to adjust var->varnullingrels, but that
234  * shouldn't need any changes. It will contain outer-join relids,
235  * while the transformation we are making affects only baserels.
236  * Below, we just propagate var->varnullingrels into the translated
237  * Var.
238  *
239  * If var->varnullingrels isn't empty, and the translation wouldn't be
240  * a Var, we have to fail. One could imagine wrapping the translated
241  * expression in a PlaceHolderVar, but that won't work because this is
242  * typically used after freezing placeholders. Fortunately, the case
243  * appears unreachable at the moment. We can see nonempty
244  * var->varnullingrels here, but only in cases involving partitionwise
245  * joining, and in such cases the translations will always be Vars.
246  * (Non-Var translations occur only for appendrels made by flattening
247  * UNION ALL subqueries.) Should we need to make this work in future,
248  * a possible fix is to mandate that prepjointree.c create PHVs for
249  * all non-Var outputs of such subqueries, and then we could look up
250  * the pre-existing PHV here. Or perhaps just wrap the translations
251  * that way to begin with?
252  */
253 
254  for (cnt = 0; cnt < nappinfos; cnt++)
255  {
256  if (var->varno == appinfos[cnt]->parent_relid)
257  {
258  appinfo = appinfos[cnt];
259  break;
260  }
261  }
262 
263  if (appinfo)
264  {
265  var->varno = appinfo->child_relid;
266  /* it's now a generated Var, so drop any syntactic labeling */
267  var->varnosyn = 0;
268  var->varattnosyn = 0;
269  if (var->varattno > 0)
270  {
271  Node *newnode;
272 
273  if (var->varattno > list_length(appinfo->translated_vars))
274  elog(ERROR, "attribute %d of relation \"%s\" does not exist",
275  var->varattno, get_rel_name(appinfo->parent_reloid));
276  newnode = copyObject(list_nth(appinfo->translated_vars,
277  var->varattno - 1));
278  if (newnode == NULL)
279  elog(ERROR, "attribute %d of relation \"%s\" does not exist",
280  var->varattno, get_rel_name(appinfo->parent_reloid));
281  if (IsA(newnode, Var))
282  ((Var *) newnode)->varnullingrels = var->varnullingrels;
283  else if (var->varnullingrels != NULL)
284  elog(ERROR, "failed to apply nullingrels to a non-Var");
285  return newnode;
286  }
287  else if (var->varattno == 0)
288  {
289  /*
290  * Whole-row Var: if we are dealing with named rowtypes, we
291  * can use a whole-row Var for the child table plus a coercion
292  * step to convert the tuple layout to the parent's rowtype.
293  * Otherwise we have to generate a RowExpr.
294  */
295  if (OidIsValid(appinfo->child_reltype))
296  {
297  Assert(var->vartype == appinfo->parent_reltype);
298  if (appinfo->parent_reltype != appinfo->child_reltype)
299  {
301 
302  r->arg = (Expr *) var;
303  r->resulttype = appinfo->parent_reltype;
304  r->convertformat = COERCE_IMPLICIT_CAST;
305  r->location = -1;
306  /* Make sure the Var node has the right type ID, too */
307  var->vartype = appinfo->child_reltype;
308  return (Node *) r;
309  }
310  }
311  else
312  {
313  /*
314  * Build a RowExpr containing the translated variables.
315  *
316  * In practice var->vartype will always be RECORDOID here,
317  * so we need to come up with some suitable column names.
318  * We use the parent RTE's column names.
319  *
320  * Note: we can't get here for inheritance cases, so there
321  * is no need to worry that translated_vars might contain
322  * some dummy NULLs.
323  */
324  RowExpr *rowexpr;
325  List *fields;
326  RangeTblEntry *rte;
327 
328  rte = rt_fetch(appinfo->parent_relid,
329  context->root->parse->rtable);
330  fields = copyObject(appinfo->translated_vars);
331  rowexpr = makeNode(RowExpr);
332  rowexpr->args = fields;
333  rowexpr->row_typeid = var->vartype;
334  rowexpr->row_format = COERCE_IMPLICIT_CAST;
335  rowexpr->colnames = copyObject(rte->eref->colnames);
336  rowexpr->location = -1;
337 
338  if (var->varnullingrels != NULL)
339  elog(ERROR, "failed to apply nullingrels to a non-Var");
340 
341  return (Node *) rowexpr;
342  }
343  }
344  /* system attributes don't need any other translation */
345  }
346  else if (var->varno == ROWID_VAR)
347  {
348  /*
349  * If it's a ROWID_VAR placeholder, see if we've reached a leaf
350  * target rel, for which we can translate the Var to a specific
351  * instantiation. We should never be asked to translate to a set
352  * of relids containing more than one leaf target rel, so the
353  * answer will be unique. If we're still considering non-leaf
354  * inheritance levels, return the ROWID_VAR Var as-is.
355  */
356  Relids leaf_result_relids = context->root->leaf_result_relids;
357  Index leaf_relid = 0;
358 
359  for (cnt = 0; cnt < nappinfos; cnt++)
360  {
361  if (bms_is_member(appinfos[cnt]->child_relid,
362  leaf_result_relids))
363  {
364  if (leaf_relid)
365  elog(ERROR, "cannot translate to multiple leaf relids");
366  leaf_relid = appinfos[cnt]->child_relid;
367  }
368  }
369 
370  if (leaf_relid)
371  {
373  list_nth(context->root->row_identity_vars, var->varattno - 1);
374 
375  if (bms_is_member(leaf_relid, ridinfo->rowidrels))
376  {
377  /* Substitute the Var given in the RowIdentityVarInfo */
378  var = copyObject(ridinfo->rowidvar);
379  /* ... but use the correct relid */
380  var->varno = leaf_relid;
381  /* identity vars shouldn't have nulling rels */
382  Assert(var->varnullingrels == NULL);
383  /* varnosyn in the RowIdentityVarInfo is probably wrong */
384  var->varnosyn = 0;
385  var->varattnosyn = 0;
386  }
387  else
388  {
389  /*
390  * This leaf rel can't return the desired value, so
391  * substitute a NULL of the correct type.
392  */
393  return (Node *) makeNullConst(var->vartype,
394  var->vartypmod,
395  var->varcollid);
396  }
397  }
398  }
399  return (Node *) var;
400  }
401  if (IsA(node, CurrentOfExpr))
402  {
403  CurrentOfExpr *cexpr = (CurrentOfExpr *) copyObject(node);
404 
405  for (cnt = 0; cnt < nappinfos; cnt++)
406  {
407  AppendRelInfo *appinfo = appinfos[cnt];
408 
409  if (cexpr->cvarno == appinfo->parent_relid)
410  {
411  cexpr->cvarno = appinfo->child_relid;
412  break;
413  }
414  }
415  return (Node *) cexpr;
416  }
417  if (IsA(node, PlaceHolderVar))
418  {
419  /* Copy the PlaceHolderVar node with correct mutation of subnodes */
420  PlaceHolderVar *phv;
421 
424  (void *) context);
425  /* now fix PlaceHolderVar's relid sets */
426  if (phv->phlevelsup == 0)
427  {
428  phv->phrels = adjust_child_relids(phv->phrels,
429  nappinfos, appinfos);
430  /* as above, we needn't touch phnullingrels */
431  }
432  return (Node *) phv;
433  }
434  /* Shouldn't need to handle planner auxiliary nodes here */
435  Assert(!IsA(node, SpecialJoinInfo));
436  Assert(!IsA(node, AppendRelInfo));
437  Assert(!IsA(node, PlaceHolderInfo));
438  Assert(!IsA(node, MinMaxAggInfo));
439 
440  /*
441  * We have to process RestrictInfo nodes specially. (Note: although
442  * set_append_rel_pathlist will hide RestrictInfos in the parent's
443  * baserestrictinfo list from us, it doesn't hide those in joininfo.)
444  */
445  if (IsA(node, RestrictInfo))
446  {
447  RestrictInfo *oldinfo = (RestrictInfo *) node;
448  RestrictInfo *newinfo = makeNode(RestrictInfo);
449 
450  /* Copy all flat-copiable fields, notably including rinfo_serial */
451  memcpy(newinfo, oldinfo, sizeof(RestrictInfo));
452 
453  /* Recursively fix the clause itself */
454  newinfo->clause = (Expr *)
455  adjust_appendrel_attrs_mutator((Node *) oldinfo->clause, context);
456 
457  /* and the modified version, if an OR clause */
458  newinfo->orclause = (Expr *)
459  adjust_appendrel_attrs_mutator((Node *) oldinfo->orclause, context);
460 
461  /* adjust relid sets too */
462  newinfo->clause_relids = adjust_child_relids(oldinfo->clause_relids,
463  context->nappinfos,
464  context->appinfos);
466  context->nappinfos,
467  context->appinfos);
468  newinfo->outer_relids = adjust_child_relids(oldinfo->outer_relids,
469  context->nappinfos,
470  context->appinfos);
471  newinfo->left_relids = adjust_child_relids(oldinfo->left_relids,
472  context->nappinfos,
473  context->appinfos);
474  newinfo->right_relids = adjust_child_relids(oldinfo->right_relids,
475  context->nappinfos,
476  context->appinfos);
477 
478  /*
479  * Reset cached derivative fields, since these might need to have
480  * different values when considering the child relation. Note we
481  * don't reset left_ec/right_ec: each child variable is implicitly
482  * equivalent to its parent, so still a member of the same EC if any.
483  */
484  newinfo->eval_cost.startup = -1;
485  newinfo->norm_selec = -1;
486  newinfo->outer_selec = -1;
487  newinfo->left_em = NULL;
488  newinfo->right_em = NULL;
489  newinfo->scansel_cache = NIL;
490  newinfo->left_bucketsize = -1;
491  newinfo->right_bucketsize = -1;
492  newinfo->left_mcvfreq = -1;
493  newinfo->right_mcvfreq = -1;
494 
495  return (Node *) newinfo;
496  }
497 
498  /*
499  * NOTE: we do not need to recurse into sublinks, because they should
500  * already have been converted to subplans before we see them.
501  */
502  Assert(!IsA(node, SubLink));
503  Assert(!IsA(node, Query));
504  /* We should never see these Query substructures, either. */
505  Assert(!IsA(node, RangeTblRef));
506  Assert(!IsA(node, JoinExpr));
507 
509  (void *) context);
510 }
Relids adjust_child_relids(Relids relids, int nappinfos, AppendRelInfo **appinfos)
Definition: appendinfo.c:554
unsigned int Index
Definition: c.h:603
#define OidIsValid(objectId)
Definition: c.h:764
char * get_rel_name(Oid relid)
Definition: lsyscache.c:1932
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Definition: makefuncs.c:340
#define expression_tree_mutator(n, m, c)
Definition: nodeFuncs.h:153
#define rt_fetch(rangetable_index, rangetable)
Definition: parsetree.h:31
#define NIL
Definition: pg_list.h:68
static void * list_nth(const List *list, int n)
Definition: pg_list.h:299
@ COERCE_IMPLICIT_CAST
Definition: primnodes.h:663
List * colnames
Definition: primnodes.h:43
Index child_relid
Definition: pathnodes.h:2929
List * translated_vars
Definition: pathnodes.h:2956
Index parent_relid
Definition: pathnodes.h:2928
Oid parent_reltype
Definition: pathnodes.h:2937
Definition: pg_list.h:54
Index phlevelsup
Definition: pathnodes.h:2759
List * rtable
Definition: parsenodes.h:174
Alias * eref
Definition: parsenodes.h:1199
Relids required_relids
Definition: pathnodes.h:2560
Relids outer_relids
Definition: pathnodes.h:2566
Expr * clause
Definition: pathnodes.h:2529
int location
Definition: primnodes.h:1362
List * args
Definition: primnodes.h:1338
AttrNumber varattno
Definition: primnodes.h:238

References adjust_child_relids(), adjust_appendrel_attrs_context::appinfos, ConvertRowtypeExpr::arg, RowExpr::args, Assert(), bms_is_member(), AppendRelInfo::child_relid, AppendRelInfo::child_reltype, RestrictInfo::clause, COERCE_IMPLICIT_CAST, Alias::colnames, copyObject, CurrentOfExpr::cvarno, elog(), RangeTblEntry::eref, ERROR, expression_tree_mutator, get_rel_name(), IsA, PlannerInfo::leaf_result_relids, list_length(), list_nth(), ConvertRowtypeExpr::location, RowExpr::location, makeNode, makeNullConst(), adjust_appendrel_attrs_context::nappinfos, NIL, OidIsValid, RestrictInfo::outer_relids, AppendRelInfo::parent_relid, AppendRelInfo::parent_reloid, AppendRelInfo::parent_reltype, PlannerInfo::parse, PlaceHolderVar::phlevelsup, RestrictInfo::required_relids, ConvertRowtypeExpr::resulttype, adjust_appendrel_attrs_context::root, PlannerInfo::row_identity_vars, ROWID_VAR, RowIdentityVarInfo::rowidrels, RowIdentityVarInfo::rowidvar, rt_fetch, Query::rtable, AppendRelInfo::translated_vars, Var::varattno, Var::varlevelsup, and Var::varno.

Referenced by adjust_appendrel_attrs().

◆ adjust_child_relids()

Relids adjust_child_relids ( Relids  relids,
int  nappinfos,
AppendRelInfo **  appinfos 
)

Definition at line 554 of file appendinfo.c.

555 {
556  Bitmapset *result = NULL;
557  int cnt;
558 
559  for (cnt = 0; cnt < nappinfos; cnt++)
560  {
561  AppendRelInfo *appinfo = appinfos[cnt];
562 
563  /* Remove parent, add child */
564  if (bms_is_member(appinfo->parent_relid, relids))
565  {
566  /* Make a copy if we are changing the set. */
567  if (!result)
568  result = bms_copy(relids);
569 
570  result = bms_del_member(result, appinfo->parent_relid);
571  result = bms_add_member(result, appinfo->child_relid);
572  }
573  }
574 
575  /* If we made any changes, return the modified copy. */
576  if (result)
577  return result;
578 
579  /* Otherwise, return the original set without modification. */
580  return relids;
581 }
Bitmapset * bms_del_member(Bitmapset *a, int x)
Definition: bitmapset.c:793
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:80

References bms_add_member(), bms_copy(), bms_del_member(), bms_is_member(), AppendRelInfo::child_relid, and AppendRelInfo::parent_relid.

Referenced by adjust_appendrel_attrs_mutator(), adjust_child_relids_multilevel(), build_child_join_rel(), build_child_join_sjinfo(), and try_partitionwise_join().

◆ adjust_child_relids_multilevel()

Relids adjust_child_relids_multilevel ( PlannerInfo root,
Relids  relids,
RelOptInfo childrel,
RelOptInfo parentrel 
)

Definition at line 588 of file appendinfo.c.

591 {
592  AppendRelInfo **appinfos;
593  int nappinfos;
594 
595  /*
596  * If the given relids set doesn't contain any of the parent relids, it
597  * will remain unchanged.
598  */
599  if (!bms_overlap(relids, parentrel->relids))
600  return relids;
601 
602  /* Recurse if immediate parent is not the top parent. */
603  if (childrel->parent != parentrel)
604  {
605  if (childrel->parent)
606  relids = adjust_child_relids_multilevel(root, relids,
607  childrel->parent,
608  parentrel);
609  else
610  elog(ERROR, "childrel is not a child of parentrel");
611  }
612 
613  /* Now translate for this child. */
614  appinfos = find_appinfos_by_relids(root, childrel->relids, &nappinfos);
615 
616  relids = adjust_child_relids(relids, nappinfos, appinfos);
617 
618  pfree(appinfos);
619 
620  return relids;
621 }
Relids adjust_child_relids_multilevel(PlannerInfo *root, Relids relids, RelOptInfo *childrel, RelOptInfo *parentrel)
Definition: appendinfo.c:588
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:527

References adjust_child_relids(), bms_overlap(), elog(), ERROR, find_appinfos_by_relids(), pfree(), and RelOptInfo::relids.

Referenced by reparameterize_path_by_child().

◆ adjust_inherited_attnums()

List* adjust_inherited_attnums ( List attnums,
AppendRelInfo context 
)

Definition at line 628 of file appendinfo.c.

629 {
630  List *result = NIL;
631  ListCell *lc;
632 
633  /* This should only happen for an inheritance case, not UNION ALL */
634  Assert(OidIsValid(context->parent_reloid));
635 
636  /* Look up each attribute in the AppendRelInfo's translated_vars list */
637  foreach(lc, attnums)
638  {
639  AttrNumber parentattno = lfirst_int(lc);
640  Var *childvar;
641 
642  /* Look up the translation of this column: it must be a Var */
643  if (parentattno <= 0 ||
644  parentattno > list_length(context->translated_vars))
645  elog(ERROR, "attribute %d of relation \"%s\" does not exist",
646  parentattno, get_rel_name(context->parent_reloid));
647  childvar = (Var *) list_nth(context->translated_vars, parentattno - 1);
648  if (childvar == NULL || !IsA(childvar, Var))
649  elog(ERROR, "attribute %d of relation \"%s\" does not exist",
650  parentattno, get_rel_name(context->parent_reloid));
651 
652  result = lappend_int(result, childvar->varattno);
653  }
654  return result;
655 }
int16 AttrNumber
Definition: attnum.h:21
List * lappend_int(List *list, int datum)
Definition: list.c:356
#define lfirst_int(lc)
Definition: pg_list.h:173

References Assert(), elog(), ERROR, get_rel_name(), IsA, lappend_int(), lfirst_int, list_length(), list_nth(), NIL, OidIsValid, AppendRelInfo::parent_reloid, AppendRelInfo::translated_vars, and Var::varattno.

Referenced by adjust_inherited_attnums_multilevel().

◆ adjust_inherited_attnums_multilevel()

List* adjust_inherited_attnums_multilevel ( PlannerInfo root,
List attnums,
Index  child_relid,
Index  top_parent_relid 
)

Definition at line 662 of file appendinfo.c.

664 {
665  AppendRelInfo *appinfo = root->append_rel_array[child_relid];
666 
667  if (!appinfo)
668  elog(ERROR, "child rel %d not found in append_rel_array", child_relid);
669 
670  /* Recurse if immediate parent is not the top parent. */
671  if (appinfo->parent_relid != top_parent_relid)
672  attnums = adjust_inherited_attnums_multilevel(root, attnums,
673  appinfo->parent_relid,
674  top_parent_relid);
675 
676  /* Now translate for this child */
677  return adjust_inherited_attnums(attnums, appinfo);
678 }
List * adjust_inherited_attnums(List *attnums, AppendRelInfo *context)
Definition: appendinfo.c:628
List * adjust_inherited_attnums_multilevel(PlannerInfo *root, List *attnums, Index child_relid, Index top_parent_relid)
Definition: appendinfo.c:662

References adjust_inherited_attnums(), elog(), ERROR, and AppendRelInfo::parent_relid.

Referenced by get_translated_update_targetlist(), and grouping_planner().

◆ distribute_row_identity_vars()

void distribute_row_identity_vars ( PlannerInfo root)

Definition at line 966 of file appendinfo.c.

967 {
968  Query *parse = root->parse;
969  int result_relation = parse->resultRelation;
970  RangeTblEntry *target_rte;
971  RelOptInfo *target_rel;
972  ListCell *lc;
973 
974  /*
975  * There's nothing to do if this isn't an inherited UPDATE/DELETE/MERGE.
976  */
977  if (parse->commandType != CMD_UPDATE && parse->commandType != CMD_DELETE &&
978  parse->commandType != CMD_MERGE)
979  {
980  Assert(root->row_identity_vars == NIL);
981  return;
982  }
983  target_rte = rt_fetch(result_relation, parse->rtable);
984  if (!target_rte->inh)
985  {
986  Assert(root->row_identity_vars == NIL);
987  return;
988  }
989 
990  /*
991  * Ordinarily, we expect that leaf result relation(s) will have added some
992  * ROWID_VAR Vars to the query. However, it's possible that constraint
993  * exclusion suppressed every leaf relation. The executor will get upset
994  * if the plan has no row identity columns at all, even though it will
995  * certainly process no rows. Handle this edge case by re-opening the top
996  * result relation and adding the row identity columns it would have used,
997  * as preprocess_targetlist() would have done if it weren't marked "inh".
998  * Then re-run build_base_rel_tlists() to ensure that the added columns
999  * get propagated to the relation's reltarget. (This is a bit ugly, but
1000  * it seems better to confine the ugliness and extra cycles to this
1001  * unusual corner case.)
1002  */
1003  if (root->row_identity_vars == NIL)
1004  {
1005  Relation target_relation;
1006 
1007  target_relation = table_open(target_rte->relid, NoLock);
1008  add_row_identity_columns(root, result_relation,
1009  target_rte, target_relation);
1010  table_close(target_relation, NoLock);
1012  /* There are no ROWID_VAR Vars in this case, so we're done. */
1013  return;
1014  }
1015 
1016  /*
1017  * Dig through the processed_tlist to find the ROWID_VAR reference Vars,
1018  * and forcibly copy them into the reltarget list of the topmost target
1019  * relation. That's sufficient because they'll be copied to the
1020  * individual leaf target rels (with appropriate translation) later,
1021  * during appendrel expansion --- see set_append_rel_size().
1022  */
1023  target_rel = find_base_rel(root, result_relation);
1024 
1025  foreach(lc, root->processed_tlist)
1026  {
1027  TargetEntry *tle = lfirst(lc);
1028  Var *var = (Var *) tle->expr;
1029 
1030  if (var && IsA(var, Var) && var->varno == ROWID_VAR)
1031  {
1032  target_rel->reltarget->exprs =
1033  lappend(target_rel->reltarget->exprs, copyObject(var));
1034  /* reltarget cost and width will be computed later */
1035  }
1036  }
1037 }
void add_row_identity_columns(PlannerInfo *root, Index rtindex, RangeTblEntry *target_rte, Relation target_relation)
Definition: appendinfo.c:884
void build_base_rel_tlists(PlannerInfo *root, List *final_tlist)
Definition: initsplan.c:235
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
#define NoLock
Definition: lockdefs.h:34
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
Definition: regcomp.c:715
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
Definition: relnode.c:405
List * exprs
Definition: pathnodes.h:1501
struct PathTarget * reltarget
Definition: pathnodes.h:878
Expr * expr
Definition: primnodes.h:1895
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40

References add_row_identity_columns(), Assert(), build_base_rel_tlists(), CMD_DELETE, CMD_MERGE, CMD_UPDATE, copyObject, TargetEntry::expr, PathTarget::exprs, find_base_rel(), if(), RangeTblEntry::inh, IsA, lappend(), lfirst, NIL, NoLock, parse(), PlannerInfo::parse, PlannerInfo::processed_tlist, RangeTblEntry::relid, RelOptInfo::reltarget, PlannerInfo::row_identity_vars, ROWID_VAR, rt_fetch, table_close(), table_open(), and Var::varno.

Referenced by query_planner().

◆ find_appinfos_by_relids()

AppendRelInfo** find_appinfos_by_relids ( PlannerInfo root,
Relids  relids,
int *  nappinfos 
)

Definition at line 733 of file appendinfo.c.

734 {
735  AppendRelInfo **appinfos;
736  int cnt = 0;
737  int i;
738 
739  /* Allocate an array that's certainly big enough */
740  appinfos = (AppendRelInfo **)
741  palloc(sizeof(AppendRelInfo *) * bms_num_members(relids));
742 
743  i = -1;
744  while ((i = bms_next_member(relids, i)) >= 0)
745  {
746  AppendRelInfo *appinfo = root->append_rel_array[i];
747 
748  if (!appinfo)
749  {
750  /* Probably i is an OJ index, but let's check */
751  if (find_base_rel_ignore_join(root, i) == NULL)
752  continue;
753  /* It's a base rel, but we lack an append_rel_array entry */
754  elog(ERROR, "child rel %d not found in append_rel_array", i);
755  }
756 
757  appinfos[cnt++] = appinfo;
758  }
759  *nappinfos = cnt;
760  return appinfos;
761 }
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1106
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:685
int i
Definition: isn.c:73
void * palloc(Size size)
Definition: mcxt.c:1226
RelOptInfo * find_base_rel_ignore_join(PlannerInfo *root, int relid)
Definition: relnode.c:432

References bms_next_member(), bms_num_members(), elog(), ERROR, find_base_rel_ignore_join(), i, and palloc().

Referenced by adjust_appendrel_attrs_multilevel(), adjust_child_relids_multilevel(), apply_scanjoin_target_to_paths(), build_child_join_rel(), build_child_join_sjinfo(), create_partitionwise_grouping_paths(), make_partitionedrel_pruneinfo(), and try_partitionwise_join().

◆ get_translated_update_targetlist()

void get_translated_update_targetlist ( PlannerInfo root,
Index  relid,
List **  processed_tlist,
List **  update_colnos 
)

Definition at line 690 of file appendinfo.c.

692 {
693  /* This is pretty meaningless for commands other than UPDATE. */
694  Assert(root->parse->commandType == CMD_UPDATE);
695  if (relid == root->parse->resultRelation)
696  {
697  /*
698  * Non-inheritance case, so it's easy. The caller might be expecting
699  * a tree it can scribble on, though, so copy.
700  */
701  *processed_tlist = copyObject(root->processed_tlist);
702  if (update_colnos)
703  *update_colnos = copyObject(root->update_colnos);
704  }
705  else
706  {
707  Assert(bms_is_member(relid, root->all_result_relids));
708  *processed_tlist = (List *)
710  (Node *) root->processed_tlist,
711  find_base_rel(root, relid),
712  find_base_rel(root, root->parse->resultRelation));
713  if (update_colnos)
714  *update_colnos =
716  relid,
717  root->parse->resultRelation);
718  }
719 }
List * update_colnos
Definition: pathnodes.h:461
Relids all_result_relids
Definition: pathnodes.h:351

References adjust_appendrel_attrs_multilevel(), adjust_inherited_attnums_multilevel(), PlannerInfo::all_result_relids, Assert(), bms_is_member(), CMD_UPDATE, Query::commandType, copyObject, find_base_rel(), PlannerInfo::parse, PlannerInfo::processed_tlist, and PlannerInfo::update_colnos.

Referenced by postgresPlanDirectModify().

◆ make_append_rel_info()

AppendRelInfo* make_append_rel_info ( Relation  parentrel,
Relation  childrel,
Index  parentRTindex,
Index  childRTindex 
)

Definition at line 51 of file appendinfo.c.

53 {
55 
56  appinfo->parent_relid = parentRTindex;
57  appinfo->child_relid = childRTindex;
58  appinfo->parent_reltype = parentrel->rd_rel->reltype;
59  appinfo->child_reltype = childrel->rd_rel->reltype;
60  make_inh_translation_list(parentrel, childrel, childRTindex, appinfo);
61  appinfo->parent_reloid = RelationGetRelid(parentrel);
62 
63  return appinfo;
64 }
static void make_inh_translation_list(Relation oldrelation, Relation newrelation, Index newvarno, AppendRelInfo *appinfo)
Definition: appendinfo.c:80
#define RelationGetRelid(relation)
Definition: rel.h:504

References AppendRelInfo::child_relid, AppendRelInfo::child_reltype, make_inh_translation_list(), makeNode, AppendRelInfo::parent_relid, AppendRelInfo::parent_reloid, AppendRelInfo::parent_reltype, RelationData::rd_rel, and RelationGetRelid.

Referenced by expand_single_inheritance_child().

◆ make_inh_translation_list()

static void make_inh_translation_list ( Relation  oldrelation,
Relation  newrelation,
Index  newvarno,
AppendRelInfo appinfo 
)
static

Definition at line 80 of file appendinfo.c.

83 {
84  List *vars = NIL;
85  AttrNumber *pcolnos;
86  TupleDesc old_tupdesc = RelationGetDescr(oldrelation);
87  TupleDesc new_tupdesc = RelationGetDescr(newrelation);
88  Oid new_relid = RelationGetRelid(newrelation);
89  int oldnatts = old_tupdesc->natts;
90  int newnatts = new_tupdesc->natts;
91  int old_attno;
92  int new_attno = 0;
93 
94  /* Initialize reverse-translation array with all entries zero */
95  appinfo->num_child_cols = newnatts;
96  appinfo->parent_colnos = pcolnos =
97  (AttrNumber *) palloc0(newnatts * sizeof(AttrNumber));
98 
99  for (old_attno = 0; old_attno < oldnatts; old_attno++)
100  {
101  Form_pg_attribute att;
102  char *attname;
103  Oid atttypid;
104  int32 atttypmod;
105  Oid attcollation;
106 
107  att = TupleDescAttr(old_tupdesc, old_attno);
108  if (att->attisdropped)
109  {
110  /* Just put NULL into this list entry */
111  vars = lappend(vars, NULL);
112  continue;
113  }
114  attname = NameStr(att->attname);
115  atttypid = att->atttypid;
116  atttypmod = att->atttypmod;
117  attcollation = att->attcollation;
118 
119  /*
120  * When we are generating the "translation list" for the parent table
121  * of an inheritance set, no need to search for matches.
122  */
123  if (oldrelation == newrelation)
124  {
125  vars = lappend(vars, makeVar(newvarno,
126  (AttrNumber) (old_attno + 1),
127  atttypid,
128  atttypmod,
129  attcollation,
130  0));
131  pcolnos[old_attno] = old_attno + 1;
132  continue;
133  }
134 
135  /*
136  * Otherwise we have to search for the matching column by name.
137  * There's no guarantee it'll have the same column position, because
138  * of cases like ALTER TABLE ADD COLUMN and multiple inheritance.
139  * However, in simple cases, the relative order of columns is mostly
140  * the same in both relations, so try the column of newrelation that
141  * follows immediately after the one that we just found, and if that
142  * fails, let syscache handle it.
143  */
144  if (new_attno >= newnatts ||
145  (att = TupleDescAttr(new_tupdesc, new_attno))->attisdropped ||
146  strcmp(attname, NameStr(att->attname)) != 0)
147  {
148  HeapTuple newtup;
149 
150  newtup = SearchSysCacheAttName(new_relid, attname);
151  if (!HeapTupleIsValid(newtup))
152  elog(ERROR, "could not find inherited attribute \"%s\" of relation \"%s\"",
153  attname, RelationGetRelationName(newrelation));
154  new_attno = ((Form_pg_attribute) GETSTRUCT(newtup))->attnum - 1;
155  Assert(new_attno >= 0 && new_attno < newnatts);
156  ReleaseSysCache(newtup);
157 
158  att = TupleDescAttr(new_tupdesc, new_attno);
159  }
160 
161  /* Found it, check type and collation match */
162  if (atttypid != att->atttypid || atttypmod != att->atttypmod)
163  elog(ERROR, "attribute \"%s\" of relation \"%s\" does not match parent's type",
164  attname, RelationGetRelationName(newrelation));
165  if (attcollation != att->attcollation)
166  elog(ERROR, "attribute \"%s\" of relation \"%s\" does not match parent's collation",
167  attname, RelationGetRelationName(newrelation));
168 
169  vars = lappend(vars, makeVar(newvarno,
170  (AttrNumber) (new_attno + 1),
171  atttypid,
172  atttypmod,
173  attcollation,
174  0));
175  pcolnos[new_attno] = old_attno + 1;
176  new_attno++;
177  }
178 
179  appinfo->translated_vars = vars;
180 }
#define NameStr(name)
Definition: c.h:735
signed int int32
Definition: c.h:483
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define GETSTRUCT(TUP)
Definition: htup_details.h:653
void * palloc0(Size size)
Definition: mcxt.c:1257
NameData attname
Definition: pg_attribute.h:41
int16 attnum
Definition: pg_attribute.h:74
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:209
unsigned int Oid
Definition: postgres_ext.h:31
#define RelationGetDescr(relation)
Definition: rel.h:530
#define RelationGetRelationName(relation)
Definition: rel.h:538
int num_child_cols
Definition: pathnodes.h:2964
Definition: regcomp.c:281
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:868
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
Definition: syscache.c:961
#define TupleDescAttr(tupdesc, i)
Definition: tupdesc.h:92

References Assert(), attname, attnum, elog(), ERROR, GETSTRUCT, HeapTupleIsValid, lappend(), makeVar(), NameStr, TupleDescData::natts, NIL, AppendRelInfo::num_child_cols, palloc0(), RelationGetDescr, RelationGetRelationName, RelationGetRelid, ReleaseSysCache(), SearchSysCacheAttName(), AppendRelInfo::translated_vars, and TupleDescAttr.

Referenced by make_append_rel_info().