PostgreSQL Source Code  git master
appendinfo.h File Reference
#include "nodes/pathnodes.h"
#include "utils/relcache.h"
Include dependency graph for appendinfo.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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 888 of file appendinfo.c.

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

References add_row_identity_var(), FdwRoutine::AddForeignUpdateTargets, Assert, CMD_DELETE, CMD_MERGE, CMD_UPDATE, GetFdwRoutineForRelation(), InvalidAttrNumber, InvalidOid, makeVar(), RelationData::rd_rel, root, 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 793 of file appendinfo.c.

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

References Assert, bms_add_member(), bms_is_member(), bms_make_singleton(), copyObject, elog, equal(), ERROR, exprType(), exprTypmod(), get_typavgwidth(), IsA, lappend(), lfirst, list_length(), makeNode, makeTargetEntry(), pstrdup(), root, 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 200 of file appendinfo.c.

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

References adjust_appendrel_attrs_mutator(), Assert, context, IsA, and 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 525 of file appendinfo.c.

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

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

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_child_relids()

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

Definition at line 558 of file appendinfo.c.

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

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 592 of file appendinfo.c.

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

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

Referenced by reparameterize_path_by_child().

◆ adjust_inherited_attnums()

List* adjust_inherited_attnums ( List attnums,
AppendRelInfo context 
)

Definition at line 632 of file appendinfo.c.

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

References Assert, context, elog, ERROR, get_rel_name(), IsA, lappend_int(), lfirst_int, list_length(), list_nth(), NIL, OidIsValid, 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 666 of file appendinfo.c.

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

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

Referenced by get_translated_update_targetlist(), and grouping_planner().

◆ distribute_row_identity_vars()

void distribute_row_identity_vars ( PlannerInfo root)

Definition at line 969 of file appendinfo.c.

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

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

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

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 694 of file appendinfo.c.

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

References adjust_appendrel_attrs_multilevel(), adjust_inherited_attnums_multilevel(), Assert, bms_is_member(), CMD_UPDATE, copyObject, find_base_rel(), and root.

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:505
Oid parent_reltype
Definition: pathnodes.h:2978

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().