mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Restructure creation of run-time pruning steps.
Previously, gen_partprune_steps() always built executor pruning steps using all suitable clauses, including those containing PARAM_EXEC Params. This meant that the pruning steps were only completely safe for executor run-time (scan start) pruning. To prune at executor startup, we had to ignore the steps involving exec Params. But this doesn't really work in general, since there may be logic changes needed as well --- for example, pruning according to the last operator's btree strategy is the wrong thing if we're not applying that operator. The rules embodied in gen_partprune_steps() and its minions are sufficiently complicated that tracking their incremental effects in other logic seems quite impractical. Short of a complete redesign, the only safe fix seems to be to run gen_partprune_steps() twice, once to create executor startup pruning steps and then again for run-time pruning steps. We can save a few cycles however by noting during the first scan whether we rejected any clauses because they involved exec Params --- if not, we don't need to do the second scan. In support of this, refactor the internal APIs in partprune.c to make more use of passing information in the GeneratePruningStepsContext struct, rather than as separate arguments. This is, I hope, the last piece of our response to a bug report from Alan Jackson. Back-patch to v11 where this code came in. Discussion: https://postgr.es/m/FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com
This commit is contained in:
@@ -58,28 +58,30 @@ typedef struct PartitionRoutingInfo
|
||||
* PartitionedRelPruneInfo (see plannodes.h); though note that here,
|
||||
* subpart_map contains indexes into PartitionPruningData.partrelprunedata[].
|
||||
*
|
||||
* nparts Length of subplan_map[] and subpart_map[].
|
||||
* subplan_map Subplan index by partition index, or -1.
|
||||
* subpart_map Subpart index by partition index, or -1.
|
||||
* present_parts A Bitmapset of the partition indexes that we
|
||||
* have subplans or subparts for.
|
||||
* context Contains the context details required to call
|
||||
* the partition pruning code.
|
||||
* pruning_steps List of PartitionPruneSteps used to
|
||||
* perform the actual pruning.
|
||||
* do_initial_prune true if pruning should be performed during
|
||||
* executor startup (for this partitioning level).
|
||||
* do_exec_prune true if pruning should be performed during
|
||||
* executor run (for this partitioning level).
|
||||
* initial_pruning_steps List of PartitionPruneSteps used to
|
||||
* perform executor startup pruning.
|
||||
* exec_pruning_steps List of PartitionPruneSteps used to
|
||||
* perform per-scan pruning.
|
||||
* initial_context If initial_pruning_steps isn't NIL, contains
|
||||
* the details needed to execute those steps.
|
||||
* exec_context If exec_pruning_steps isn't NIL, contains
|
||||
* the details needed to execute those steps.
|
||||
*/
|
||||
typedef struct PartitionedRelPruningData
|
||||
{
|
||||
int nparts;
|
||||
int *subplan_map;
|
||||
int *subpart_map;
|
||||
Bitmapset *present_parts;
|
||||
PartitionPruneContext context;
|
||||
List *pruning_steps;
|
||||
bool do_initial_prune;
|
||||
bool do_exec_prune;
|
||||
List *initial_pruning_steps;
|
||||
List *exec_pruning_steps;
|
||||
PartitionPruneContext initial_context;
|
||||
PartitionPruneContext exec_context;
|
||||
} PartitionedRelPruningData;
|
||||
|
||||
/*
|
||||
|
@@ -1109,21 +1109,23 @@ typedef struct PartitionedRelPruneInfo
|
||||
{
|
||||
NodeTag type;
|
||||
Index rtindex; /* RT index of partition rel for this level */
|
||||
List *pruning_steps; /* List of PartitionPruneStep, see below */
|
||||
Bitmapset *present_parts; /* Indexes of all partitions which subplans or
|
||||
* subparts are present for. */
|
||||
int nparts; /* Length of subplan_map[] and subpart_map[] */
|
||||
int nexprs; /* Length of hasexecparam[] */
|
||||
* subparts are present for */
|
||||
int nparts; /* Length of the following arrays: */
|
||||
int *subplan_map; /* subplan index by partition index, or -1 */
|
||||
int *subpart_map; /* subpart index by partition index, or -1 */
|
||||
Oid *relid_map; /* relation OID by partition index, or 0 */
|
||||
bool *hasexecparam; /* true if corresponding pruning_step contains
|
||||
* any PARAM_EXEC Params. */
|
||||
bool do_initial_prune; /* true if pruning should be performed
|
||||
* during executor startup. */
|
||||
bool do_exec_prune; /* true if pruning should be performed during
|
||||
* executor run. */
|
||||
Bitmapset *execparamids; /* All PARAM_EXEC Param IDs in pruning_steps */
|
||||
|
||||
/*
|
||||
* initial_pruning_steps shows how to prune during executor startup (i.e.,
|
||||
* without use of any PARAM_EXEC Params); it is NIL if no startup pruning
|
||||
* is required. exec_pruning_steps shows how to prune with PARAM_EXEC
|
||||
* Params; it is NIL if no per-scan pruning is required.
|
||||
*/
|
||||
List *initial_pruning_steps; /* List of PartitionPruneStep */
|
||||
List *exec_pruning_steps; /* List of PartitionPruneStep */
|
||||
Bitmapset *execparamids; /* All PARAM_EXEC Param IDs in
|
||||
* exec_pruning_steps */
|
||||
} PartitionedRelPruneInfo;
|
||||
|
||||
/*
|
||||
|
@@ -44,10 +44,6 @@ struct RelOptInfo;
|
||||
* exprstates Array of ExprStates, indexed as per PruneCtxStateIdx; one
|
||||
* for each partition key in each pruning step. Allocated if
|
||||
* planstate is non-NULL, otherwise NULL.
|
||||
* exprhasexecparam Array of bools, each true if corresponding 'exprstate'
|
||||
* expression contains any PARAM_EXEC Params. (Can be NULL
|
||||
* if planstate is NULL.)
|
||||
* evalexecparams True if it's safe to evaluate PARAM_EXEC Params.
|
||||
*/
|
||||
typedef struct PartitionPruneContext
|
||||
{
|
||||
@@ -61,8 +57,6 @@ typedef struct PartitionPruneContext
|
||||
MemoryContext ppccontext;
|
||||
PlanState *planstate;
|
||||
ExprState **exprstates;
|
||||
bool *exprhasexecparam;
|
||||
bool evalexecparams;
|
||||
} PartitionPruneContext;
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user