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

907{
908 CmdType commandType = root->parse->commandType;
909 char relkind = target_relation->rd_rel->relkind;
910 Var *var;
911
912 Assert(commandType == CMD_UPDATE || commandType == CMD_DELETE || commandType == CMD_MERGE);
913
914 if (relkind == RELKIND_RELATION ||
915 relkind == RELKIND_MATVIEW ||
916 relkind == RELKIND_PARTITIONED_TABLE)
917 {
918 /*
919 * Emit CTID so that executor can find the row to merge, update or
920 * delete.
921 */
922 var = makeVar(rtindex,
924 TIDOID,
925 -1,
927 0);
928 add_row_identity_var(root, var, rtindex, "ctid");
929 }
930 else if (relkind == RELKIND_FOREIGN_TABLE)
931 {
932 /*
933 * Let the foreign table's FDW add whatever junk TLEs it wants.
934 */
935 FdwRoutine *fdwroutine;
936
937 fdwroutine = GetFdwRoutineForRelation(target_relation, false);
938
939 if (fdwroutine->AddForeignUpdateTargets != NULL)
940 fdwroutine->AddForeignUpdateTargets(root, rtindex,
941 target_rte, target_relation);
942
943 /*
944 * For UPDATE, we need to make the FDW fetch unchanged columns by
945 * asking it to fetch a whole-row Var. That's because the top-level
946 * targetlist only contains entries for changed columns, but
947 * ExecUpdate will need to build the complete new tuple. (Actually,
948 * we only really need this in UPDATEs that are not pushed to the
949 * remote side, but it's hard to tell if that will be the case at the
950 * point when this function is called.)
951 *
952 * We will also need the whole row if there are any row triggers, so
953 * that the executor will have the "old" row to pass to the trigger.
954 * Alas, this misses system columns.
955 */
956 if (commandType == CMD_UPDATE ||
957 (target_relation->trigdesc &&
958 (target_relation->trigdesc->trig_delete_after_row ||
959 target_relation->trigdesc->trig_delete_before_row)))
960 {
961 var = makeVar(rtindex,
963 RECORDOID,
964 -1,
966 0);
967 add_row_identity_var(root, var, rtindex, "wholerow");
968 }
969 }
970}
void add_row_identity_var(PlannerInfo *root, Var *orig_var, Index rtindex, const char *rowid_name)
Definition: appendinfo.c:809
#define InvalidAttrNumber
Definition: attnum.h:23
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
Definition: foreign.c:442
Assert(PointerIsAligned(start, uint64))
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
Definition: makefuncs.c:66
CmdType
Definition: nodes.h:265
@ CMD_MERGE
Definition: nodes.h:271
@ CMD_DELETE
Definition: nodes.h:270
@ CMD_UPDATE
Definition: nodes.h:268
#define InvalidOid
Definition: postgres_ext.h:37
tree ctl root
Definition: radixtree.h:1857
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:262
#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 809 of file appendinfo.c.

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

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
215 return adjust_appendrel_attrs_mutator(node, &context);
216}
static Node * adjust_appendrel_attrs_mutator(Node *node, adjust_appendrel_attrs_context *context)
Definition: appendinfo.c:219
AppendRelInfo ** appinfos
Definition: appendinfo.c:35

References adjust_appendrel_attrs_mutator(), adjust_appendrel_attrs_context::appinfos, Assert(), IsA, adjust_appendrel_attrs_context::nappinfos, adjust_appendrel_attrs_context::root, 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 541 of file appendinfo.c.

544{
545 AppendRelInfo **appinfos;
546 int nappinfos;
547
548 /* Recurse if immediate parent is not the top parent. */
549 if (childrel->parent != parentrel)
550 {
551 if (childrel->parent)
553 childrel->parent,
554 parentrel);
555 else
556 elog(ERROR, "childrel is not a child of parentrel");
557 }
558
559 /* Now translate for this child. */
560 appinfos = find_appinfos_by_relids(root, childrel->relids, &nappinfos);
561
562 node = adjust_appendrel_attrs(root, node, nappinfos, appinfos);
563
564 pfree(appinfos);
565
566 return node;
567}
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: appendinfo.c:753
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:541
void pfree(void *pointer)
Definition: mcxt.c:1524
Relids relids
Definition: pathnodes.h:898

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

Referenced by add_child_join_rel_equivalences(), add_child_rel_equivalences(), adjust_appendrel_attrs_multilevel(), 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 574 of file appendinfo.c.

575{
576 Bitmapset *result = NULL;
577 int cnt;
578
579 for (cnt = 0; cnt < nappinfos; cnt++)
580 {
581 AppendRelInfo *appinfo = appinfos[cnt];
582
583 /* Remove parent, add child */
584 if (bms_is_member(appinfo->parent_relid, relids))
585 {
586 /* Make a copy if we are changing the set. */
587 if (!result)
588 result = bms_copy(relids);
589
590 result = bms_del_member(result, appinfo->parent_relid);
591 result = bms_add_member(result, appinfo->child_relid);
592 }
593 }
594
595 /* If we made any changes, return the modified copy. */
596 if (result)
597 return result;
598
599 /* Otherwise, return the original set without modification. */
600 return relids;
601}
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:3008
Index parent_relid
Definition: pathnodes.h:3007

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

