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.
This commit is contained in:
Julien Rouhaud 2019-04-11 11:15:53 +02:00
parent b5e50e6429
commit 19af48499e
4 changed files with 19 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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);

View file

@ -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"