Hide rte->values_lists usage with (ugly) macros

This commit is contained in:
Julien Rouhaud 2018-11-17 20:22:00 +01:00
parent 171c51bba9
commit b2f8fc6c48
4 changed files with 31 additions and 25 deletions

View file

@ -581,11 +581,11 @@ hypo_get_relation_info_hook(PlannerInfo *root,
* check for hypothetical index on hypothetical leaf partition
*/
else if (hypo_table_oid_is_hypothetical(relationObjectId) &&
rte->values_lists &&
entry->relid == linitial_oid(rte->values_lists)
HYPO_TABLE_RTE_HAS_HYPOOID(rte) &&
entry->relid == HYPO_TABLE_RTE_GET_HYPOOID(rte)
)
{
oid = linitial_oid(rte->values_lists);
oid = HYPO_TABLE_RTE_GET_HYPOOID(rte);
}
#endif
/*
@ -628,7 +628,7 @@ hypo_get_relation_stats_hook(PlannerInfo *root,
* performed yet, because postgres will search for an entry with stainherit
* = true, which won't exist.
*/
if (rte->security_barrier && (rte->values_lists == NIL))
if (HYPO_RTE_IS_TAGGED(rte) && (!HYPO_TABLE_RTE_HAS_HYPOOID(rte)))
{
vardata->statsTuple = SearchSysCache3(STATRELATTINH,
ObjectIdGetDatum(rte->relid),
@ -659,11 +659,11 @@ hypo_get_relation_stats_hook(PlannerInfo *root,
return false;
/* Nothing to do if it's not a hypothetical partition */
if (!rte->values_lists)
if (!HYPO_TABLE_RTE_HAS_HYPOOID(rte))
return false;
/* At this point, we have a hypothetical partition. Get its oid */
poid = linitial_oid(rte->values_lists);
poid = HYPO_TABLE_RTE_GET_HYPOOID(rte);
if (poid == InvalidOid)
/* This should not happen */
return false;

View file

@ -130,13 +130,14 @@ hypo_clauselist_selectivity(PlannerInfo *root, RelOptInfo *rel, List *clauses,
if (clauses == NIL)
{
hypoTable *part = hypo_find_table(parent_oid, false);
RangeTblEntry *save_rte = planner_rt_fetch(save_relid, root);
Assert(root != NULL);
Assert(part->partkey);
/* add the hypothetical partition oid to be able to get the
* constraints */
rte->values_lists = (planner_rt_fetch(save_relid, root))->values_lists;
HYPO_TABLE_RTE_COPY_HYPOOID_FROM_RTE(rte, save_rte);
root_dummy->parse->rtable = list_make1(rte);
/* get the partition constraints, setup for a rel with relid 1 */
@ -146,21 +147,22 @@ hypo_clauselist_selectivity(PlannerInfo *root, RelOptInfo *rel, List *clauses,
* and remove the hypothetical oid to avoid computing selectivity with
* hypothetical statistics
*/
rte->values_lists = NIL;
HYPO_TABLE_RTE_CLEAR_HYPOOID(rte);
root_dummy->parse->rtable = list_make1(rte);
}
else
{ /* We estimates selectivity for hypothetical indexes */
RangeTblEntry *rt = NULL;
RangeTblEntry *dummyrte = planner_rt_fetch(1, root_dummy);
if (root)
rt = planner_rt_fetch(save_relid, root);
/* modify RangeTableEntry to be able to get correct oid */
if (rt && rt->values_lists) /* Is this a hypothetical partition? */
planner_rt_fetch(1, root_dummy)->values_lists = rt->values_lists;
if (HYPO_TABLE_RTE_HAS_HYPOOID(rt)) /* Is this a hypothetical partition? */
HYPO_TABLE_RTE_COPY_HYPOOID_FROM_RTE(dummyrte, rt);
else if (rt)
planner_rt_fetch(1, root_dummy)->relid = rt->relid;
dummyrte->relid = rt->relid;
else
{
Assert(save_relid == 1);

View file

@ -123,9 +123,6 @@ static List *hypo_get_qual_for_range(hypoTable *parent, PartitionBoundSpec *spec
static void hypo_check_new_partition_bound(char *relname, hypoTable *parent,
PartitionBoundSpec *spec);
#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)
/* Setup the hypoTables hash */
static void hypo_initTablesHash()
@ -322,11 +319,10 @@ hypo_expand_single_inheritance_child(PlannerInfo *root, Oid relationObjectId,
childrte->alias = makeNode(Alias);
childrte->alias->aliasname = child->tablename;
/* XXX maybe use a mapping array here instead of rte->values_lists*/
if (expandBranch)
childrte->values_lists = list_make1_oid(branch->oid); //partitionOID
HYPO_TABLE_RTE_SET_HYPOOID(childrte, branch->oid); // partitionOID
else
childrte->values_lists = list_make1_oid(child->oid); //partitionOID
HYPO_TABLE_RTE_SET_HYPOOID(childrte, child->oid); // partitionOID
root->simple_rte_array[newrelid] = childrte;
HYPO_TAG_RTI(newrelid, root);
@ -2145,8 +2141,8 @@ hypo_injectHypotheticalPartitioning(PlannerInfo *root,
double pages;
int total_modulus = 1;
Assert(rte->values_lists);
partoid = linitial_oid(rte->values_lists);
Assert(HYPO_TABLE_RTE_HAS_HYPOOID(rte));
partoid = HYPO_TABLE_RTE_GET_HYPOOID(rte);
part = hypo_find_table(partoid, false);
#if PG_VERSION_NUM >= 110000
/*
@ -2209,8 +2205,7 @@ hypo_injectHypotheticalPartitioning(PlannerInfo *root,
part->rootid, part->parentid);
elog(DEBUG1, "hypopg: selectivity for partition \"%s\": %lf",
hypo_find_table(linitial_oid(planner_rt_fetch(rel->relid,
root)->values_lists), false)->tablename,
hypo_find_table(HYPO_TABLE_RTE_GET_HYPOOID(rte), false)->tablename,
selectivity);
/* compute pages and tuples using selectivity and total_modulus */
@ -2285,14 +2280,11 @@ hypo_set_relation_partition_info(PlannerInfo *root, RelOptInfo *rel,
List *
hypo_get_partition_constraints(PlannerInfo *root, RelOptInfo *rel, hypoTable *parent)
{
ListCell *lc;
Oid childOid;
hypoTable *child;
List *constraints;
/* XXX maybe use a mapping array here instead of rte->values_lists*/
lc = list_head(planner_rt_fetch(rel->relid, root)->values_lists);
childOid = lfirst_oid(lc);
childOid = HYPO_TABLE_RTI_GET_HYPOOID(rel->relid, root);
child = hypo_find_table(childOid, false);
Assert(child->parentid == parent->oid);

View file

@ -21,6 +21,18 @@
#define HYPO_TABLE_NB_COLS 6 /* # of column hypopg_table() returns */
#define HYPO_ADD_PART_COLS 2 /* # of column hypopg_add_partition() returns */
#define HYPO_RTE_IS_TAGGED(rte) (rte && (rte->security_barrier))
#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
#include "optimizer/paths.h"
/*--- Structs --- */