From 0f66b82a6ab998c4d790a4e2a6437950edf7de18 Mon Sep 17 00:00:00 2001 From: amit Date: Fri, 26 Oct 2018 16:45:59 +0900 Subject: [PATCH v5 1/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 | 14 ++++++++++++++ src/include/nodes/relation.h | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c index 69731ccdea..53a657c0ae 100644 --- a/src/backend/nodes/outfuncs.c +++ b/src/backend/nodes/outfuncs.c @@ -2371,6 +2371,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 39f5729b91..29ba19349f 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -215,9 +215,23 @@ 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; + rel->inh_root_parent = 0; + } /* Check type of rtable entry */ switch (rte->rtekind) diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index 6fd24203dd..32ac3315a4 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -703,6 +703,10 @@ 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. */ + + Index inh_root_parent; /* For otherrels, this is the RT index of + * inheritance table mentioned in the query + * from which this relation originated */ } RelOptInfo; /* -- 2.11.0