89 int oldnatts = old_tupdesc->
natts;
90 int newnatts = new_tupdesc->
natts;
96 appinfo->parent_colnos = pcolnos =
99 for (old_attno = 0; old_attno < oldnatts; old_attno++)
108 if (att->attisdropped)
115 atttypid = att->atttypid;
116 atttypmod = att->atttypmod;
117 attcollation = att->attcollation;
123 if (oldrelation == newrelation)
131 pcolnos[old_attno] = old_attno + 1;
144 if (new_attno >= newnatts ||
145 (att =
TupleDescAttr(new_tupdesc, new_attno))->attisdropped ||
152 elog(
ERROR,
"could not find inherited attribute \"%s\" of relation \"%s\"",
155 Assert(new_attno >= 0 && new_attno < newnatts);
162 if (atttypid != att->atttypid || atttypmod != att->atttypmod)
164 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
165 errmsg(
"attribute \"%s\" of relation \"%s\" does not match parent's type",
167 if (attcollation != att->attcollation)
169 (
errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
170 errmsg(
"attribute \"%s\" of relation \"%s\" does not match parent's collation",
179 pcolnos[new_attno] = old_attno + 1;
210 Assert(nappinfos >= 1 && appinfos != NULL);
223 int nappinfos =
context->nappinfos;
258 for (cnt = 0; cnt < nappinfos; cnt++)
262 appinfo = appinfos[cnt];
272 var->varattnosyn = 0;
278 elog(
ERROR,
"attribute %d of relation \"%s\" does not exist",
283 elog(
ERROR,
"attribute %d of relation \"%s\" does not exist",
286 ((
Var *) newnode)->varnullingrels = var->varnullingrels;
287 else if (var->varnullingrels != NULL)
288 elog(
ERROR,
"failed to apply nullingrels to a non-Var");
336 rowexpr->
args = fields;
337 rowexpr->row_typeid = var->vartype;
339 rowexpr->colnames =
copyObject(rte->eref->colnames);
342 if (var->varnullingrels != NULL)
343 elog(
ERROR,
"failed to apply nullingrels to a non-Var");
345 return (
Node *) rowexpr;
360 Relids leaf_result_relids =
context->root->leaf_result_relids;
361 Index leaf_relid = 0;
363 for (cnt = 0; cnt < nappinfos; cnt++)
369 elog(
ERROR,
"cannot translate to multiple leaf relids");
384 var->
varno = leaf_relid;
386 Assert(var->varnullingrels == NULL);
389 var->varattnosyn = 0;
409 for (cnt = 0; cnt < nappinfos; cnt++)
419 return (
Node *) cexpr;
433 nappinfos, appinfos);
462 newinfo->orclause = (
Expr *)
488 newinfo->eval_cost.startup = -1;
489 newinfo->norm_selec = -1;
490 newinfo->outer_selec = -1;
491 newinfo->left_em = NULL;
492 newinfo->right_em = NULL;
493 newinfo->scansel_cache =
NIL;
494 newinfo->left_bucketsize = -1;
495 newinfo->right_bucketsize = -1;
496 newinfo->left_mcvfreq = -1;
497 newinfo->right_mcvfreq = -1;
499 return (
Node *) newinfo;
533 if (childrel->parent != parentrel)
535 if (childrel->parent)
540 elog(
ERROR,
"childrel is not a child of parentrel");
563 for (cnt = 0; cnt < nappinfos; cnt++)
607 if (childrel->parent != parentrel)
609 if (childrel->parent)
614 elog(
ERROR,
"childrel is not a child of parentrel");
647 if (parentattno <= 0 ||
649 elog(
ERROR,
"attribute %d of relation \"%s\" does not exist",
652 if (childvar == NULL || !
IsA(childvar,
Var))
653 elog(
ERROR,
"attribute %d of relation \"%s\" does not exist",
672 elog(
ERROR,
"child rel %d not found in append_rel_array", child_relid);
695 List **processed_tlist,
List **update_colnos)
699 if (relid ==
root->parse->resultRelation)
712 *processed_tlist = (
List *)
721 root->parse->resultRelation);
758 elog(
ERROR,
"child rel %d not found in append_rel_array",
i);
761 appinfos[cnt++] = appinfo;
794 Index rtindex,
const char *rowid_name)
805 Assert(orig_var->varnullingrels == NULL);
812 if (rtindex ==
root->parse->resultRelation)
827 Assert(
root->append_rel_array[rtindex] != NULL);
839 foreach(lc,
root->row_identity_vars)
842 if (strcmp(rowid_name, ridinfo->
rowidname) != 0)
853 elog(
ERROR,
"conflicting uses of row-identity name \"%s\"",
893 char relkind = target_relation->
rd_rel->relkind;
898 if (relkind == RELKIND_RELATION ||
899 relkind == RELKIND_MATVIEW ||
900 relkind == RELKIND_PARTITIONED_TABLE)
914 else if (relkind == RELKIND_FOREIGN_TABLE)
925 target_rte, target_relation);
972 int result_relation =
parse->resultRelation;
987 if (!target_rte->
inh)
1006 if (
root->row_identity_vars ==
NIL)
1012 target_rte, target_relation);
1028 foreach(lc,
root->processed_tlist)
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, RelOptInfo *childrel, RelOptInfo *parentrel)
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, RelOptInfo *childrel, RelOptInfo *parentrel)
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
int bms_next_member(const Bitmapset *a, int prevbit)
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 Assert(condition)
#define OidIsValid(objectId)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
bool equal(const void *a, const void *b)
FdwRoutine * GetFdwRoutineForRelation(Relation relation, bool makecopy)
#define HeapTupleIsValid(tuple)
void build_base_rel_tlists(PlannerInfo *root, List *final_tlist)
if(TABLE==NULL||TABLE_index==NULL)
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)
#define expression_tree_mutator(n, m, c)
#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 *v, int stopper, int type, struct state *init, struct state *final)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
RelOptInfo * find_base_rel_ignore_join(PlannerInfo *root, int relid)
AddForeignUpdateTargets_function AddForeignUpdateTargets
struct PathTarget * reltarget
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)