611{
612 AppendRelInfo **appinfos;
613 int nappinfos;
614
615 /*
616 * If the given relids set doesn't contain any of the parent relids, it
617 * will remain unchanged.
618 */
619 if (!bms_overlap(relids, parentrel->relids))
620 return relids;
621
622 /* Recurse if immediate parent is not the top parent. */
623 if (childrel->parent != parentrel)
624 {
625 if (childrel->parent)
626 relids = adjust_child_relids_multilevel(root, relids,
627 childrel->parent,
628 parentrel);
629 else
630 elog(ERROR, "childrel is not a child of parentrel");
631 }
632
633 /* Now translate for this child. */
634 appinfos = find_appinfos_by_relids(root, childrel->relids, &nappinfos);
635
636 relids = adjust_child_relids(relids, nappinfos, appinfos);
637
638 pfree(appinfos);
639
640 return relids;
641}
Relids adjust_child_relids_multilevel(PlannerInfo *root, Relids relids, RelOptInfo *childrel, RelOptInfo *parentrel)
Definition: appendinfo.c:608
Relids adjust_child_relids(Relids relids, int nappinfos, AppendRelInfo **appinfos)
Definition: appendinfo.c:574
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:582

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

Referenced by adjust_child_relids_multilevel(), and reparameterize_path_by_child().

◆ adjust_inherited_attnums()

List * adjust_inherited_attnums ( List attnums,
AppendRelInfo context 
)

Definition at line 648 of file appendinfo.c.

649{
650 List *result = NIL;
651 ListCell *lc;
652
653 /* This should only happen for an inheritance case, not UNION ALL */
655
656 /* Look up each attribute in the AppendRelInfo's translated_vars list */
657 foreach(lc, attnums)
658 {
659 AttrNumber parentattno = lfirst_int(lc);
660 Var *childvar;
661
662 /* Look up the translation of this column: it must be a Var */
663 if (parentattno <= 0 ||
664 parentattno > list_length(context->translated_vars))
665 elog(ERROR, "attribute %d of relation \"%s\" does not exist",
666 parentattno, get_rel_name(context->parent_reloid));
667 childvar = (Var *) list_nth(context->translated_vars, parentattno - 1);
668 if (childvar == NULL || !IsA(childvar, Var))
669 elog(ERROR, "attribute %d of relation \"%s\" does not exist",
670 parentattno, get_rel_name(context->parent_reloid));
671
672 result = lappend_int(result, childvar->varattno);
673 }
674 return result;
675}
int16 AttrNumber
Definition: attnum.h:21
#define OidIsValid(objectId)
Definition: c.h:746
List * lappend_int(List *list, int datum)
Definition: list.c:357
char * get_rel_name(Oid relid)
Definition: lsyscache.c:2011
#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
List * translated_vars
Definition: pathnodes.h:3035
Definition: pg_list.h:54
AttrNumber varattno
Definition: primnodes.h:274

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

684{
685 AppendRelInfo *appinfo = root->append_rel_array[child_relid];
686
687 if (!appinfo)
688 elog(ERROR, "child rel %d not found in append_rel_array", child_relid);
689
690 /* Recurse if immediate parent is not the top parent. */
691 if (appinfo->parent_relid != top_parent_relid)
692 attnums = adjust_inherited_attnums_multilevel(root, attnums,
693 appinfo->parent_relid,
694 top_parent_relid);
695
696 /* Now translate for this child */
697 return adjust_inherited_attnums(attnums, appinfo);
698}
List * adjust_inherited_attnums_multilevel(PlannerInfo *root, List *attnums, Index child_relid, Index top_parent_relid)
Definition: appendinfo.c:682
List * adjust_inherited_attnums(List *attnums, AppendRelInfo *context)
Definition: appendinfo.c:648

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

Referenced by adjust_inherited_attnums_multilevel(), get_translated_update_targetlist(), and grouping_planner().

◆ distribute_row_identity_vars()

void distribute_row_identity_vars ( PlannerInfo root)

Definition at line 985 of file appendinfo.c.

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

754{
755 AppendRelInfo **appinfos;
756 int cnt = 0;
757 int i;
758
759 /* Allocate an array that's certainly big enough */
760 appinfos = (AppendRelInfo **)
761 palloc(sizeof(AppendRelInfo *) * bms_num_members(relids));
762
763 i = -1;
764 while ((i = bms_next_member(relids, i)) >= 0)
765 {
766 AppendRelInfo *appinfo = root->append_rel_array[i];
767
768 if (!appinfo)
769 {
770 /* Probably i is an OJ index, but let's check */
771 if (find_base_rel_ignore_join(root, i) == NULL)
772 continue;
773 /* It's a base rel, but we lack an append_rel_array entry */
774 elog(ERROR, "child rel %d not found in append_rel_array", i);
775 }
776
777 appinfos[cnt++] = appinfo;
778 }
779 *nappinfos = cnt;
780 return appinfos;
781}
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:74
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_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 710 of file appendinfo.c.

712{
713 /* This is pretty meaningless for commands other than UPDATE. */
714 Assert(root->parse->commandType == CMD_UPDATE);
715 if (relid == root->parse->resultRelation)
716 {
717 /*
718 * Non-inheritance case, so it's easy. The caller might be expecting
719 * a tree it can scribble on, though, so copy.
720 */
721 *processed_tlist = copyObject(root->processed_tlist);
722 if (update_colnos)
723 *update_colnos = copyObject(root->update_colnos);
724 }
725 else
726 {
727 Assert(bms_is_member(relid, root->all_result_relids));
728 *processed_tlist = (List *)
730 (Node *) root->processed_tlist,
731 find_base_rel(root, relid),
732 find_base_rel(root, root->parse->resultRelation));
733 if (update_colnos)
734 *update_colnos =
736 relid,
737 root->parse->resultRelation);
738 }
739}

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:512
Oid parent_reltype
Definition: pathnodes.h:3016

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