mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Perform runtime initial pruning outside ExecInitNode()
This commit builds on the prior change that moved PartitionPruneInfos out of individual plan nodes into a list in PlannedStmt, making it possible to initialize PartitionPruneStates without traversing the plan tree and perform runtime initial pruning before ExecInitNode() initializes the plan trees. These tasks are now handled in a new routine, ExecDoInitialPruning(), which is called by InitPlan() before calling ExecInitNode() on various plan trees. ExecDoInitialPruning() performs the initial pruning and saves the result -- a Bitmapset of indexes for surviving child subnodes -- in es_part_prune_results, a list in EState. PartitionPruneStates created for initial pruning are stored in es_part_prune_states, another list in EState, for later use during exec pruning. Both lists are parallel to es_part_prune_infos, which holds the PartitionPruneInfos from PlannedStmt, enabling shared indexing. PartitionPruneStates initialized in ExecDoInitialPruning() now include only the PartitionPruneContexts for initial pruning steps. Exec pruning contexts are initialized later in ExecInitPartitionExecPruning() when the parent plan node is initialized, as the exec pruning step expressions depend on the parent node's PlanState. The existing function PartitionPruneFixSubPlanMap() has been repurposed for this initialization to avoid duplicating a similar loop structure for finding PartitionedRelPruningData to initialize exec pruning contexts for. It has been renamed to InitExecPruningContexts() to reflect its new primary responsibility. The original logic to "fix subplan maps" remains intact but is now encapsulated within the renamed function. This commit removes two obsolete Asserts in partkey_datum_from_expr(). The ExprContext used for pruning expression evaluation is now independent of the parent PlanState, making these Asserts unnecessary. By centralizing pruning logic and decoupling it from the plan initialization step (ExecInitNode()), this change sets the stage for future patches that will use the result of initial pruning to save the overhead of redundant processing for pruned partitions. Reviewed-by: Robert Haas <robertmhaas@gmail.com> Reviewed-by: Tomas Vondra <tomas@vondra.me> Discussion: https://postgr.es/m/CA+HiwqFGkMSge6TgC9KQzde0ohpAycLQuV7ooitEEpbKB0O_mg@mail.gmail.com
This commit is contained in:
@ -46,6 +46,7 @@
|
||||
#include "commands/matview.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "executor/executor.h"
|
||||
#include "executor/execPartition.h"
|
||||
#include "executor/nodeSubplan.h"
|
||||
#include "foreign/fdwapi.h"
|
||||
#include "mb/pg_wchar.h"
|
||||
@ -855,6 +856,17 @@ InitPlan(QueryDesc *queryDesc, int eflags)
|
||||
estate->es_plannedstmt = plannedstmt;
|
||||
estate->es_part_prune_infos = plannedstmt->partPruneInfos;
|
||||
|
||||
/*
|
||||
* Perform runtime "initial" pruning to identify which child subplans,
|
||||
* corresponding to the children of plan nodes that contain
|
||||
* PartitionPruneInfo such as Append, will not be executed. The results,
|
||||
* which are bitmapsets of indexes of the child subplans that will be
|
||||
* executed, are saved in es_part_prune_results. These results correspond
|
||||
* to each PartitionPruneInfo entry, and the es_part_prune_results list is
|
||||
* parallel to es_part_prune_infos.
|
||||
*/
|
||||
ExecDoInitialPruning(estate);
|
||||
|
||||
/*
|
||||
* Next, build the ExecRowMark array from the PlanRowMark(s), if any.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user