Add the feature of size estimation for hash partitioning

This commit is contained in:
yuzupy 2018-04-20 06:13:47 +00:00 committed by Julien Rouhaud
parent 5c8f53deaa
commit 5efd7bff2c

View file

@ -748,6 +748,9 @@ hypo_generate_partkey(CreateStmt *stmt, Oid parentid, hypoTable *entry)
partattrs, &partexprs, partopclass,
partcollation, strategy);
key->strategy = strategy;
key->partexprs = partexprs;
/*--- Adapted from RelationBuildPartitionKey ---*/
{
ListCell *partexprs_item;
@ -850,8 +853,6 @@ hypo_generate_partkey(CreateStmt *stmt, Oid parentid, hypoTable *entry)
heap_close(rel, AccessShareLock);
key->strategy = strategy;
key->partexprs = partexprs;
/*--------
* Copied in previous loop
key->partattrs = partattrs;
@ -1372,9 +1373,11 @@ hypo_table_pfree(hypoTable *entry)
{
pfree(entry->part_scheme->partopfamily);
pfree(entry->part_scheme->partopcintype);
//pfree(entry->part_scheme->parttypcoll);
pfree(entry->part_scheme->partcollation);
//pfree(entry->part_scheme->parttypcoll);
pfree(entry->part_scheme->parttyplen);
pfree(entry->part_scheme->parttypbyval);
pfree(entry->part_scheme->partsupfunc);
pfree(entry->part_scheme);
}
@ -1393,7 +1396,6 @@ hypo_table_pfree(hypoTable *entry)
pfree(entry->partkey->parttypbyval);
pfree(entry->partkey->parttypalign);
pfree(entry->partkey->parttypcoll);
pfree(entry->partkey->partcollation);
pfree(entry->partkey);
}
@ -1750,29 +1752,30 @@ hypo_injectHypotheticalPartitioning(PlannerInfo *root,
RelOptInfo *rel)
{
hypoTable *parent;
List *inhoids;
int nparts;
Assert(HYPO_ENABLED());
Assert(hypo_table_oid_is_hypothetical(relationObjectId));
parent = hypo_find_table(relationObjectId);
/* get all of the partition oids */
inhoids = hypo_find_inheritance_children(parent);
nparts = list_length(inhoids);
/*
* if this rel is parent, prepare some structures to inject
* hypothetical partitioning
*/
if(!HYPO_RTI_IS_TAGGED(rel->relid,root))
{
List *inhoids;
int nparts, i;
int i;
int oldsize = root->simple_rel_array_size;
RangeTblEntry *rte;
ListCell *cell;
AppendRelInfo *appinfo;
/* get all of the partition oids */
inhoids = hypo_find_inheritance_children(parent);
nparts = list_length(inhoids);
/* resize and clean rte and rel arrays */
root->simple_rel_array_size = oldsize + nparts + 1;
root->simple_rel_array = (RelOptInfo **)
@ -1857,29 +1860,39 @@ hypo_injectHypotheticalPartitioning(PlannerInfo *root,
}
/*
* If this rel is partition, we add the partition constraints to the
* rte->securityQuals so that the rel->rows is computed correctly at
* If this rel is partitioned by hash, we should rewrite the rel->pages
* and the rel->pages here according to the number of partitions.
*
* If this rel is partitioned list or range, we add the partition constraints
* to the rte->securityQuals so that the rel->rows is computed correctly at
* the set_baserel_size_estimates(). We shouldn't rewrite the rel->pages
* and the rel->tuples here, because they will be rewritten at the later hook.
*
* TODO: should comfirm that the tuples will not referred till the
* set_baserel_size_esimates() and think about rel->reltarget->width
*
*/
if (rel->reloptkind != RELOPT_BASEREL
&&HYPO_RTI_IS_TAGGED(rel->relid,root))
{
List *constraints;
if (parent->part_scheme->strategy == PARTITION_STRATEGY_HASH)
{
double pages;
/* get its partition constraints */
constraints = hypo_get_partition_constraints(root, rel, parent);
pages = ceil(rel->pages / nparts);
rel->pages = (BlockNumber)pages;
rel->tuples = clamp_row_est(rel->tuples / nparts);
}
else
{
List *constraints;
/*
* to compute rel->rows at set_baserel_size_estimates using parent's
* statistics, parent's tuples and baserestrictinfo, we add the partition
* constraints to its rte->securityQuals
*/
planner_rt_fetch(rel->relid, root)->securityQuals = list_make1(constraints);
/* get its partition constraints */
constraints = hypo_get_partition_constraints(root, rel, parent);
/*
* to compute rel->rows at set_baserel_size_estimates using parent's
* statistics, parent's tuples and baserestrictinfo, we add the partition
* constraints to its rte->securityQuals
*/
planner_rt_fetch(rel->relid, root)->securityQuals = list_make1(constraints);
}
}
}
@ -1904,6 +1917,10 @@ void hypo_setPartitionPathlist(PlannerInfo *root, RelOptInfo *rel,
Selectivity selectivity;
double pages;
/* If this rel is partitioned by hash, nothing to do */
if (parent->part_scheme->strategy == PARTITION_STRATEGY_HASH)
return;
/*
* get the parent's rel and copy its rel->baserestrictinfo to
* the own rel->baserestrictinfo.