From e1e9631c9f97762ec57d253314d6d745050138fc Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Tue, 15 Jul 2025 12:24:49 -0400 Subject: [PATCH] Remove pgpa_gathered_join -- query features make it is obsolete. --- contrib/pg_plan_advice/pg_plan_advice.c | 4 +- contrib/pg_plan_advice/pgpa_join.c | 33 ------------- contrib/pg_plan_advice/pgpa_join.h | 13 ------ contrib/pg_plan_advice/pgpa_output.c | 14 ------ contrib/pg_plan_advice/pgpa_walker.c | 62 ++----------------------- contrib/pg_plan_advice/pgpa_walker.h | 1 - src/tools/pgindent/typedefs.list | 1 - 7 files changed, 6 insertions(+), 122 deletions(-) diff --git a/contrib/pg_plan_advice/pg_plan_advice.c b/contrib/pg_plan_advice/pg_plan_advice.c index 71c0c6d270..992e711b91 100644 --- a/contrib/pg_plan_advice/pg_plan_advice.c +++ b/contrib/pg_plan_advice/pg_plan_advice.c @@ -324,7 +324,7 @@ pg_plan_advice_generate(PlannedStmt *pstmt) context.pstmt = pstmt; /* Walk the main plan tree. */ - pgpa_plan_walker(&context, pstmt->planTree, 0, NULL, NULL, NIL); + pgpa_plan_walker(&context, pstmt->planTree, 0, NULL, NIL); /* Main plan tree walk won't reach subplans, so walk those. */ foreach(lc, pstmt->subplans) @@ -332,7 +332,7 @@ pg_plan_advice_generate(PlannedStmt *pstmt) Plan *plan = lfirst(lc); if (plan != NULL) - pgpa_plan_walker(&context, plan, 0, NULL, NULL, NIL); + pgpa_plan_walker(&context, plan, 0, NULL, NIL); } /* Put advice into string form. */ diff --git a/contrib/pg_plan_advice/pgpa_join.c b/contrib/pg_plan_advice/pgpa_join.c index 8ced1a0c33..d7a5c99ffd 100644 --- a/contrib/pg_plan_advice/pgpa_join.c +++ b/contrib/pg_plan_advice/pgpa_join.c @@ -692,39 +692,6 @@ pgpa_add_member_relids(Bitmapset *relids, pgpa_join_member *member) return bms_add_member(relids, member->rti); } -/* - * Update a pgpa_gathered_join to include RTIs scanned by the provided - * plan node. - */ -void -pgpa_add_to_gathered_join(pgpa_gathered_join *gathered_join, Plan *plan) -{ - Bitmapset *relids = pgpa_relids(plan); - Index rti; - - /* - * In cases where a single node replaces a join -- such as a Result node - * that replaces a join between multiple provably-empty relations -- or - * when partitionwise join is chosen, we find multiple RTIs for a single - * Plan node and must add all of them to the pgpa_gathered_join. - */ - if (relids != NULL) - { - gathered_join->relids = bms_add_members(gathered_join->relids, - relids); - return; - } - - /* - * Otherwise, maybe there's a single RTI that this Plan node is scanning. - * If so, we should add its RTI to the pgpa_gathered_join; else, there's - * nothing to do here. - */ - rti = pgpa_scanrelid(plan); - if (rti != 0) - gathered_join->relids = bms_add_member(gathered_join->relids, rti); -} - /* * Is this a Result node that has a child? */ diff --git a/contrib/pg_plan_advice/pgpa_join.h b/contrib/pg_plan_advice/pgpa_join.h index 55e2cfbecf..a3bc287e48 100644 --- a/contrib/pg_plan_advice/pgpa_join.h +++ b/contrib/pg_plan_advice/pgpa_join.h @@ -134,16 +134,6 @@ typedef enum PGPA_UNROLLED_JOIN } pgpa_join_class; -/* - * Relevant details about which relations are joined beneath a Gather or - * Gather Merge node. - */ -typedef struct pgpa_gathered_join -{ - bool is_merge; - Bitmapset *relids; -} pgpa_gathered_join; - extern pgpa_join_class pgpa_get_join_class(Plan *plan); extern pgpa_clumped_join *pgpa_build_clumped_join(PlannedStmt *pstmt, Plan *plan, @@ -160,7 +150,4 @@ extern pgpa_unrolled_join *pgpa_build_unrolled_join(PlannedStmt *pstmt, extern void pgpa_destroy_join_unroller(pgpa_join_unroller *join_unroller); extern Bitmapset *pgpa_unrolled_join_all_relids(pgpa_unrolled_join *join); -extern void pgpa_add_to_gathered_join(pgpa_gathered_join *gathered_join, - Plan *plan); - #endif diff --git a/contrib/pg_plan_advice/pgpa_output.c b/contrib/pg_plan_advice/pgpa_output.c index 632f3dff62..a8c121d9c8 100644 --- a/contrib/pg_plan_advice/pgpa_output.c +++ b/contrib/pg_plan_advice/pgpa_output.c @@ -133,20 +133,6 @@ pgpa_output_advice(StringInfo buf, pgpa_plan_walker_context *walker, appendStringInfoChar(buf, ')'); } - foreach(lc, walker->gathered_joins) - { - pgpa_gathered_join *gathered_join = lfirst(lc); - - if (buf->len > 0) - appendStringInfoChar(buf, '\n'); - if (gathered_join->is_merge) - appendStringInfo(buf, "GATHER_MERGE("); - else - appendStringInfo(buf, "GATHER("); - pgpa_output_relations(&context, buf, gathered_join->relids); - appendStringInfoChar(buf, ')'); - } - foreach(lc, walker->query_features) { pgpa_query_feature *qf = lfirst(lc); diff --git a/contrib/pg_plan_advice/pgpa_walker.c b/contrib/pg_plan_advice/pgpa_walker.c index e0cd9355a9..694961eac8 100644 --- a/contrib/pg_plan_advice/pgpa_walker.c +++ b/contrib/pg_plan_advice/pgpa_walker.c @@ -22,7 +22,6 @@ void pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan, int join_unroll_level, pgpa_join_unroller *join_unroller, - pgpa_gathered_join *gathered_join, List *active_query_features) { pgpa_join_unroller *outer_join_unroller = NULL; @@ -64,30 +63,6 @@ pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan, pgpa_qf_add_rtis(active_query_features, last_elided_node->relids); } - /* - * If we're trying to accumulate the set of relids beneath a Gather or - * Gather Merge node, add the relids from the last elided node to the - * set. Earlier elided nodes don't need to be mentioned, because we - * only want to accumulate RTIs that are part of the same join - * problem. - * - * For instance, if a Gather node appears above a join between p and - * q, we do not really care whether p is a plain table, a partitioned - * table with children p1 and p2, or a non-inlined subquery containing - * arbitrary logic. Knowing that p was joined to q and that the Gather - * node appears above that join is enough for us to understand that - * any substructure of p and/or q must also appear beneath the Gather - * node. - */ - if (gathered_join != NULL) - { - ElidedNode *last_elided_node; - - last_elided_node = list_nth(elided_nodes, num_elided_nodes - 1); - gathered_join->relids = bms_add_members(gathered_join->relids, - last_elided_node->relids); - } - /* * If there are multiple relids for the elided node, a clumped join * should be built for it exactly once. When there's a join_unroller, @@ -126,28 +101,8 @@ pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan, * flattening it into the parent. In either case, the join order and * join methods beneath the elided node should be described separately * from the join order and methods above the elided node. - * - * Likewise, we only expect a ppga_gathered_join to mention the RTIs - * from the join problem considered immediately beneath the Gather or - * Gather Merge node. */ join_unroller = NULL; - gathered_join = NULL; - } - - /* - * If we've found a Gather or Gather Merge node, prepare to accumulate the - * associated RTIs in a new ppga_gathered_join object. - */ - if (IsA(plan, Gather) || IsA(plan, GatherMerge)) - { - if (gathered_join != NULL) - elog(ERROR, "nested Gather or Gather Merge nodes"); - gathered_join = palloc(sizeof(pgpa_gathered_join)); - gathered_join->is_merge = IsA(plan, GatherMerge); - gathered_join->relids = NULL; - context->gathered_joins = - lappend(context->gathered_joins, gathered_join); } /* Check whether the Plan node is a join, and if so, which kind. */ @@ -186,13 +141,6 @@ pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan, pgpa_unroll_join(context, plan, join_unroller, &outer_join_unroller, &inner_join_unroller); - /* - * If we are collecting RTIs below Gather (Merge), add any appropriate - * RTIs for this node. - */ - if (gathered_join != NULL) - pgpa_add_to_gathered_join(gathered_join, plan); - /* * If this is a Gather or Gather Merge node, directly add it to the list * of currently-active query features. @@ -236,12 +184,10 @@ pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan, /* Recurse into the outer and inner subtrees. */ if (plan->lefttree != NULL) pgpa_plan_walker(context, plan->lefttree, join_unroll_level, - outer_join_unroller, gathered_join, - active_query_features); + outer_join_unroller, active_query_features); if (plan->righttree != NULL) pgpa_plan_walker(context, plan->righttree, join_unroll_level, - inner_join_unroller, gathered_join, - active_query_features); + inner_join_unroller, active_query_features); /* * If we created a join unroller up above, then it's also our join to use @@ -291,7 +237,7 @@ pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan, * those are specific to a subquery level. */ pgpa_plan_walker(context, ((SubqueryScan *) plan)->subplan, - 0, NULL, NULL, NIL); + 0, NULL, NIL); break; case T_CustomScan: extraplans = ((CustomScan *) plan)->custom_plans; @@ -305,7 +251,7 @@ pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan, { Plan *subplan = lfirst(lc); - pgpa_plan_walker(context, subplan, 0, NULL, NULL, + pgpa_plan_walker(context, subplan, 0, NULL, pushdown_query_features ? active_query_features : NIL); } diff --git a/contrib/pg_plan_advice/pgpa_walker.h b/contrib/pg_plan_advice/pgpa_walker.h index 6533a877e0..65a366ee06 100644 --- a/contrib/pg_plan_advice/pgpa_walker.h +++ b/contrib/pg_plan_advice/pgpa_walker.h @@ -69,7 +69,6 @@ typedef struct pgpa_plan_walker_context extern void pgpa_plan_walker(pgpa_plan_walker_context *context, Plan *plan, int join_unroll_level, pgpa_join_unroller *join_unroller, - pgpa_gathered_join *gathered_join, List *active_query_features); extern void pgpa_add_future_feature(pgpa_plan_walker_context *context, diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index 9b5d1572fb..f8622e276c 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -4319,7 +4319,6 @@ pgpa_clumped_join pgpa_unrolled_join pgpa_join_unroller pgpa_plan_walker_context -pgpa_gathered_join pgpa_output_context pgpa_collected_advice pgpa_local_advice_chunk -- 2.39.5