From abdaaca3ce8ec87809440e0650cbdaf25b4bbc99 Mon Sep 17 00:00:00 2001 From: amit Date: Fri, 26 Oct 2018 16:45:59 +0900 Subject: [PATCH v14 3/6] Store inheritance root parent index in otherrel's RelOptInfo Although it's set by build_simple_rel, it's not being used by any code yet. --- src/backend/nodes/outfuncs.c | 1 + src/backend/optimizer/util/relnode.c | 15 +++++++++++++-- src/include/nodes/relation.h | 9 +++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 158da68925..67697b8884 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -2272,6 +2272,7 @@ _outRelOptInfo(StringInfo str, const RelOptInfo *node) WRITE_BOOL_FIELD(consider_partitionwise_join); WRITE_BITMAPSET_FIELD(top_parent_relids); WRITE_NODE_FIELD(partitioned_child_rels); + WRITE_UINT_FIELD(inh_root_parent); } static void diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index fe83ec4519..45f9950935 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -195,6 +195,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent) rel->joininfo = NIL; rel->has_eclass_joins = false; rel->consider_partitionwise_join = false; /* might get changed later */ + rel->top_parent_relids = NULL; /* might be changed later */ rel->part_scheme = NULL; rel->nparts = 0; rel->boundinfo = NULL; @@ -203,6 +204,7 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent) rel->partexprs = NULL; rel->nullable_partexprs = NULL; rel->partitioned_child_rels = NIL; + rel->inh_root_parent = 0; /* might be changed later */ /* * Pass top parent's relids down the inheritance hierarchy. If the parent @@ -216,9 +218,18 @@ build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent) rel->top_parent_relids = parent->top_parent_relids; else rel->top_parent_relids = bms_copy(parent->relids); + + /* + * For inheritance child relations, we also set inh_root_parent. + * Note that 'parent' might itself be a child (a sub-partitioned + * partition), in which case we simply use its value of + * inh_root_parent. + */ + if (parent->rtekind == RTE_RELATION) + rel->inh_root_parent = parent->inh_root_parent > 0 ? + parent->inh_root_parent : + parent->relid; } - else - rel->top_parent_relids = NULL; /* Check type of rtable entry */ switch (rte->rtekind) diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index beb2e323a8..db439bd904 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -734,6 +734,15 @@ typedef struct RelOptInfo List **partexprs; /* Non-nullable partition key expressions. */ List **nullable_partexprs; /* Nullable partition key expressions. */ List *partitioned_child_rels; /* List of RT indexes. */ + + /* + * For inheritance children, this is the RT index of inheritance table + * mentioned in the query from which this relation originated. + * top_parent_relids cannot be used for this, because if the inheritance + * root table is itself under UNION ALL, top_parent_relids contains the + * RT index of UNION ALL parent subquery. + */ + Index inh_root_parent; } RelOptInfo; /* -- 2.11.0