=== Applying patches on top of PostgreSQL commit ID 5092aae431e3e1a20324ea3a42a181c63f703d0d === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Sat Oct 4 00:41:22 UTC 2025 On branch cf/5595 nothing to commit, working tree clean === using 'git am' to apply patch ./0001-Store-working-memory-limit-per-Plan-SubPlan-rather-t.patch === Applying: Store working memory limit per Plan/SubPlan, rather than in GUC Using index info to reconstruct a base tree... M src/backend/executor/execGrouping.c M src/backend/executor/execMain.c M src/backend/executor/nodeAgg.c M src/backend/executor/nodeHash.c M src/backend/executor/nodeSubplan.c M src/backend/executor/nodeWindowAgg.c M src/backend/optimizer/path/costsize.c M src/backend/optimizer/plan/createplan.c M src/backend/optimizer/plan/planner.c M src/backend/optimizer/plan/subselect.c M src/include/executor/executor.h M src/include/nodes/execnodes.h M src/include/nodes/pathnodes.h M src/include/nodes/plannodes.h M src/include/nodes/primnodes.h Falling back to patching base and 3-way merge... Auto-merging src/include/nodes/primnodes.h Auto-merging src/include/nodes/plannodes.h Auto-merging src/include/nodes/pathnodes.h Auto-merging src/include/nodes/execnodes.h Auto-merging src/include/executor/executor.h Auto-merging src/backend/optimizer/plan/subselect.c Auto-merging src/backend/optimizer/plan/planner.c Auto-merging src/backend/optimizer/plan/createplan.c CONFLICT (content): Merge conflict in src/backend/optimizer/plan/createplan.c Auto-merging src/backend/optimizer/path/costsize.c Auto-merging src/backend/executor/nodeWindowAgg.c Auto-merging src/backend/executor/nodeSubplan.c Auto-merging src/backend/executor/nodeHash.c Auto-merging src/backend/executor/nodeAgg.c Auto-merging src/backend/executor/execMain.c Auto-merging src/backend/executor/execGrouping.c error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 Store working memory limit per Plan/SubPlan, rather than in GUC When you have resolved this problem, run "git am --continue". If you prefer to skip this patch, run "git am --skip" instead. To restore the original branch and stop patching, run "git am --abort". Unstaged changes after reset: M src/backend/executor/Makefile M src/backend/executor/execGrouping.c M src/backend/executor/execMain.c M src/backend/executor/execParallel.c M src/backend/executor/execSRF.c M src/backend/executor/meson.build M src/backend/executor/nodeAgg.c M src/backend/executor/nodeBitmapIndexscan.c M src/backend/executor/nodeBitmapOr.c M src/backend/executor/nodeCtescan.c M src/backend/executor/nodeFunctionscan.c M src/backend/executor/nodeHash.c M src/backend/executor/nodeIncrementalSort.c M src/backend/executor/nodeMaterial.c M src/backend/executor/nodeMemoize.c M src/backend/executor/nodeRecursiveunion.c M src/backend/executor/nodeSetOp.c M src/backend/executor/nodeSort.c M src/backend/executor/nodeSubplan.c M src/backend/executor/nodeTableFuncscan.c M src/backend/executor/nodeWindowAgg.c M src/backend/optimizer/path/costsize.c M src/backend/optimizer/plan/createplan.c M src/backend/optimizer/plan/planner.c M src/backend/optimizer/plan/subselect.c M src/include/executor/executor.h M src/include/executor/hashjoin.h M src/include/executor/nodeAgg.h M src/include/executor/nodeHash.h M src/include/nodes/execnodes.h M src/include/nodes/pathnodes.h M src/include/nodes/plannodes.h M src/include/nodes/primnodes.h M src/include/optimizer/planmain.h Removing src/backend/executor/execWorkmem.c === using patch(1) to apply patch ./0001-Store-working-memory-limit-per-Plan-SubPlan-rather-t.patch === patching file src/backend/executor/Makefile patching file src/backend/executor/execGrouping.c Hunk #1 succeeded at 174 (offset 6 lines). Hunk #2 succeeded at 182 (offset 6 lines). Hunk #3 succeeded at 190 (offset 6 lines). patching file src/backend/executor/execMain.c Hunk #1 succeeded at 948 (offset -1 lines). patching file src/backend/executor/execParallel.c patching file src/backend/executor/execSRF.c patching file src/backend/executor/execWorkmem.c patching file src/backend/executor/meson.build patching file src/backend/executor/nodeAgg.c Hunk #2 succeeded at 403 (offset -1 lines). Hunk #3 succeeded at 413 (offset -1 lines). Hunk #4 succeeded at 436 (offset -1 lines). Hunk #5 succeeded at 524 (offset -1 lines). Hunk #6 succeeded at 540 (offset -1 lines). Hunk #7 succeeded at 596 (offset -1 lines). Hunk #8 succeeded at 605 (offset -1 lines). Hunk #9 succeeded at 626 (offset -1 lines). Hunk #10 succeeded at 636 (offset -1 lines). Hunk #11 succeeded at 1515 (offset -1 lines). Hunk #12 succeeded at 1525 (offset -1 lines). Hunk #13 succeeded at 1555 (offset -1 lines). Hunk #14 succeeded at 1828 (offset -1 lines). Hunk #15 succeeded at 1852 (offset -1 lines). Hunk #16 succeeded at 1953 (offset -1 lines). Hunk #17 succeeded at 2103 (offset -1 lines). Hunk #18 succeeded at 2241 (offset -1 lines). Hunk #19 succeeded at 2716 (offset -1 lines). Hunk #20 succeeded at 2808 (offset -1 lines). Hunk #21 succeeded at 3008 (offset -1 lines). Hunk #22 succeeded at 3740 (offset -1 lines). patching file src/backend/executor/nodeBitmapIndexscan.c patching file src/backend/executor/nodeBitmapOr.c patching file src/backend/executor/nodeCtescan.c patching file src/backend/executor/nodeFunctionscan.c patching file src/backend/executor/nodeHash.c Hunk #1 succeeded at 447 (offset -1 lines). Hunk #2 succeeded at 471 (offset -1 lines). Hunk #3 succeeded at 603 (offset -1 lines). Hunk #4 succeeded at 663 (offset -1 lines). Hunk #5 succeeded at 693 (offset -1 lines). Hunk #6 succeeded at 712 (offset -1 lines). Hunk #7 succeeded at 814 (offset -1 lines). Hunk #8 succeeded at 936 (offset -1 lines). Hunk #9 succeeded at 1242 (offset -1 lines). patching file src/backend/executor/nodeIncrementalSort.c patching file src/backend/executor/nodeMaterial.c patching file src/backend/executor/nodeMemoize.c patching file src/backend/executor/nodeRecursiveunion.c patching file src/backend/executor/nodeSetOp.c patching file src/backend/executor/nodeSort.c patching file src/backend/executor/nodeSubplan.c Hunk #1 succeeded at 517 (offset -19 lines). Hunk #2 FAILED at 552. Hunk #3 succeeded at 552 (offset -19 lines). Hunk #4 FAILED at 587. 2 out of 4 hunks FAILED -- saving rejects to file src/backend/executor/nodeSubplan.c.rej patching file src/backend/executor/nodeTableFuncscan.c patching file src/backend/executor/nodeWindowAgg.c Hunk #1 succeeded at 1130 (offset 38 lines). patching file src/backend/optimizer/path/costsize.c Hunk #3 succeeded at 4260 (offset 2 lines). Hunk #4 succeeded at 4603 (offset 17 lines). patching file src/backend/optimizer/plan/createplan.c Hunk #1 succeeded at 1697 (offset -9 lines). Hunk #2 succeeded at 1754 (offset -9 lines). Hunk #3 FAILED at 1911. Hunk #4 succeeded at 2191 (offset -66 lines). Hunk #5 succeeded at 2460 with fuzz 2 (offset 175 lines). Hunk #6 succeeded at 2557 (offset 159 lines). Hunk #7 FAILED at 2457. Hunk #8 FAILED at 2522. Hunk #9 FAILED at 2545. Hunk #10 FAILED at 2568. Hunk #11 FAILED at 2600. Hunk #12 succeeded at 2757 (offset -7 lines). Hunk #13 succeeded at 3390 with fuzz 2 (offset 584 lines). Hunk #14 FAILED at 2844. Hunk #15 FAILED at 3550. Hunk #16 succeeded at 3975 (offset 118 lines). Hunk #17 succeeded at 4132 with fuzz 2 (offset 230 lines). Hunk #18 FAILED at 4042. Hunk #19 succeeded at 4544 (offset -200 lines). Hunk #20 succeeded at 4891 (offset -200 lines). Hunk #21 succeeded at 5446 (offset -200 lines). Hunk #22 succeeded at 5479 (offset -200 lines). Hunk #23 succeeded at 6532 (offset -200 lines). Hunk #24 succeeded at 6578 (offset -200 lines). Hunk #25 succeeded at 7349 (offset -196 lines). 9 out of 25 hunks FAILED -- saving rejects to file src/backend/optimizer/plan/createplan.c.rej patching file src/backend/optimizer/plan/planner.c Hunk #1 succeeded at 454 (offset 7 lines). Hunk #2 succeeded at 591 (offset 7 lines). patching file src/backend/optimizer/plan/subselect.c patching file src/include/executor/executor.h Hunk #2 succeeded at 562 (offset 2 lines). Hunk #3 succeeded at 800 (offset 2 lines). patching file src/include/executor/hashjoin.h patching file src/include/executor/nodeAgg.h patching file src/include/executor/nodeHash.h patching file src/include/nodes/execnodes.h Hunk #1 succeeded at 1271 (offset -5 lines). patching file src/include/nodes/pathnodes.h patching file src/include/nodes/plannodes.h Hunk #3 succeeded at 481 (offset 22 lines). Hunk #4 succeeded at 1213 (offset 22 lines). Hunk #5 succeeded at 1832 (offset 22 lines). patching file src/include/nodes/primnodes.h Hunk #1 succeeded at 1124 (offset 13 lines). patching file src/include/optimizer/planmain.h Unstaged changes after reset: M src/backend/executor/Makefile M src/backend/executor/execGrouping.c M src/backend/executor/execMain.c M src/backend/executor/execParallel.c M src/backend/executor/execSRF.c M src/backend/executor/meson.build M src/backend/executor/nodeAgg.c M src/backend/executor/nodeBitmapIndexscan.c M src/backend/executor/nodeBitmapOr.c M src/backend/executor/nodeCtescan.c M src/backend/executor/nodeFunctionscan.c M src/backend/executor/nodeHash.c M src/backend/executor/nodeIncrementalSort.c M src/backend/executor/nodeMaterial.c M src/backend/executor/nodeMemoize.c M src/backend/executor/nodeRecursiveunion.c M src/backend/executor/nodeSetOp.c M src/backend/executor/nodeSort.c M src/backend/executor/nodeSubplan.c M src/backend/executor/nodeTableFuncscan.c M src/backend/executor/nodeWindowAgg.c M src/backend/optimizer/path/costsize.c M src/backend/optimizer/plan/createplan.c M src/backend/optimizer/plan/planner.c M src/backend/optimizer/plan/subselect.c M src/include/executor/executor.h M src/include/executor/hashjoin.h M src/include/executor/nodeAgg.h M src/include/executor/nodeHash.h M src/include/nodes/execnodes.h M src/include/nodes/pathnodes.h M src/include/nodes/plannodes.h M src/include/nodes/primnodes.h M src/include/optimizer/planmain.h Removing src/backend/executor/execWorkmem.c Removing src/backend/executor/nodeSubplan.c.rej Removing src/backend/optimizer/plan/createplan.c.rej === using 'git apply' to apply patch ./0001-Store-working-memory-limit-per-Plan-SubPlan-rather-t.patch === Applied patch to 'src/backend/executor/Makefile' cleanly. Applied patch to 'src/backend/executor/execGrouping.c' cleanly. Applied patch to 'src/backend/executor/execMain.c' cleanly. Applied patch to 'src/backend/executor/execParallel.c' cleanly. Applied patch to 'src/backend/executor/execSRF.c' cleanly. Falling back to direct application... Applied patch to 'src/backend/executor/meson.build' cleanly. Applied patch to 'src/backend/executor/nodeAgg.c' cleanly. Applied patch to 'src/backend/executor/nodeBitmapIndexscan.c' cleanly. Applied patch to 'src/backend/executor/nodeBitmapOr.c' cleanly. Applied patch to 'src/backend/executor/nodeCtescan.c' cleanly. Applied patch to 'src/backend/executor/nodeFunctionscan.c' cleanly. Applied patch to 'src/backend/executor/nodeHash.c' cleanly. Applied patch to 'src/backend/executor/nodeIncrementalSort.c' cleanly. Applied patch to 'src/backend/executor/nodeMaterial.c' cleanly. Applied patch to 'src/backend/executor/nodeMemoize.c' cleanly. Applied patch to 'src/backend/executor/nodeRecursiveunion.c' cleanly. Applied patch to 'src/backend/executor/nodeSetOp.c' cleanly. Applied patch to 'src/backend/executor/nodeSort.c' cleanly. Applied patch to 'src/backend/executor/nodeSubplan.c' cleanly. Applied patch to 'src/backend/executor/nodeTableFuncscan.c' cleanly. Applied patch to 'src/backend/executor/nodeWindowAgg.c' cleanly. Applied patch to 'src/backend/optimizer/path/costsize.c' cleanly. Applied patch to 'src/backend/optimizer/plan/createplan.c' with conflicts. Applied patch to 'src/backend/optimizer/plan/planner.c' cleanly. Applied patch to 'src/backend/optimizer/plan/subselect.c' cleanly. Applied patch to 'src/include/executor/executor.h' cleanly. Applied patch to 'src/include/executor/hashjoin.h' cleanly. Applied patch to 'src/include/executor/nodeAgg.h' cleanly. Applied patch to 'src/include/executor/nodeHash.h' cleanly. Applied patch to 'src/include/nodes/execnodes.h' cleanly. Applied patch to 'src/include/nodes/pathnodes.h' cleanly. Applied patch to 'src/include/nodes/plannodes.h' cleanly. Applied patch to 'src/include/nodes/primnodes.h' cleanly. Applied patch to 'src/include/optimizer/planmain.h' cleanly. U src/backend/optimizer/plan/createplan.c diff --cc src/backend/optimizer/plan/createplan.c index c9dba7ff346,22834fe37f4..00000000000 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@@ -1756,6 -1769,209 +1760,212 @@@ create_memoize_plan(PlannerInfo *root, } /* ++<<<<<<< ours ++======= + * create_unique_plan + * Create a Unique plan for 'best_path' and (recursively) plans + * for its subpaths. + * + * Returns a Plan node. + */ + static Plan * + create_unique_plan(PlannerInfo *root, UniquePath *best_path, int flags) + { + Plan *plan; + Plan *subplan; + List *in_operators; + List *uniq_exprs; + List *newtlist; + int nextresno; + bool newitems; + int numGroupCols; + AttrNumber *groupColIdx; + Oid *groupCollations; + int groupColPos; + ListCell *l; + + /* Unique doesn't project, so tlist requirements pass through */ + subplan = create_plan_recurse(root, best_path->subpath, flags); + + /* Done if we don't need to do any actual unique-ifying */ + if (best_path->umethod == UNIQUE_PATH_NOOP) + return subplan; + + /* + * As constructed, the subplan has a "flat" tlist containing just the Vars + * needed here and at upper levels. The values we are supposed to + * unique-ify may be expressions in these variables. We have to add any + * such expressions to the subplan's tlist. + * + * The subplan may have a "physical" tlist if it is a simple scan plan. If + * we're going to sort, this should be reduced to the regular tlist, so + * that we don't sort more data than we need to. For hashing, the tlist + * should be left as-is if we don't need to add any expressions; but if we + * do have to add expressions, then a projection step will be needed at + * runtime anyway, so we may as well remove unneeded items. Therefore + * newtlist starts from build_path_tlist() not just a copy of the + * subplan's tlist; and we don't install it into the subplan unless we are + * sorting or stuff has to be added. + */ + in_operators = best_path->in_operators; + uniq_exprs = best_path->uniq_exprs; + + /* initialize modified subplan tlist as just the "required" vars */ + newtlist = build_path_tlist(root, &best_path->path); + nextresno = list_length(newtlist) + 1; + newitems = false; + + foreach(l, uniq_exprs) + { + Expr *uniqexpr = lfirst(l); + TargetEntry *tle; + + tle = tlist_member(uniqexpr, newtlist); + if (!tle) + { + tle = makeTargetEntry((Expr *) uniqexpr, + nextresno, + NULL, + false); + newtlist = lappend(newtlist, tle); + nextresno++; + newitems = true; + } + } + + /* Use change_plan_targetlist in case we need to insert a Result node */ + if (newitems || best_path->umethod == UNIQUE_PATH_SORT) + subplan = change_plan_targetlist(subplan, newtlist, + best_path->path.parallel_safe); + + /* + * Build control information showing which subplan output columns are to + * be examined by the grouping step. Unfortunately we can't merge this + * with the previous loop, since we didn't then know which version of the + * subplan tlist we'd end up using. + */ + newtlist = subplan->targetlist; + numGroupCols = list_length(uniq_exprs); + groupColIdx = (AttrNumber *) palloc(numGroupCols * sizeof(AttrNumber)); + groupCollations = (Oid *) palloc(numGroupCols * sizeof(Oid)); + + groupColPos = 0; + foreach(l, uniq_exprs) + { + Expr *uniqexpr = lfirst(l); + TargetEntry *tle; + + tle = tlist_member(uniqexpr, newtlist); + if (!tle) /* shouldn't happen */ + elog(ERROR, "failed to find unique expression in subplan tlist"); + groupColIdx[groupColPos] = tle->resno; + groupCollations[groupColPos] = exprCollation((Node *) tle->expr); + groupColPos++; + } + + if (best_path->umethod == UNIQUE_PATH_HASH) + { + Oid *groupOperators; + + /* + * Get the hashable equality operators for the Agg node to use. + * Normally these are the same as the IN clause operators, but if + * those are cross-type operators then the equality operators are the + * ones for the IN clause operators' RHS datatype. + */ + groupOperators = (Oid *) palloc(numGroupCols * sizeof(Oid)); + groupColPos = 0; + foreach(l, in_operators) + { + Oid in_oper = lfirst_oid(l); + Oid eq_oper; + + if (!get_compatible_hash_operators(in_oper, NULL, &eq_oper)) + elog(ERROR, "could not find compatible hash operator for operator %u", + in_oper); + groupOperators[groupColPos++] = eq_oper; + } + + /* + * Since the Agg node is going to project anyway, we can give it the + * minimum output tlist, without any stuff we might have added to the + * subplan tlist. + */ + plan = (Plan *) make_agg(build_path_tlist(root, &best_path->path), + NIL, + AGG_HASHED, + AGGSPLIT_SIMPLE, + numGroupCols, + groupColIdx, + groupOperators, + groupCollations, + NIL, + NIL, + best_path->path.rows, + 0, + subplan); + + plan->workmem_id = add_hash_workmem(root->glob); + } + else + { + List *sortList = NIL; + Sort *sort; + + /* Create an ORDER BY list to sort the input compatibly */ + groupColPos = 0; + foreach(l, in_operators) + { + Oid in_oper = lfirst_oid(l); + Oid sortop; + Oid eqop; + TargetEntry *tle; + SortGroupClause *sortcl; + + sortop = get_ordering_op_for_equality_op(in_oper, false); + if (!OidIsValid(sortop)) /* shouldn't happen */ + elog(ERROR, "could not find ordering operator for equality operator %u", + in_oper); + + /* + * The Unique node will need equality operators. Normally these + * are the same as the IN clause operators, but if those are + * cross-type operators then the equality operators are the ones + * for the IN clause operators' RHS datatype. + */ + eqop = get_equality_op_for_ordering_op(sortop, NULL); + if (!OidIsValid(eqop)) /* shouldn't happen */ + elog(ERROR, "could not find equality operator for ordering operator %u", + sortop); + + tle = get_tle_by_resno(subplan->targetlist, + groupColIdx[groupColPos]); + Assert(tle != NULL); + + sortcl = makeNode(SortGroupClause); + sortcl->tleSortGroupRef = assignSortGroupRef(tle, + subplan->targetlist); + sortcl->eqop = eqop; + sortcl->sortop = sortop; + sortcl->reverse_sort = false; + sortcl->nulls_first = false; + sortcl->hashable = false; /* no need to make this accurate */ + sortList = lappend(sortList, sortcl); + groupColPos++; + } + sort = make_sort_from_sortclauses(sortList, subplan); + label_sort_with_costsize(root, sort, -1.0); + plan = (Plan *) make_unique_from_sortclauses((Plan *) sort, sortList); + } + + /* Copy cost data from Path to Plan */ + copy_generic_path_info(plan, &best_path->path); + + return plan; + } + + /* ++>>>>>>> theirs * create_gather_plan * * Create a Gather plan for 'best_path' and (recursively) plans