=== Applying patches on top of PostgreSQL commit ID 2c077c7d602dba034e209227ea04a14b10797c42 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Thu Nov 19 10:11:31 UTC 2026 On branch cf/7600 nothing to commit, working tree clean === using 'git am' to apply patch ./v2-0001-WIP-Supply-valid-input-Vars-for-sort-EC-selection.patch === Applying: WIP: Supply valid input Vars for sort EC selection Using index info to reconstruct a base tree... M src/backend/optimizer/path/equivclass.c M src/backend/optimizer/plan/createplan.c M src/test/regress/expected/aggregates.out M src/test/regress/sql/aggregates.sql Falling back to patching base and 3-way merge... Auto-merging src/test/regress/sql/aggregates.sql Auto-merging src/test/regress/expected/aggregates.out 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/equivclass.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 WIP: Supply valid input Vars for sort EC selection 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". === using patch(1) to apply patch ./v2-0001-WIP-Supply-valid-input-Vars-for-sort-EC-selection.patch === patching file src/backend/optimizer/path/equivclass.c patching file src/backend/optimizer/plan/createplan.c Hunk #10 FAILED at 1577. Hunk #11 FAILED at 1593. Hunk #12 succeeded at 1640 (offset 14 lines). Hunk #13 succeeded at 1652 (offset 14 lines). Hunk #14 succeeded at 1727 with fuzz 1 (offset 26 lines). Hunk #15 succeeded at 1758 (offset 26 lines). Hunk #16 succeeded at 1999 (offset 26 lines). Hunk #17 succeeded at 6342 (offset 26 lines). Hunk #18 succeeded at 6547 (offset 26 lines). Hunk #19 succeeded at 6560 (offset 26 lines). Hunk #20 succeeded at 6575 (offset 26 lines). Hunk #21 succeeded at 6591 (offset 26 lines). Hunk #22 succeeded at 6693 (offset 26 lines). Hunk #23 succeeded at 6778 (offset 26 lines). Hunk #24 succeeded at 6816 (offset 26 lines). 2 out of 24 hunks FAILED -- saving rejects to file src/backend/optimizer/plan/createplan.c.rej patching file src/include/optimizer/paths.h patching file src/test/regress/expected/aggregates.out Hunk #1 succeeded at 4079 (offset 93 lines). patching file src/test/regress/expected/partition_join.out patching file src/test/regress/sql/aggregates.sql Hunk #1 succeeded at 1842 (offset 39 lines). Unstaged changes after reset: M src/backend/optimizer/path/equivclass.c M src/backend/optimizer/plan/createplan.c M src/include/optimizer/paths.h M src/test/regress/expected/aggregates.out M src/test/regress/expected/partition_join.out M src/test/regress/sql/aggregates.sql Removing src/backend/optimizer/plan/createplan.c.rej === using 'git apply' to apply patch ./v2-0001-WIP-Supply-valid-input-Vars-for-sort-EC-selection.patch === Applied patch to 'src/backend/optimizer/path/equivclass.c' cleanly. Applied patch to 'src/backend/optimizer/plan/createplan.c' with conflicts. Applied patch to 'src/include/optimizer/paths.h' cleanly. Applied patch to 'src/test/regress/expected/aggregates.out' cleanly. Applied patch to 'src/test/regress/expected/partition_join.out' cleanly. Applied patch to 'src/test/regress/sql/aggregates.sql' cleanly. U src/backend/optimizer/plan/createplan.c diff --cc src/backend/optimizer/plan/createplan.c index bc991d31254,19e85f621f7..00000000000 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@@ -1474,15 -1577,9 +1577,10 @@@ create_merge_append_plan(PlannerInfo *r List *pathkeys = best_path->path.pathkeys; List *subplans = NIL; ListCell *subpaths; + ListCell *subplans_cell; RelOptInfo *rel = best_path->path.parent; + bool consider_async; - /* - * We don't have the actual creation of the MergeAppend node split out - * into a separate make_xxx function. This is because we want to run - * prepare_sort_from_pathkeys on it before we do so on the individual - * child plans, to make cross-checking the sort info easier. - */ copy_generic_path_info(plan, (Path *) best_path); plan->targetlist = tlist; plan->qual = NIL; @@@ -1491,41 -1588,7 +1589,45 @@@ node->apprelids = rel->relids; node->child_append_relid_sets = best_path->child_append_relid_sets; ++<<<<<<< ours + /* + * Compute sort column info, and adjust MergeAppend's tlist as needed. + * Because we pass adjust_tlist_in_place = true, we may ignore the + * function result; it must be the same plan node. However, we then need + * to detect whether any tlist entries were added. + */ + (void) prepare_sort_from_pathkeys(root, plan, pathkeys, + best_path->path.parent->relids, + NULL, + true, + &node->numCols, + &node->sortColIdx, + &node->sortOperators, + &node->collations, + &node->nullsFirst); + tlist_was_changed = (orig_tlist_length != list_length(plan->targetlist)); + + /* + * If appropriate, consider async execution of the children. Unlike a + * plain Append (which returns tuples in arrival order and hence disables + * async whenever the output must be ordered), a MergeAppend always has + * pathkeys but still preserves ordering by merging the per-child streams. + * A child is only eligible if it is directly async-capable, i.e. we don't + * have to insert a Sort node on top of it below; that is checked per + * child. + */ + consider_async = (enable_async_merge_append && + !best_path->path.parallel_safe && + list_length(best_path->subpaths) > 1); + + /* + * Now prepare the child plans. We must apply prepare_sort_from_pathkeys + * even to subplans that don't need an explicit sort, to make sure they + * are returning the same sort key columns the MergeAppend expects. + */ ++======= + /* Build and attach all children before preparing their sort inputs. */ ++>>>>>>> theirs foreach(subpaths, best_path->subpaths) { Path *subpath = (Path *) lfirst(subpaths); @@@ -1603,22 -1685,12 +1724,24 @@@ subplan = sort_plan; } + else if (consider_async) + { + /* + * The subplan is sufficiently ordered on its own, so no Sort node + * was inserted on top of it. Only in this case is the child + * still directly async-capable, so check for that here. (If a + * Sort node had been inserted, it would be the MergeAppend's + * child, and Sort nodes are not async-capable.) + */ + if (mark_async_capable_plan(subplan, subpath)) + Assert(subplan->async_capable); + } - subplans = lappend(subplans, subplan); + lfirst(subplans_cell) = subplan; } + tlist_was_changed = (orig_tlist_length != list_length(plan->targetlist)); + /* Set below if we find quals that we can use to run-time prune */ node->part_prune_index = -1;