mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Move PartitionPruneInfo out of plan nodes into PlannedStmt
This moves PartitionPruneInfo from plan nodes to PlannedStmt, simplifying traversal by centralizing all PartitionPruneInfo structures in a single list in it, which holds all instances for the main query and its subqueries. Instead of plan nodes (Append or MergeAppend) storing PartitionPruneInfo pointers, they now reference an index in this list. A bitmapset field is added to PartitionPruneInfo to store the RT indexes corresponding to the apprelids field in Append or MergeAppend. This allows execution pruning logic to verify that it operates on the correct plan node, mainly to facilitate debugging. Duplicated code in set_append_references() and set_mergeappend_references() is refactored into a new function, register_pruneinfo(). This updates RT indexes by applying rtoffet and adds PartitionPruneInfo to the global list in PlannerGlobal. By allowing pruning to be performed without traversing the plan tree, this change lays the groundwork for runtime initial pruning to occur independently of plan tree initialization. Reviewed-by: Alvaro Herrera <alvherre@alvh.no-ip.org> (earlier version) 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:
@@ -207,16 +207,20 @@ static void partkey_datum_from_expr(PartitionPruneContext *context,
|
||||
|
||||
/*
|
||||
* make_partition_pruneinfo
|
||||
* Builds a PartitionPruneInfo which can be used in the executor to allow
|
||||
* additional partition pruning to take place. Returns NULL when
|
||||
* partition pruning would be useless.
|
||||
* Checks if the given set of quals can be used to build pruning steps
|
||||
* that the executor can use to prune away unneeded partitions. If
|
||||
* suitable quals are found then a PartitionPruneInfo is built and tagged
|
||||
* onto the PlannerInfo's partPruneInfos list.
|
||||
*
|
||||
* The return value is the 0-based index of the item added to the
|
||||
* partPruneInfos list or -1 if nothing was added.
|
||||
*
|
||||
* 'parentrel' is the RelOptInfo for an appendrel, and 'subpaths' is the list
|
||||
* of scan paths for its child rels.
|
||||
* 'prunequal' is a list of potential pruning quals (i.e., restriction
|
||||
* clauses that are applicable to the appendrel).
|
||||
*/
|
||||
PartitionPruneInfo *
|
||||
int
|
||||
make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
|
||||
List *subpaths,
|
||||
List *prunequal)
|
||||
@@ -330,10 +334,11 @@ make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
|
||||
* quals, then we can just not bother with run-time pruning.
|
||||
*/
|
||||
if (prunerelinfos == NIL)
|
||||
return NULL;
|
||||
return -1;
|
||||
|
||||
/* Else build the result data structure */
|
||||
pruneinfo = makeNode(PartitionPruneInfo);
|
||||
pruneinfo->relids = bms_copy(parentrel->relids);
|
||||
pruneinfo->prune_infos = prunerelinfos;
|
||||
|
||||
/*
|
||||
@@ -356,7 +361,9 @@ make_partition_pruneinfo(PlannerInfo *root, RelOptInfo *parentrel,
|
||||
else
|
||||
pruneinfo->other_subplans = NULL;
|
||||
|
||||
return pruneinfo;
|
||||
root->partPruneInfos = lappend(root->partPruneInfos, pruneinfo);
|
||||
|
||||
return list_length(root->partPruneInfos) - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user