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