From 8427dba043f96463116d739e7761e4bb8387fb90 Mon Sep 17 00:00:00 2001 From: Richard Guo Date: Mon, 17 Nov 2025 10:28:36 +0900 Subject: [PATCH v3 2/3] Remove nrm_match parameter from fix_upper_expr --- src/backend/optimizer/plan/setrefs.c | 32 ++++++---------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index ae29d59c78f..c95aaa6d858 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -78,7 +78,6 @@ typedef struct indexed_tlist *subplan_itlist; int newvarno; int rtoffset; - NullingRelsMatch nrm_match; double num_exec; } fix_upper_expr_context; @@ -197,7 +196,6 @@ static Node *fix_upper_expr(PlannerInfo *root, indexed_tlist *subplan_itlist, int newvarno, int rtoffset, - NullingRelsMatch nrm_match, double num_exec); static Node *fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context); @@ -1407,7 +1405,6 @@ set_indexonlyscan_references(PlannerInfo *root, index_itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_TLIST((Plan *) plan)); plan->scan.plan.qual = (List *) fix_upper_expr(root, @@ -1415,7 +1412,6 @@ set_indexonlyscan_references(PlannerInfo *root, index_itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL((Plan *) plan)); plan->recheckqual = (List *) fix_upper_expr(root, @@ -1423,7 +1419,6 @@ set_indexonlyscan_references(PlannerInfo *root, index_itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL((Plan *) plan)); /* indexqual is already transformed to reference index columns */ plan->indexqual = fix_scan_list(root, plan->indexqual, @@ -1660,7 +1655,6 @@ set_foreignscan_references(PlannerInfo *root, itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_TLIST((Plan *) fscan)); fscan->scan.plan.qual = (List *) fix_upper_expr(root, @@ -1668,7 +1662,6 @@ set_foreignscan_references(PlannerInfo *root, itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL((Plan *) fscan)); fscan->fdw_exprs = (List *) fix_upper_expr(root, @@ -1676,7 +1669,6 @@ set_foreignscan_references(PlannerInfo *root, itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL((Plan *) fscan)); fscan->fdw_recheck_quals = (List *) fix_upper_expr(root, @@ -1684,7 +1676,6 @@ set_foreignscan_references(PlannerInfo *root, itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL((Plan *) fscan)); pfree(itlist); /* fdw_scan_tlist itself just needs fix_scan_list() adjustments */ @@ -1746,7 +1737,6 @@ set_customscan_references(PlannerInfo *root, itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_TLIST((Plan *) cscan)); cscan->scan.plan.qual = (List *) fix_upper_expr(root, @@ -1754,7 +1744,6 @@ set_customscan_references(PlannerInfo *root, itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL((Plan *) cscan)); cscan->custom_exprs = (List *) fix_upper_expr(root, @@ -1762,7 +1751,6 @@ set_customscan_references(PlannerInfo *root, itlist, INDEX_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL((Plan *) cscan)); pfree(itlist); /* custom_scan_tlist itself just needs fix_scan_list() adjustments */ @@ -2039,7 +2027,6 @@ set_hash_references(PlannerInfo *root, Plan *plan, int rtoffset) outer_itlist, OUTER_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL(plan)); /* Hash doesn't project */ @@ -2447,15 +2434,14 @@ set_join_references(PlannerInfo *root, Join *join, int rtoffset) * Vars or PHVs seen in the NestLoopParam expression have * nullingrels that include exactly the outer-join relids that * appear in the outer side's output and can null the respective - * Var or PHV. So we can use exact nullingrels matches for the - * NestLoopParam expression. + * Var or PHV. Therefore, fix_upper_expr will not complain when + * performing the nullingrels matches here. */ nlp->paramval = (Var *) fix_upper_expr(root, (Node *) nlp->paramval, outer_itlist, OUTER_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_TLIST(outer_plan)); /* Check we replaced any PlaceHolderVar with simple Var */ if (!(IsA(nlp->paramval, Var) && @@ -2498,7 +2484,6 @@ set_join_references(PlannerInfo *root, Join *join, int rtoffset) outer_itlist, OUTER_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL((Plan *) join)); } @@ -2603,7 +2588,6 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset) subplan_itlist, OUTER_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_TLIST(plan)); } else @@ -2612,7 +2596,6 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset) subplan_itlist, OUTER_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_TLIST(plan)); tle = flatCopyTargetEntry(tle); tle->expr = (Expr *) newexpr; @@ -2626,7 +2609,6 @@ set_upper_references(PlannerInfo *root, Plan *plan, int rtoffset) subplan_itlist, OUTER_VAR, rtoffset, - NRM_EQUAL, NUM_EXEC_QUAL(plan)); pfree(subplan_itlist); @@ -3332,11 +3314,13 @@ fix_join_expr_mutator(Node *node, fix_join_expr_context *context) * expensive, so we don't want to try it in the common case where the * subplan tlist is just a flattened list of Vars.) * + * When cross-checking the nullingrels of the subplan output Vars/PHVs, we + * always expect exact matches. + * * 'node': the tree to be fixed (a target item or qual) * 'subplan_itlist': indexed target list for subplan (or index) * 'newvarno': varno to use for Vars referencing tlist elements * 'rtoffset': how much to increment varnos by - * 'nrm_match': as for search_indexed_tlist_for_var() * 'num_exec': estimated number of executions of expression * * The resulting tree is a copy of the original in which all Var nodes have @@ -3349,7 +3333,6 @@ fix_upper_expr(PlannerInfo *root, indexed_tlist *subplan_itlist, int newvarno, int rtoffset, - NullingRelsMatch nrm_match, double num_exec) { fix_upper_expr_context context; @@ -3358,7 +3341,6 @@ fix_upper_expr(PlannerInfo *root, context.subplan_itlist = subplan_itlist; context.newvarno = newvarno; context.rtoffset = rtoffset; - context.nrm_match = nrm_match; context.num_exec = num_exec; return fix_upper_expr_mutator(node, &context); } @@ -3378,7 +3360,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context) context->subplan_itlist, context->newvarno, context->rtoffset, - context->nrm_match); + NRM_EQUAL); if (!newvar) elog(ERROR, "variable not found in subplan target list"); return (Node *) newvar; @@ -3393,7 +3375,7 @@ fix_upper_expr_mutator(Node *node, fix_upper_expr_context *context) newvar = search_indexed_tlist_for_phv(phv, context->subplan_itlist, context->newvarno, - context->nrm_match); + NRM_EQUAL); if (newvar) return (Node *) newvar; } -- 2.39.5 (Apple Git-154)