From: Robert Haas Date: Tue, 24 Jun 2025 16:08:21 +0000 (-0400) Subject: Refactoring. X-Git-Url: http://git.postgresql.org/gitweb/static/gitweb.js?a=commitdiff_plain;h=76973d518d137f84d8e5d745902c3bac7c69cf88;p=users%2Frhaas%2Fpostgres.git Refactoring. --- diff --git a/contrib/pg_plan_advice/pgpa_join.c b/contrib/pg_plan_advice/pgpa_join.c index 9bf0a71675..6b2578edf6 100644 --- a/contrib/pg_plan_advice/pgpa_join.c +++ b/contrib/pg_plan_advice/pgpa_join.c @@ -41,6 +41,7 @@ static pgpa_join_strategy pgpa_decompose_join(PlannedStmt *pstmt, static void pgpa_fix_scan_or_clump_member(pgpa_join_member *member); static ElidedNode *pgpa_descend_node(PlannedStmt *pstmt, Plan **plan); static ElidedNode *pgpa_descend_any_gather(PlannedStmt *pstmt, Plan **plan); +static ElidedNode *pgpa_descend_any_unique(PlannedStmt *pstmt, Plan **plan); static Index pgpa_scanrelid(Plan *plan); static Bitmapset *pgpa_relids(Plan *plan); @@ -439,23 +440,11 @@ pgpa_decompose_join(PlannedStmt *pstmt, Plan *plan, elog(ERROR, "unrecognized node type: %d", (int) nodeTag(plan)); } - if (elidedouter == NULL && - (IsA(outerplan, Agg) || IsA(outerplan, Unique))) - { - elidedouter = pgpa_descend_node(pstmt, &outerplan); - - if (elidedouter == NULL && is_sorting_plan(outerplan)) - elidedouter = pgpa_descend_node(pstmt, &outerplan); - } - - if (elidedinner == NULL && - (IsA(innerplan, Agg) || IsA(innerplan, Unique))) - { - elidedinner = pgpa_descend_node(pstmt, &innerplan); + if (elidedouter == NULL) + elidedouter = pgpa_descend_any_unique(pstmt, &outerplan); - if (elidedinner == NULL && is_sorting_plan(innerplan)) - elidedinner = pgpa_descend_node(pstmt, &innerplan); - } + if (elidedinner == NULL) + elidedinner = pgpa_descend_any_unique(pstmt, &innerplan); if (elidedouter == NULL) elidedouter = pgpa_descend_any_gather(pstmt, &outerplan); @@ -561,6 +550,32 @@ pgpa_descend_any_gather(PlannedStmt *pstmt, Plan **plan) return NULL; } +/* + * Descend through an Agg or Unique node, if present, and any Sort or + * IncrementalSort node occurring beneath it. + * + * Caller should have verified that there is no ElidedNode pertaining to + * the initial value of *plan. + * + * Updates *plan, and returns the last of any elided nodes pertaining to the + * new plan node. + */ +static ElidedNode * +pgpa_descend_any_unique(PlannedStmt *pstmt, Plan **plan) +{ + if (IsA(*plan, Agg) || IsA(*plan, Unique)) + { + ElidedNode *elided = pgpa_descend_node(pstmt, plan); + + if (elided == NULL && is_sorting_plan(*plan)) + elided = pgpa_descend_node(pstmt, plan); + + return elided; + } + + return NULL; +} + /* * Update a pgpa_gathered_join to include RTIs scanned by the provided * plan node.