88 int oldnatts = old_tupdesc->
natts;
89 int newnatts = new_tupdesc->
natts;
98 for (old_attno = 0; old_attno < oldnatts; old_attno++)
107 if (att->attisdropped)
114 atttypid = att->atttypid;
115 atttypmod = att->atttypmod;
116 attcollation = att->attcollation;
122 if (oldrelation == newrelation)
130 pcolnos[old_attno] = old_attno + 1;
143 if (new_attno >= newnatts ||
144 (att =
TupleDescAttr(new_tupdesc, new_attno))->attisdropped ||
151 elog(
ERROR,
"could not find inherited attribute \"%s\" of relation \"%s\"",
154 Assert(new_attno >= 0 && new_attno < newnatts);
161 if (atttypid != att->atttypid || atttypmod != att->atttypmod)
162 elog(
ERROR,
"attribute \"%s\" of relation \"%s\" does not match parent's type",
164 if (attcollation != att->attcollation)
165 elog(
ERROR,
"attribute \"%s\" of relation \"%s\" does not match parent's collation",
174 pcolnos[new_attno] = old_attno + 1;
205 Assert(nappinfos >= 1 && appinfos != NULL);
231 for (cnt = 0; cnt < nappinfos; cnt++)
235 appinfo = appinfos[cnt];
251 elog(
ERROR,
"attribute %d of relation \"%s\" does not exist",
256 elog(
ERROR,
"attribute %d of relation \"%s\" does not exist",
305 rowexpr->
args = fields;
311 return (
Node *) rowexpr;
327 Index leaf_relid = 0;
329 for (cnt = 0; cnt < nappinfos; cnt++)
335 elog(
ERROR,
"cannot translate to multiple leaf relids");
350 var->
varno = leaf_relid;
373 for (cnt = 0; cnt < nappinfos; cnt++)
383 return (
Node *) cexpr;
463 return (
Node *) newinfo;
502 for (cnt = 0; cnt < nappinfos; cnt++)
510 if (!
bms_equal(parent_relids, top_parent_relids))
532 for (cnt = 0; cnt < nappinfos; cnt++)
567 Relids parent_relids = NULL;
582 for (cnt = 0; cnt < nappinfos; cnt++)
590 if (!
bms_equal(parent_relids, top_parent_relids))
629 if (parentattno <= 0 ||
631 elog(
ERROR,
"attribute %d of relation \"%s\" does not exist",
634 if (childvar == NULL || !
IsA(childvar,
Var))
635 elog(
ERROR,
"attribute %d of relation \"%s\" does not exist",
654 elog(
ERROR,
"child rel %d not found in append_rel_array", child_relid);
677 List **processed_tlist,
List **update_colnos)
694 *processed_tlist = (
List *)
730 elog(
ERROR,
"child rel %d not found in append_rel_array",
i);
732 appinfos[cnt++] = appinfo;
764 Index rtindex,
const char *rowid_name)
811 if (strcmp(rowid_name, ridinfo->
rowidname) != 0)
822 elog(
ERROR,
"conflicting uses of row-identity name \"%s\"",
862 char relkind = target_relation->
rd_rel->relkind;
868 relkind == RELKIND_RELATION ||
869 relkind == RELKIND_MATVIEW ||
870 relkind == RELKIND_PARTITIONED_TABLE)
884 else if (relkind == RELKIND_FOREIGN_TABLE)
895 target_rte, target_relation);
942 int result_relation =
parse->resultRelation;
957 if (!target_rte->
inh)
981 target_rte, target_relation);
void distribute_row_identity_vars(PlannerInfo *root)
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)
static void make_inh_translation_list(Relation oldrelation, Relation newrelation, Index newvarno, AppendRelInfo *appinfo)
Relids adjust_child_relids_multilevel(PlannerInfo *root, Relids relids, Relids child_relids, Relids top_parent_relids)
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
void add_row_identity_columns(PlannerInfo *root, Index rtindex, RangeTblEntry *target_rte, Relation target_relation)
static Node * adjust_appendrel_attrs_mutator(Node *node, adjust_appendrel_attrs_context *context)
AppendRelInfo * make_append_rel_info(Relation parentrel, Relation childrel, Index parentRTindex, Index childRTindex)
Relids adjust_child_relids(Relids relids, int nappinfos, AppendRelInfo **appinfos)
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids)
List * adjust_inherited_attnums(List *attnums, AppendRelInfo *context)
List * adjust_inherited_attnums_multilevel(PlannerInfo *root, List *attnums, Index child_relid, Index top_parent_relid)
void add_row_identity_var(PlannerInfo *root, Var *orig_var, Index rtindex, const char *rowid_name)
#define InvalidAttrNumber
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
void bms_free(Bitmapset *a)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_del_member(Bitmapset *a, int x)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
#define OidIsValid(objectId)
bool equal(const void *a, const void *b)
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
#define HeapTupleIsValid(tuple)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lappend(List *list, void *datum)
List * lappend_int(List *list, int datum)
char * get_rel_name(Oid relid)
int32 get_typavgwidth(Oid typid, int32 typmod)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Const * makeNullConst(Oid consttype, int32 consttypmod, Oid constcollid)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
Oid exprType(const Node *expr)
int32 exprTypmod(const Node *expr)
Node * expression_tree_mutator(Node *node, Node *(*mutator)(), void *context)
#define IsA(nodeptr, _type_)
#define rt_fetch(rangetable_index, rangetable)
FormData_pg_attribute * Form_pg_attribute
static int list_length(const List *l)
static void * list_nth(const List *list, int n)
static struct subre * parse(struct vars *, int, int, struct state *, struct state *)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
AttrNumber * parent_colnos
CoercionForm convertformat
AddForeignUpdateTargets_function AddForeignUpdateTargets
struct AppendRelInfo ** append_rel_array
Relids leaf_result_relids
struct PathTarget * reltarget
Selectivity right_bucketsize
Selectivity left_bucketsize
EquivalenceMember * left_em
EquivalenceMember * right_em
Selectivity right_mcvfreq
bool trig_delete_before_row
bool trig_delete_after_row
AppendRelInfo ** appinfos
#define SelfItemPointerAttributeNumber
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCacheAttName(Oid relid, const char *attname)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
#define TupleDescAttr(tupdesc, i)