mirror of
https://github.com/postgres/postgres.git
synced 2025-11-01 21:31:19 +03:00
Faster partition pruning
Add a new module backend/partitioning/partprune.c, implementing a more sophisticated algorithm for partition pruning. The new module uses each partition's "boundinfo" for pruning instead of constraint exclusion, based on an idea proposed by Robert Haas of a "pruning program": a list of steps generated from the query quals which are run iteratively to obtain a list of partitions that must be scanned in order to satisfy those quals. At present, this targets planner-time partition pruning, but there exist further patches to apply partition pruning at execution time as well. This commit also moves some definitions from include/catalog/partition.h to a new file include/partitioning/partbounds.h, in an attempt to rationalize partitioning related code. Authors: Amit Langote, David Rowley, Dilip Kumar Reviewers: Robert Haas, Kyotaro Horiguchi, Ashutosh Bapat, Jesper Pedersen. Discussion: https://postgr.es/m/098b9c71-1915-1a2a-8d52-1a7a50ce79e8@lab.ntt.co.jp
This commit is contained in:
@@ -2150,6 +2150,38 @@ _copyMergeAction(const MergeAction *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyPartitionPruneStepOp
|
||||
*/
|
||||
static PartitionPruneStepOp *
|
||||
_copyPartitionPruneStepOp(const PartitionPruneStepOp *from)
|
||||
{
|
||||
PartitionPruneStepOp *newnode = makeNode(PartitionPruneStepOp);
|
||||
|
||||
COPY_SCALAR_FIELD(step.step_id);
|
||||
COPY_SCALAR_FIELD(opstrategy);
|
||||
COPY_NODE_FIELD(exprs);
|
||||
COPY_NODE_FIELD(cmpfns);
|
||||
COPY_BITMAPSET_FIELD(nullkeys);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyPartitionPruneStepCombine
|
||||
*/
|
||||
static PartitionPruneStepCombine *
|
||||
_copyPartitionPruneStepCombine(const PartitionPruneStepCombine *from)
|
||||
{
|
||||
PartitionPruneStepCombine *newnode = makeNode(PartitionPruneStepCombine);
|
||||
|
||||
COPY_SCALAR_FIELD(step.step_id);
|
||||
COPY_SCALAR_FIELD(combineOp);
|
||||
COPY_NODE_FIELD(source_stepids);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* ****************************************************************
|
||||
* relation.h copy functions
|
||||
*
|
||||
@@ -2277,21 +2309,6 @@ _copyAppendRelInfo(const AppendRelInfo *from)
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyPartitionedChildRelInfo
|
||||
*/
|
||||
static PartitionedChildRelInfo *
|
||||
_copyPartitionedChildRelInfo(const PartitionedChildRelInfo *from)
|
||||
{
|
||||
PartitionedChildRelInfo *newnode = makeNode(PartitionedChildRelInfo);
|
||||
|
||||
COPY_SCALAR_FIELD(parent_relid);
|
||||
COPY_NODE_FIELD(child_rels);
|
||||
COPY_SCALAR_FIELD(part_cols_updated);
|
||||
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* _copyPlaceHolderInfo
|
||||
*/
|
||||
@@ -5076,6 +5093,12 @@ copyObjectImpl(const void *from)
|
||||
case T_MergeAction:
|
||||
retval = _copyMergeAction(from);
|
||||
break;
|
||||
case T_PartitionPruneStepOp:
|
||||
retval = _copyPartitionPruneStepOp(from);
|
||||
break;
|
||||
case T_PartitionPruneStepCombine:
|
||||
retval = _copyPartitionPruneStepCombine(from);
|
||||
break;
|
||||
|
||||
/*
|
||||
* RELATION NODES
|
||||
@@ -5095,9 +5118,6 @@ copyObjectImpl(const void *from)
|
||||
case T_AppendRelInfo:
|
||||
retval = _copyAppendRelInfo(from);
|
||||
break;
|
||||
case T_PartitionedChildRelInfo:
|
||||
retval = _copyPartitionedChildRelInfo(from);
|
||||
break;
|
||||
case T_PlaceHolderInfo:
|
||||
retval = _copyPlaceHolderInfo(from);
|
||||
break;
|
||||
|
||||
@@ -915,16 +915,6 @@ _equalAppendRelInfo(const AppendRelInfo *a, const AppendRelInfo *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalPartitionedChildRelInfo(const PartitionedChildRelInfo *a, const PartitionedChildRelInfo *b)
|
||||
{
|
||||
COMPARE_SCALAR_FIELD(parent_relid);
|
||||
COMPARE_NODE_FIELD(child_rels);
|
||||
COMPARE_SCALAR_FIELD(part_cols_updated);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
_equalPlaceHolderInfo(const PlaceHolderInfo *a, const PlaceHolderInfo *b)
|
||||
{
|
||||
@@ -3230,9 +3220,6 @@ equal(const void *a, const void *b)
|
||||
case T_AppendRelInfo:
|
||||
retval = _equalAppendRelInfo(a, b);
|
||||
break;
|
||||
case T_PartitionedChildRelInfo:
|
||||
retval = _equalPartitionedChildRelInfo(a, b);
|
||||
break;
|
||||
case T_PlaceHolderInfo:
|
||||
retval = _equalPlaceHolderInfo(a, b);
|
||||
break;
|
||||
|
||||
@@ -2156,6 +2156,17 @@ expression_tree_walker(Node *node,
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case T_PartitionPruneStepOp:
|
||||
{
|
||||
PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
|
||||
|
||||
if (walker((Node *) opstep->exprs, context))
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case T_PartitionPruneStepCombine:
|
||||
/* no expression subnodes */
|
||||
break;
|
||||
case T_JoinExpr:
|
||||
{
|
||||
JoinExpr *join = (JoinExpr *) node;
|
||||
@@ -2958,6 +2969,20 @@ expression_tree_mutator(Node *node,
|
||||
return (Node *) newnode;
|
||||
}
|
||||
break;
|
||||
case T_PartitionPruneStepOp:
|
||||
{
|
||||
PartitionPruneStepOp *opstep = (PartitionPruneStepOp *) node;
|
||||
PartitionPruneStepOp *newnode;
|
||||
|
||||
FLATCOPY(newnode, opstep, PartitionPruneStepOp);
|
||||
MUTATE(newnode->exprs, opstep->exprs, List *);
|
||||
|
||||
return (Node *) newnode;
|
||||
}
|
||||
break;
|
||||
case T_PartitionPruneStepCombine:
|
||||
/* no expression sub-nodes */
|
||||
return (Node *) copyObject(node);
|
||||
case T_JoinExpr:
|
||||
{
|
||||
JoinExpr *join = (JoinExpr *) node;
|
||||
|
||||
@@ -1710,6 +1710,28 @@ _outFromExpr(StringInfo str, const FromExpr *node)
|
||||
WRITE_NODE_FIELD(quals);
|
||||
}
|
||||
|
||||
static void
|
||||
_outPartitionPruneStepOp(StringInfo str, const PartitionPruneStepOp *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("PARTITIONPRUNESTEPOP");
|
||||
|
||||
WRITE_INT_FIELD(step.step_id);
|
||||
WRITE_INT_FIELD(opstrategy);
|
||||
WRITE_NODE_FIELD(exprs);
|
||||
WRITE_NODE_FIELD(cmpfns);
|
||||
WRITE_BITMAPSET_FIELD(nullkeys);
|
||||
}
|
||||
|
||||
static void
|
||||
_outPartitionPruneStepCombine(StringInfo str, const PartitionPruneStepCombine *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("PARTITIONPRUNESTEPCOMBINE");
|
||||
|
||||
WRITE_INT_FIELD(step.step_id);
|
||||
WRITE_ENUM_FIELD(combineOp, PartitionPruneCombineOp);
|
||||
WRITE_NODE_FIELD(source_stepids);
|
||||
}
|
||||
|
||||
static void
|
||||
_outOnConflictExpr(StringInfo str, const OnConflictExpr *node)
|
||||
{
|
||||
@@ -2261,7 +2283,6 @@ _outPlannerInfo(StringInfo str, const PlannerInfo *node)
|
||||
WRITE_NODE_FIELD(full_join_clauses);
|
||||
WRITE_NODE_FIELD(join_info_list);
|
||||
WRITE_NODE_FIELD(append_rel_list);
|
||||
WRITE_NODE_FIELD(pcinfo_list);
|
||||
WRITE_NODE_FIELD(rowMarks);
|
||||
WRITE_NODE_FIELD(placeholder_list);
|
||||
WRITE_NODE_FIELD(fkey_list);
|
||||
@@ -2286,6 +2307,7 @@ _outPlannerInfo(StringInfo str, const PlannerInfo *node)
|
||||
WRITE_INT_FIELD(wt_param_id);
|
||||
WRITE_BITMAPSET_FIELD(curOuterRels);
|
||||
WRITE_NODE_FIELD(curOuterParams);
|
||||
WRITE_BOOL_FIELD(partColsUpdated);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2335,6 +2357,7 @@ _outRelOptInfo(StringInfo str, const RelOptInfo *node)
|
||||
WRITE_NODE_FIELD(joininfo);
|
||||
WRITE_BOOL_FIELD(has_eclass_joins);
|
||||
WRITE_BITMAPSET_FIELD(top_parent_relids);
|
||||
WRITE_NODE_FIELD(partitioned_child_rels);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -2559,16 +2582,6 @@ _outAppendRelInfo(StringInfo str, const AppendRelInfo *node)
|
||||
WRITE_OID_FIELD(parent_reloid);
|
||||
}
|
||||
|
||||
static void
|
||||
_outPartitionedChildRelInfo(StringInfo str, const PartitionedChildRelInfo *node)
|
||||
{
|
||||
WRITE_NODE_TYPE("PARTITIONEDCHILDRELINFO");
|
||||
|
||||
WRITE_UINT_FIELD(parent_relid);
|
||||
WRITE_NODE_FIELD(child_rels);
|
||||
WRITE_BOOL_FIELD(part_cols_updated);
|
||||
}
|
||||
|
||||
static void
|
||||
_outPlaceHolderInfo(StringInfo str, const PlaceHolderInfo *node)
|
||||
{
|
||||
@@ -3973,6 +3986,12 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_MergeAction:
|
||||
_outMergeAction(str, obj);
|
||||
break;
|
||||
case T_PartitionPruneStepOp:
|
||||
_outPartitionPruneStepOp(str, obj);
|
||||
break;
|
||||
case T_PartitionPruneStepCombine:
|
||||
_outPartitionPruneStepCombine(str, obj);
|
||||
break;
|
||||
case T_Path:
|
||||
_outPath(str, obj);
|
||||
break;
|
||||
@@ -4114,9 +4133,6 @@ outNode(StringInfo str, const void *obj)
|
||||
case T_AppendRelInfo:
|
||||
_outAppendRelInfo(str, obj);
|
||||
break;
|
||||
case T_PartitionedChildRelInfo:
|
||||
_outPartitionedChildRelInfo(str, obj);
|
||||
break;
|
||||
case T_PlaceHolderInfo:
|
||||
_outPlaceHolderInfo(str, obj);
|
||||
break;
|
||||
|
||||
@@ -1331,6 +1331,32 @@ _readOnConflictExpr(void)
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
static PartitionPruneStepOp *
|
||||
_readPartitionPruneStepOp(void)
|
||||
{
|
||||
READ_LOCALS(PartitionPruneStepOp);
|
||||
|
||||
READ_INT_FIELD(step.step_id);
|
||||
READ_INT_FIELD(opstrategy);
|
||||
READ_NODE_FIELD(exprs);
|
||||
READ_NODE_FIELD(cmpfns);
|
||||
READ_BITMAPSET_FIELD(nullkeys);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
static PartitionPruneStepCombine *
|
||||
_readPartitionPruneStepCombine(void)
|
||||
{
|
||||
READ_LOCALS(PartitionPruneStepCombine);
|
||||
|
||||
READ_INT_FIELD(step.step_id);
|
||||
READ_ENUM_FIELD(combineOp, PartitionPruneCombineOp);
|
||||
READ_NODE_FIELD(source_stepids);
|
||||
|
||||
READ_DONE();
|
||||
}
|
||||
|
||||
/*
|
||||
* _readMergeAction
|
||||
*/
|
||||
@@ -2615,6 +2641,10 @@ parseNodeString(void)
|
||||
return_value = _readOnConflictExpr();
|
||||
else if (MATCH("MERGEACTION", 11))
|
||||
return_value = _readMergeAction();
|
||||
else if (MATCH("PARTITIONPRUNESTEPOP", 20))
|
||||
return_value = _readPartitionPruneStepOp();
|
||||
else if (MATCH("PARTITIONPRUNESTEPCOMBINE", 25))
|
||||
return_value = _readPartitionPruneStepCombine();
|
||||
else if (MATCH("RTE", 3))
|
||||
return_value = _readRangeTblEntry();
|
||||
else if (MATCH("RANGETBLFUNCTION", 16))
|
||||
|
||||
Reference in New Issue
Block a user