aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/include')
-rw-r--r--src/include/executor/execPartition.h77
-rw-r--r--src/include/nodes/execnodes.h12
-rw-r--r--src/include/nodes/nodes.h1
-rw-r--r--src/include/nodes/plannodes.h5
-rw-r--r--src/include/nodes/primnodes.h23
-rw-r--r--src/include/optimizer/pathnode.h2
-rw-r--r--src/include/partitioning/partprune.h14
7 files changed, 131 insertions, 3 deletions
diff --git a/src/include/executor/execPartition.h b/src/include/executor/execPartition.h
index 63c883093ea..b2daf24c41d 100644
--- a/src/include/executor/execPartition.h
+++ b/src/include/executor/execPartition.h
@@ -17,6 +17,7 @@
#include "nodes/execnodes.h"
#include "nodes/parsenodes.h"
#include "nodes/plannodes.h"
+#include "partitioning/partprune.h"
/*-----------------------
* PartitionDispatch - information about one partitioned table in a partition
@@ -108,6 +109,77 @@ typedef struct PartitionTupleRouting
TupleTableSlot *root_tuple_slot;
} PartitionTupleRouting;
+/*-----------------------
+ * PartitionPruningData - Encapsulates all information required to support
+ * elimination of partitions in node types which support arbitrary Lists of
+ * subplans. Information stored here allows the planner's partition pruning
+ * functions to be called and the return value of partition indexes translated
+ * into the subpath indexes of node types such as Append, thus allowing us to
+ * bypass certain subnodes when we have proofs that indicate that no tuple
+ * matching the 'pruning_steps' will be found within.
+ *
+ * subnode_map An array containing the subnode index which
+ * matches this partition index, or -1 if the
+ * subnode has been pruned already.
+ * subpart_map An array containing the offset into the
+ * 'partprunedata' array in PartitionPruning, or
+ * -1 if there is no such element in that array.
+ * present_parts A Bitmapset of the partition index that we have
+ * subnodes mapped for.
+ * context Contains the context details required to call
+ * the partition pruning code.
+ * pruning_steps Contains a list of PartitionPruneStep used to
+ * perform the actual pruning.
+ * extparams Contains paramids of external params found
+ * matching partition keys in 'pruning_steps'.
+ * allparams As 'extparams' but also including exec params.
+ *-----------------------
+ */
+typedef struct PartitionPruningData
+{
+ int *subnode_map;
+ int *subpart_map;
+ Bitmapset *present_parts;
+ PartitionPruneContext context;
+ List *pruning_steps;
+ Bitmapset *extparams;
+ Bitmapset *allparams;
+} PartitionPruningData;
+
+/*-----------------------
+ * PartitionPruneState - State object required for executor nodes to perform
+ * partition pruning elimination of their subnodes. This encapsulates a
+ * flattened hierarchy of PartitionPruningData structs and also stores all
+ * paramids which were found to match the partition keys of each partition.
+ * This struct can be attached to node types which support arbitrary Lists of
+ * subnodes containing partitions to allow subnodes to be eliminated due to
+ * the clauses being unable to match to any tuple that the subnode could
+ * possibly produce.
+ *
+ * partprunedata Array of PartitionPruningData for the node's target
+ * partitioned relation. First element contains the
+ * details for the target partitioned table.
+ * num_partprunedata Number of items in 'partprunedata' array.
+ * prune_context A memory context which can be used to call the query
+ * planner's partition prune functions.
+ * extparams All PARAM_EXTERN paramids which were found to match a
+ * partition key in each of the contained
+ * PartitionPruningData structs.
+ * execparams As above but for PARAM_EXEC.
+ * allparams Union of 'extparams' and 'execparams', saved to avoid
+ * recalculation.
+ *-----------------------
+ */
+typedef struct PartitionPruneState
+{
+ PartitionPruningData *partprunedata;
+ int num_partprunedata;
+ MemoryContext prune_context;
+ Bitmapset *extparams;
+ Bitmapset *execparams;
+ Bitmapset *allparams;
+} PartitionPruneState;
+
extern PartitionTupleRouting *ExecSetupPartitionTupleRouting(ModifyTableState *mtstate,
Relation rel);
extern int ExecFindPartition(ResultRelInfo *resultRelInfo,
@@ -133,5 +205,10 @@ extern HeapTuple ConvertPartitionTupleSlot(TupleConversionMap *map,
TupleTableSlot **p_my_slot);
extern void ExecCleanupTupleRouting(ModifyTableState *mtstate,
PartitionTupleRouting *proute);
+extern PartitionPruneState *ExecSetupPartitionPruneState(PlanState *planstate,
+ List *partitionpruneinfo);
+extern Bitmapset *ExecFindMatchingSubPlans(PartitionPruneState *prunestate);
+extern Bitmapset *ExecFindInitialMatchingSubPlans(PartitionPruneState *prunestate,
+ int nsubnodes);
#endif /* EXECPARTITION_H */
diff --git a/src/include/nodes/execnodes.h b/src/include/nodes/execnodes.h
index 4ad5131aa97..06456f07cc7 100644
--- a/src/include/nodes/execnodes.h
+++ b/src/include/nodes/execnodes.h
@@ -1123,8 +1123,13 @@ typedef struct ModifyTableState
/* ----------------
* AppendState information
*
- * nplans how many plans are in the array
- * whichplan which plan is being executed (0 .. n-1)
+ * nplans how many plans are in the array
+ * whichplan which plan is being executed (0 .. n-1), or a
+ * special negative value. See nodeAppend.c.
+ * pruningstate details required to allow partitions to be
+ * eliminated from the scan, or NULL if not possible.
+ * valid_subplans for runtime pruning, valid appendplans indexes to
+ * scan.
* ----------------
*/
@@ -1132,6 +1137,7 @@ struct AppendState;
typedef struct AppendState AppendState;
struct ParallelAppendState;
typedef struct ParallelAppendState ParallelAppendState;
+struct PartitionPruneState;
struct AppendState
{
@@ -1141,6 +1147,8 @@ struct AppendState
int as_whichplan;
ParallelAppendState *as_pstate; /* parallel coordination info */
Size pstate_len; /* size of parallel coordination info */
+ struct PartitionPruneState *as_prune_state;
+ Bitmapset *as_valid_subplans;
bool (*choose_next_subplan) (AppendState *);
};
diff --git a/src/include/nodes/nodes.h b/src/include/nodes/nodes.h
index 4fc2de7184a..defdbae5070 100644
--- a/src/include/nodes/nodes.h
+++ b/src/include/nodes/nodes.h
@@ -196,6 +196,7 @@ typedef enum NodeTag
T_PartitionPruneStep,
T_PartitionPruneStepOp,
T_PartitionPruneStepCombine,
+ T_PartitionPruneInfo,
/*
* TAGS FOR EXPRESSION STATE NODES (execnodes.h)
diff --git a/src/include/nodes/plannodes.h b/src/include/nodes/plannodes.h
index 0a797f0a052..c3e5c2c79f8 100644
--- a/src/include/nodes/plannodes.h
+++ b/src/include/nodes/plannodes.h
@@ -256,6 +256,11 @@ typedef struct Append
List *partitioned_rels;
List *appendplans;
int first_partial_plan;
+
+ /*
+ * Mapping details for run-time subplan pruning, one per partitioned_rels
+ */
+ List *part_prune_infos;
} Append;
/* ----------------
diff --git a/src/include/nodes/primnodes.h b/src/include/nodes/primnodes.h
index ff5c4ff8e4a..f90aa7b2a19 100644
--- a/src/include/nodes/primnodes.h
+++ b/src/include/nodes/primnodes.h
@@ -1581,4 +1581,27 @@ typedef struct PartitionPruneStepCombine
List *source_stepids;
} PartitionPruneStepCombine;
+/*----------
+ * PartitionPruneInfo - Details required to allow the executor to prune
+ * partitions.
+ *
+ * Here we store mapping details to allow translation of a partitioned table's
+ * index into subnode indexes for node types which support arbitrary numbers
+ * of sub nodes, such as Append.
+ *----------
+ */
+typedef struct PartitionPruneInfo
+{
+ NodeTag type;
+ Oid reloid; /* Oid of partition rel */
+ List *pruning_steps; /* List of PartitionPruneStep */
+ Bitmapset *present_parts; /* Indexes of all partitions which subnodes
+ * are present for. */
+ int nparts; /* The length of the following two arrays */
+ int *subnode_map; /* subnode index by partition id, or -1 */
+ int *subpart_map; /* subpart index by partition id, or -1 */
+ Bitmapset *extparams; /* All external paramids seen in prunesteps */
+ Bitmapset *execparams; /* All exec paramids seen in prunesteps */
+} PartitionPruneInfo;
+
#endif /* PRIMNODES_H */
diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h
index 895bf6959da..4f65686d9be 100644
--- a/src/include/optimizer/pathnode.h
+++ b/src/include/optimizer/pathnode.h
@@ -64,7 +64,7 @@ extern BitmapOrPath *create_bitmap_or_path(PlannerInfo *root,
List *bitmapquals);
extern TidPath *create_tidscan_path(PlannerInfo *root, RelOptInfo *rel,
List *tidquals, Relids required_outer);
-extern AppendPath *create_append_path(RelOptInfo *rel,
+extern AppendPath *create_append_path(PlannerInfo *root, RelOptInfo *rel,
List *subpaths, List *partial_subpaths,
Relids required_outer,
int parallel_workers, bool parallel_aware,
diff --git a/src/include/partitioning/partprune.h b/src/include/partitioning/partprune.h
index 52fadc7caf0..f68b6c9935a 100644
--- a/src/include/partitioning/partprune.h
+++ b/src/include/partitioning/partprune.h
@@ -37,9 +37,23 @@ typedef struct PartitionPruneContext
/* Partition boundary info */
PartitionBoundInfo boundinfo;
+
+ /*
+ * Can be set when the context is used from the executor to allow params
+ * found matching the partition key to be evaulated.
+ */
+ PlanState *planstate;
+
+ /*
+ * Parameters that are safe to be used for partition pruning. execparams
+ * are not safe to use until the executor is running.
+ */
+ Bitmapset *safeparams;
} PartitionPruneContext;
+extern List *make_partition_pruneinfo(PlannerInfo *root, List *partition_rels,
+ List *subpaths, List *prunequal);
extern Relids prune_append_rel_partitions(RelOptInfo *rel);
extern Bitmapset *get_matching_partitions(PartitionPruneContext *context,
List *pruning_steps);