| 1 |
/*-------------------------------------------------------------------- |
| 2 |
* execPartition.h |
| 3 |
* POSTGRES partitioning executor interface |
| 4 |
* |
| 5 |
* Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group |
| 6 |
* Portions Copyright (c) 1994, Regents of the University of California |
| 7 |
* |
| 8 |
* IDENTIFICATION |
| 9 |
* src/include/executor/execPartition.h |
| 10 |
*-------------------------------------------------------------------- |
| 11 |
*/ |
| 12 |
|
| 13 |
#ifndef EXECPARTITION_H |
| 14 |
#define EXECPARTITION_H |
| 15 |
|
| 16 |
#include "nodes/execnodes.h" |
| 17 |
#include "nodes/parsenodes.h" |
| 18 |
#include "nodes/plannodes.h" |
| 19 |
#include "partitioning/partprune.h" |
| 20 |
|
| 21 |
/* See execPartition.c for the definitions. */ |
| 22 |
typedef struct PartitionDispatchData *PartitionDispatch; |
| 23 |
typedef struct PartitionTupleRouting PartitionTupleRouting; |
| 24 |
|
| 25 |
extern PartitionTupleRouting *ExecSetupPartitionTupleRouting(EState *estate, |
| 26 |
Relation rel); |
| 27 |
extern ResultRelInfo *ExecFindPartition(ModifyTableState *mtstate, |
| 28 |
ResultRelInfo *rootResultRelInfo, |
| 29 |
PartitionTupleRouting *proute, |
| 30 |
TupleTableSlot *slot, |
| 31 |
EState *estate); |
| 32 |
extern void ExecCleanupTupleRouting(ModifyTableState *mtstate, |
| 33 |
PartitionTupleRouting *proute); |
| 34 |
|
| 35 |
|
| 36 |
/* |
| 37 |
* PartitionedRelPruningData - Per-partitioned-table data for run-time pruning |
| 38 |
* of partitions. For a multilevel partitioned table, we have one of these |
| 39 |
* for the topmost partition plus one for each non-leaf child partition. |
| 40 |
* |
| 41 |
* subplan_map[] and subpart_map[] have the same definitions as in |
| 42 |
* PartitionedRelPruneInfo (see plannodes.h); though note that here, |
| 43 |
* subpart_map contains indexes into PartitionPruningData.partrelprunedata[]. |
| 44 |
* |
| 45 |
* partrel Partitioned table Relation; obtained by |
| 46 |
* ExecGetRangeTableRelation(estate, rti, false), |
| 47 |
* where rti is PartitionedRelPruneInfo.rtindex. |
| 48 |
* nparts Length of subplan_map[] and subpart_map[]. |
| 49 |
* subplan_map Subplan index by partition index, or -1. |
| 50 |
* subpart_map Subpart index by partition index, or -1. |
| 51 |
* leafpart_rti_map RT index by partition index, or 0. |
| 52 |
* present_parts A Bitmapset of the partition indexes that we |
| 53 |
* have subplans or subparts for. |
| 54 |
* initial_pruning_steps List of PartitionPruneSteps used to |
| 55 |
* perform executor startup pruning. |
| 56 |
* exec_pruning_steps List of PartitionPruneSteps used to |
| 57 |
* perform per-scan pruning. |
| 58 |
* initial_context If initial_pruning_steps isn't NIL, contains |
| 59 |
* the details needed to execute those steps. |
| 60 |
* exec_context If exec_pruning_steps isn't NIL, contains |
| 61 |
* the details needed to execute those steps. |
| 62 |
*/ |
| 63 |
typedef struct PartitionedRelPruningData |
| 64 |
{ |
| 65 |
Relation partrel; |
| 66 |
int nparts; |
| 67 |
int *subplan_map; |
| 68 |
int *subpart_map; |
| 69 |
int *leafpart_rti_map; |
| 70 |
Bitmapset *present_parts; |
| 71 |
List *initial_pruning_steps; |
| 72 |
List *exec_pruning_steps; |
| 73 |
PartitionPruneContext initial_context; |
| 74 |
PartitionPruneContext exec_context; |
| 75 |
} PartitionedRelPruningData; |
| 76 |
|
| 77 |
/* |
| 78 |
* PartitionPruningData - Holds all the run-time pruning information for |
| 79 |
* a single partitioning hierarchy containing one or more partitions. |
| 80 |
* partrelprunedata[] is an array ordered such that parents appear before |
| 81 |
* their children; in particular, the first entry is the topmost partition, |
| 82 |
* which was actually named in the SQL query. |
| 83 |
*/ |
| 84 |
typedef struct PartitionPruningData |
| 85 |
{ |
| 86 |
int num_partrelprunedata; /* number of array entries */ |
| 87 |
PartitionedRelPruningData partrelprunedata[FLEXIBLE_ARRAY_MEMBER]; |
| 88 |
} PartitionPruningData; |
| 89 |
|
| 90 |
/* |
| 91 |
* PartitionPruneState - State object required for plan nodes to perform |
| 92 |
* run-time partition pruning. |
| 93 |
* |
| 94 |
* This struct can be attached to plan types which support arbitrary Lists of |
| 95 |
* subplans containing partitions, to allow subplans to be eliminated due to |
| 96 |
* the clauses being unable to match to any tuple that the subplan could |
| 97 |
* possibly produce. |
| 98 |
* |
| 99 |
* econtext Standalone ExprContext to evaluate expressions in |
| 100 |
* the pruning steps |
| 101 |
* execparamids Contains paramids of PARAM_EXEC Params found within |
| 102 |
* any of the partprunedata structs. Pruning must be |
| 103 |
* done again each time the value of one of these |
| 104 |
* parameters changes. |
| 105 |
* other_subplans Contains indexes of subplans that don't belong to any |
| 106 |
* "partprunedata", e.g UNION ALL children that are not |
| 107 |
* partitioned tables, or a partitioned table that the |
| 108 |
* planner deemed run-time pruning to be useless for. |
| 109 |
* These must not be pruned. |
| 110 |
* prune_context A short-lived memory context in which to execute the |
| 111 |
* partition pruning functions. |
| 112 |
* do_initial_prune true if pruning should be performed during executor |
| 113 |
* startup (at any hierarchy level). |
| 114 |
* do_exec_prune true if pruning should be performed during |
| 115 |
* executor run (at any hierarchy level). |
| 116 |
* num_partprunedata Number of items in "partprunedata" array. |
| 117 |
* partprunedata Array of PartitionPruningData pointers for the plan's |
| 118 |
* partitioned relation(s), one for each partitioning |
| 119 |
* hierarchy that requires run-time pruning. |
| 120 |
*/ |
| 121 |
typedef struct PartitionPruneState |
| 122 |
{ |
| 123 |
ExprContext *econtext; |
| 124 |
Bitmapset *execparamids; |
| 125 |
Bitmapset *other_subplans; |
| 126 |
MemoryContext prune_context; |
| 127 |
bool do_initial_prune; |
| 128 |
bool do_exec_prune; |
| 129 |
int num_partprunedata; |
| 130 |
PartitionPruningData *partprunedata[FLEXIBLE_ARRAY_MEMBER]; |
| 131 |
} PartitionPruneState; |
| 132 |
|
| 133 |
extern void ExecDoInitialPruning(EState *estate); |
| 134 |
extern PartitionPruneState *ExecInitPartitionExecPruning(PlanState *planstate, |
| 135 |
int n_total_subplans, |
| 136 |
int part_prune_index, |
| 137 |
Bitmapset *relids, |
| 138 |
Bitmapset **initially_valid_subplans); |
| 139 |
extern Bitmapset *ExecFindMatchingSubPlans(PartitionPruneState *prunestate, |
| 140 |
bool initial_prune, |
| 141 |
Bitmapset **validsubplan_rtis); |
| 142 |
|
| 143 |
#endif /* EXECPARTITION_H */ |