50 Index *childRTindex_p);
52 List *translated_vars);
93 bool old_isParent =
false;
94 int old_allMarkTypes = 0;
106 parentOID = rte->
relid;
122 lockmode = rte->rellockmode;
139 if (oldrelation->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
148 Assert(rte->relkind == RELKIND_PARTITIONED_TABLE);
198 if (childOID != parentOID)
201 newrelation = oldrelation;
218 &childrte, &childRTindex);
224 if (childOID != parentOID)
265 newvars =
lappend(newvars, var);
282 newvars =
lappend(newvars, var);
300 newvars =
lappend(newvars, var);
345 if (!
root->partColsUpdated)
346 root->partColsUpdated =
350 if (partdesc->
nparts == 0)
363 if (num_live_parts > 0)
371 Assert(relinfo->part_rels == NULL);
395 if (childrel == NULL)
407 elog(
ERROR,
"temporary relation from another session found as partition");
411 parentrel, top_parentrc, childrel,
412 &childrte, &childRTindex);
416 relinfo->part_rels[
i] = childrelinfo;
421 if (childrel->
rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
430 childrte, childRTindex,
433 top_parentrc, lockmode);
466 Index *childRTindex_p)
476 List *parent_colnames;
477 List *child_colnames;
495 childrte->
relid = childOID;
496 childrte->relkind = childrel->
rd_rel->relkind;
498 if (childrte->relkind == RELKIND_PARTITIONED_TABLE)
500 Assert(childOID != parentOID);
501 childrte->
inh =
true;
504 childrte->
inh =
false;
505 childrte->securityQuals =
NIL;
508 childrte->perminfoindex = 0;
513 *childrte_p = childrte;
514 *childRTindex_p = childRTindex;
520 parentRTindex, childRTindex);
535 parent_colnames = parentrte->eref->colnames;
536 child_colnames =
NIL;
537 for (
int cattno = 0; cattno < child_tupdesc->
natts; cattno++)
542 if (att->attisdropped)
547 else if (appinfo->parent_colnos[cattno] > 0 &&
548 appinfo->parent_colnos[cattno] <=
list_length(parent_colnames))
552 appinfo->parent_colnos[cattno] - 1));
567 childrte->alias = childrte->eref =
makeAlias(parentrte->eref->aliasname,
574 Assert(childRTindex < root->simple_rel_array_size);
575 Assert(
root->simple_rte_array[childRTindex] == NULL);
576 root->simple_rte_array[childRTindex] = childrte;
577 Assert(
root->append_rel_array[childRTindex] == NULL);
578 root->append_rel_array[childRTindex] = appinfo;
587 childrc->
rti = childRTindex;
588 childrc->
prti = top_parentrc->
rti;
602 childrc->
isParent = (childrte->relkind == RELKIND_PARTITIONED_TABLE);
623 if (childrte->relkind != RELKIND_PARTITIONED_TABLE)
673 relid =
root->parse->resultRelation;
679 if (rel->
relid != relid)
696 return bms_union(updatedCols, extraUpdatedCols);
712 List *translated_vars)
734 foreach(lc, translated_vars)
768 if (parent_cols == NULL)
772 if (rel->parent != parent_rel)
784 appinfo =
root->append_rel_array[rel->
relid];
805 foreach(l,
root->append_rel_list)
817 Assert(childRTindex < root->simple_rel_array_size);
818 childrte =
root->simple_rte_array[childRTindex];
848 Index cq_min_security;
860 cq_min_security = UINT_MAX;
873 if (childqual &&
IsA(childqual,
Const))
875 if (((
Const *) childqual)->constisnull ||
898 root->hasPseudoConstantQuals =
true;
917 childquals =
lappend(childquals, childrinfo);
934 if (childRTE->securityQuals)
936 Index security_level = 0;
938 foreach(lc, childRTE->securityQuals)
943 foreach(lc2, qualset)
948 childquals =
lappend(childquals,
955 cq_min_security =
Min(cq_min_security, security_level);
959 Assert(security_level <= root->qual_security_level);
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)
AppendRelInfo * make_append_rel_info(Relation parentrel, Relation childrel, Index parentRTindex, Index childRTindex)
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_union(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
Node * eval_const_expressions(PlannerInfo *root, Node *node)
bool contain_volatile_functions(Node *clause)
static Bitmapset * translate_col_privs(const Bitmapset *parent_privs, List *translated_vars)
Bitmapset * get_rel_all_updated_cols(PlannerInfo *root, RelOptInfo *rel)
static void expand_partitioned_rtentry(PlannerInfo *root, RelOptInfo *relinfo, RangeTblEntry *parentrte, Index parentRTindex, Relation parentrel, Bitmapset *parent_updatedCols, PlanRowMark *top_parentrc, LOCKMODE lockmode)
bool apply_child_basequals(PlannerInfo *root, RelOptInfo *parentrel, RelOptInfo *childrel, RangeTblEntry *childRTE, AppendRelInfo *appinfo)
static void expand_appendrel_subquery(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, Index rti)
static Bitmapset * translate_col_privs_multilevel(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *parent_rel, Bitmapset *parent_cols)
static void expand_single_inheritance_child(PlannerInfo *root, RangeTblEntry *parentrte, Index parentRTindex, Relation parentrel, PlanRowMark *top_parentrc, Relation childrel, RangeTblEntry **childrte_p, Index *childRTindex_p)
void expand_inherited_rtentry(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte, Index rti)
bool restriction_is_always_true(PlannerInfo *root, RestrictInfo *restrictinfo)
void add_vars_to_targetlist(PlannerInfo *root, List *vars, Relids where_needed)
bool restriction_is_always_false(PlannerInfo *root, RestrictInfo *restrictinfo)
List * lappend(List *list, void *datum)
Alias * makeAlias(const char *aliasname, List *colnames)
Var * makeWholeRowVar(RangeTblEntry *rte, int varno, Index varlevelsup, bool allowScalar)
List * make_ands_implicit(Expr *clause)
TargetEntry * makeTargetEntry(Expr *expr, AttrNumber resno, char *resname, bool resjunk)
Var * makeVar(int varno, AttrNumber varattno, Oid vartype, int32 vartypmod, Oid varcollid, Index varlevelsup)
char * pstrdup(const char *in)
void * palloc0(Size size)
#define IsA(nodeptr, _type_)
RTEPermissionInfo * getRTEPermissionInfo(List *rteperminfos, RangeTblEntry *rte)
PartitionDesc PartitionDirectoryLookup(PartitionDirectory pdir, Relation rel)
bool has_partition_attrs(Relation rel, Bitmapset *attnums, bool *used_in_expr)
Bitmapset * prune_append_rel_partitions(RelOptInfo *rel)
#define IS_SIMPLE_REL(rel)
#define planner_rt_fetch(rti, root)
#define IS_OTHER_REL(rel)
FormData_pg_attribute * Form_pg_attribute
List * find_all_inheritors(Oid parentrelId, LOCKMODE lockmode, List **numparents)
#define lfirst_node(type, lc)
static int list_length(const List *l)
static void * list_nth(const List *list, int n)
Bitmapset * get_dependent_generated_columns(PlannerInfo *root, Index rti, Bitmapset *target_cols)
RowMarkType select_rowmark_type(RangeTblEntry *rte, LockClauseStrength strength)
void check_stack_depth(void)
static bool DatumGetBool(Datum X)
PlanRowMark * get_plan_rowmark(List *rowmarks, Index rtindex)
static struct subre * parse(struct vars *v, int stopper, int type, struct state *init, struct state *final)
#define RelationGetRelid(relation)
#define RelationGetDescr(relation)
#define RELATION_IS_OTHER_TEMP(relation)
RelOptInfo * find_base_rel(PlannerInfo *root, int relid)
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
void expand_planner_arrays(PlannerInfo *root, int add_size)
RestrictInfo * make_restrictinfo(PlannerInfo *root, Expr *clause, bool is_pushed_down, bool has_clone, bool is_clone, bool pseudoconstant, Index security_level, Relids required_relids, Relids incompatible_relids, Relids outer_relids)
LockClauseStrength strength
LockWaitPolicy waitPolicy
struct TableSampleClause * tablesample
Index baserestrict_min_security
#define FirstLowInvalidHeapAttributeNumber
#define TableOidAttributeNumber
#define SelfItemPointerAttributeNumber
Relation try_table_open(Oid relationId, LOCKMODE lockmode)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
#define TupleDescAttr(tupdesc, i)
String * makeString(char *str)
bool contain_vars_of_level(Node *node, int levelsup)