mirror of
https://github.com/postgres/postgres.git
synced 2025-08-19 23:22:23 +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:
@@ -18,6 +18,7 @@
|
||||
#define PRIMNODES_H
|
||||
|
||||
#include "access/attnum.h"
|
||||
#include "access/stratnum.h"
|
||||
#include "nodes/bitmapset.h"
|
||||
#include "nodes/pg_list.h"
|
||||
|
||||
@@ -1506,4 +1507,78 @@ typedef struct OnConflictExpr
|
||||
List *exclRelTlist; /* tlist of the EXCLUDED pseudo relation */
|
||||
} OnConflictExpr;
|
||||
|
||||
|
||||
/*
|
||||
* Node types to represent a partition pruning step.
|
||||
*/
|
||||
|
||||
/*
|
||||
* The base Node type. step_id is the global identifier of a given step
|
||||
* within a given pruning context.
|
||||
*/
|
||||
typedef struct PartitionPruneStep
|
||||
{
|
||||
NodeTag type;
|
||||
int step_id;
|
||||
} PartitionPruneStep;
|
||||
|
||||
/*----------
|
||||
* PartitionPruneStepOp - Information to prune using a set of mutually AND'd
|
||||
* OpExpr clauses
|
||||
*
|
||||
* This contains information extracted from up to partnatts OpExpr clauses,
|
||||
* where partnatts is the number of partition key columns. 'opstrategy' is the
|
||||
* strategy of the operator in the clause matched to the last partition key.
|
||||
* 'exprs' contains expressions which comprise the lookup key to be passed to
|
||||
* the partition bound search function. 'cmpfns' contains the OIDs of
|
||||
* comparison function used to compare aforementioned expressions with
|
||||
* partition bounds. Both 'exprs' and 'cmpfns' contain the same number of
|
||||
* items up to partnatts items.
|
||||
*
|
||||
* Once we find the offset of a partition bound using the lookup key, we
|
||||
* determine which partitions to include in the result based on the value of
|
||||
* 'opstrategy'. For example, if it were equality, we'd return just the
|
||||
* partition that would contain that key or a set of partitions if the key
|
||||
* didn't consist of all partitioning columns. For non-equality strategies,
|
||||
* we'd need to include other partitions as appropriate.
|
||||
*
|
||||
* 'nullkeys' is the set containing the offset of the partition keys (0 to
|
||||
* partnatts - 1) that were matched to an IS NULL clause. This is only
|
||||
* considered for hash partitioning as we need to pass which keys are null
|
||||
* to the hash partition bound search function. It is never possible to
|
||||
* have an expression be present in 'exprs' for a given partition key and
|
||||
* the corresponding bit set in 'nullkeys'.
|
||||
*----------
|
||||
*/
|
||||
typedef struct PartitionPruneStepOp
|
||||
{
|
||||
PartitionPruneStep step;
|
||||
|
||||
StrategyNumber opstrategy;
|
||||
List *exprs;
|
||||
List *cmpfns;
|
||||
Bitmapset *nullkeys;
|
||||
} PartitionPruneStepOp;
|
||||
|
||||
/*----------
|
||||
* PartitionPruneStepCombine - Information to prune using a BoolExpr clause
|
||||
*
|
||||
* For BoolExpr clauses, we combine the set of partitions determined for each
|
||||
* of its argument clauses.
|
||||
*----------
|
||||
*/
|
||||
typedef enum PartitionPruneCombineOp
|
||||
{
|
||||
PARTPRUNE_COMBINE_UNION,
|
||||
PARTPRUNE_COMBINE_INTERSECT
|
||||
} PartitionPruneCombineOp;
|
||||
|
||||
typedef struct PartitionPruneStepCombine
|
||||
{
|
||||
PartitionPruneStep step;
|
||||
|
||||
PartitionPruneCombineOp combineOp;
|
||||
List *source_stepids;
|
||||
} PartitionPruneStepCombine;
|
||||
|
||||
#endif /* PRIMNODES_H */
|
||||
|
Reference in New Issue
Block a user