From 19af48499e12eceddbdc32f04c78a8fe290ed71f Mon Sep 17 00:00:00 2001 From: Julien Rouhaud Date: Thu, 11 Apr 2019 11:15:53 +0200 Subject: [PATCH] Use ctelevelsup in lieu of values_lists for saving hypo table oid. An upcoming patch to fix runtime partition pruning issue will need a field that will survive planning time. --- hypopg.c | 1 + hypopg_analyze.c | 7 +++++++ hypopg_table.c | 5 ++++- include/hypopg_table.h | 14 +++++++------- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/hypopg.c b/hypopg.c index ce0b869..072ad1d 100644 --- a/hypopg.c +++ b/hypopg.c @@ -605,6 +605,7 @@ hypo_get_relation_info_hook(PlannerInfo *root, entry->relid == HYPO_TABLE_RTE_GET_HYPOOID(rte) ) { + Assert(rte->rtekind != RTE_CTE); oid = HYPO_TABLE_RTE_GET_HYPOOID(rte); } #endif diff --git a/hypopg_analyze.c b/hypopg_analyze.c index 6aef403..be49ca4 100644 --- a/hypopg_analyze.c +++ b/hypopg_analyze.c @@ -142,6 +142,8 @@ hypo_clauselist_selectivity(PlannerInfo *root, RelOptInfo *rel, List *clauses, /* add the hypothetical partition oid to be able to get the * constraints */ + Assert(save_rte->rtekind != RTE_CTE); + Assert(rte->rtekind != RTE_CTE); HYPO_TABLE_RTE_COPY_HYPOOID_FROM_RTE(rte, save_rte); root_dummy->parse->rtable = list_make1(rte); @@ -152,6 +154,7 @@ hypo_clauselist_selectivity(PlannerInfo *root, RelOptInfo *rel, List *clauses, * and remove the hypothetical oid to avoid computing selectivity with * hypothetical statistics */ + Assert(rte->rtekind != RTE_CTE); HYPO_TABLE_RTE_CLEAR_HYPOOID(rte); root_dummy->parse->rtable = list_make1(rte); } @@ -165,7 +168,11 @@ hypo_clauselist_selectivity(PlannerInfo *root, RelOptInfo *rel, List *clauses, /* modify RangeTableEntry to be able to get correct oid */ if (HYPO_TABLE_RTE_HAS_HYPOOID(rt)) /* Is this a hypothetical partition? */ + { + Assert(dummyrte->rtekind != RTE_CTE); + Assert(rt->rtekind != RTE_CTE); HYPO_TABLE_RTE_COPY_HYPOOID_FROM_RTE(dummyrte, rt); + } else if (rt) dummyrte->relid = rt->relid; else diff --git a/hypopg_table.c b/hypopg_table.c index b3d3180..0df1ac7 100644 --- a/hypopg_table.c +++ b/hypopg_table.c @@ -369,6 +369,7 @@ hypo_expand_single_inheritance_child(PlannerInfo *root, Oid relationObjectId, childrte->alias = makeNode(Alias); childrte->alias->aliasname = child->tablename; + Assert(rte->rtekind != RTE_CTE); if (expandBranch) HYPO_TABLE_RTE_SET_HYPOOID(childrte, branch->oid); //partitionOID @@ -2497,7 +2498,7 @@ hypo_injectHypotheticalPartitioning(PlannerInfo *root, double pages; int total_modulus = 1; - Assert(HYPO_TABLE_RTE_HAS_HYPOOID(rte)); + Assert(rte->rtekind != RTE_CTE && HYPO_TABLE_RTE_HAS_HYPOOID(rte)); partoid = HYPO_TABLE_RTE_GET_HYPOOID(rte); part = hypo_find_table(partoid, false); #if PG_VERSION_NUM >= 110000 @@ -2610,6 +2611,7 @@ hypo_markDummyIfExcluded(PlannerInfo *root, RelOptInfo *rel, hypoTable *parent = hypo_find_table(part->parentid, false); Assert(hypo_table_oid_is_hypothetical(rte->relid)); + Assert(rte->rtekind != RTE_CTE); Assert(rte->relkind == 'r'); /* get its partition constraints */ @@ -2703,6 +2705,7 @@ hypo_get_partition_constraints(PlannerInfo *root, RelOptInfo *rel, hypoTable *child; List *pcqual; + Assert((planner_rt_fetch(rel->relid, root))->rtekind != RTE_CTE); childOid = HYPO_TABLE_RTI_GET_HYPOOID(rel->relid, root); child = hypo_find_table(childOid, false); diff --git a/include/hypopg_table.h b/include/hypopg_table.h index ffcdbe2..4aa6683 100644 --- a/include/hypopg_table.h +++ b/include/hypopg_table.h @@ -25,13 +25,13 @@ #define HYPO_RTI_IS_TAGGED(rti, root) (planner_rt_fetch(rti, root)->security_barrier) #define HYPO_TAG_RTI(rti, root) (planner_rt_fetch(rti, root)->security_barrier = true) -/* XXX maybe use a mapping array here instead of rte->values_lists*/ -#define HYPO_TABLE_RTE_HAS_HYPOOID(rte) (rte && (rte->values_lists != NIL)) -#define HYPO_TABLE_RTE_GET_HYPOOID(rte) linitial_oid(rte->values_lists) -#define HYPO_TABLE_RTI_GET_HYPOOID(rti, root) linitial_oid(planner_rt_fetch(rti, root)->values_lists) -#define HYPO_TABLE_RTE_SET_HYPOOID(rte, oid) rte->values_lists = list_make1_oid(oid) -#define HYPO_TABLE_RTE_CLEAR_HYPOOID(rte) rte->values_lists = NIL -#define HYPO_TABLE_RTE_COPY_HYPOOID_FROM_RTE(target, src) target->values_lists = src->values_lists +/* XXX maybe use a mapping array here instead of rte->ctelevelsup*/ +#define HYPO_TABLE_RTE_HAS_HYPOOID(rte) (rte && (rte->ctelevelsup != InvalidOid)) +#define HYPO_TABLE_RTE_GET_HYPOOID(rte) (rte->ctelevelsup) +#define HYPO_TABLE_RTI_GET_HYPOOID(rti, root) (planner_rt_fetch(rti, root)->ctelevelsup) +#define HYPO_TABLE_RTE_SET_HYPOOID(rte, oid) (rte->ctelevelsup = oid) +#define HYPO_TABLE_RTE_CLEAR_HYPOOID(rte) rte->ctelevelsup = InvalidOid +#define HYPO_TABLE_RTE_COPY_HYPOOID_FROM_RTE(target, src) target->ctelevelsup = src->ctelevelsup #include "optimizer/paths.h"