=== Applying patches on top of PostgreSQL commit ID 990571a08b66c76be85b077ddcba419fd4524952 === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Fri Jul 11 23:05:20 UTC 2025 On branch cf/5754 nothing to commit, working tree clean === using 'git am' to apply patch ./v0-0001-Employ-EquivalenceClass-to-adjust-ndistinct-estim.patch === Applying: Employ EquivalenceClass to adjust ndistinct estimation. Using index info to reconstruct a base tree... M contrib/postgres_fdw/postgres_fdw.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/util/pathnode.c M src/backend/utils/adt/selfuncs.c M src/include/nodes/pathnodes.h M src/include/optimizer/cost.h M src/test/regress/expected/incremental_sort.out M src/test/regress/expected/stats.out M src/test/regress/sql/incremental_sort.sql M src/test/regress/sql/stats.sql Falling back to patching base and 3-way merge... Auto-merging src/test/regress/sql/stats.sql Auto-merging src/test/regress/sql/incremental_sort.sql CONFLICT (content): Merge conflict in src/test/regress/sql/incremental_sort.sql Auto-merging src/test/regress/expected/stats.out Auto-merging src/test/regress/expected/incremental_sort.out CONFLICT (content): Merge conflict in src/test/regress/expected/incremental_sort.out Auto-merging src/include/optimizer/cost.h Auto-merging src/include/nodes/pathnodes.h Auto-merging src/backend/utils/adt/selfuncs.c Auto-merging src/backend/optimizer/util/pathnode.c Auto-merging src/backend/optimizer/plan/planner.c Auto-merging src/backend/optimizer/plan/createplan.c Auto-merging src/backend/optimizer/path/costsize.c Auto-merging contrib/postgres_fdw/postgres_fdw.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 Employ EquivalenceClass to adjust ndistinct estimation. 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 contrib/postgres_fdw/postgres_fdw.c M src/backend/optimizer/path/costsize.c M src/backend/optimizer/path/equivclass.c M src/backend/optimizer/path/indxpath.c M src/backend/optimizer/plan/createplan.c M src/backend/optimizer/plan/planner.c M src/backend/optimizer/prep/prepunion.c M src/backend/optimizer/util/pathnode.c M src/backend/utils/adt/selfuncs.c M src/include/nodes/pathnodes.h M src/include/optimizer/cost.h M src/include/utils/selfuncs.h M src/test/regress/expected/incremental_sort.out M src/test/regress/expected/stats.out M src/test/regress/sql/incremental_sort.sql M src/test/regress/sql/stats.sql === using patch(1) to apply patch ./v0-0001-Employ-EquivalenceClass-to-adjust-ndistinct-estim.patch === patching file contrib/postgres_fdw/postgres_fdw.c Hunk #1 succeeded at 3388 (offset 18 lines). patching file src/backend/optimizer/path/costsize.c Hunk #4 succeeded at 2554 (offset 26 lines). Hunk #5 succeeded at 2875 (offset 26 lines). Hunk #6 succeeded at 2898 (offset 26 lines). Hunk #7 succeeded at 3678 (offset 26 lines). Hunk #8 succeeded at 6590 (offset 26 lines). patching file src/backend/optimizer/path/equivclass.c patching file src/backend/optimizer/path/indxpath.c patching file src/backend/optimizer/plan/createplan.c Hunk #1 succeeded at 5633 (offset 110 lines). patching file src/backend/optimizer/plan/planner.c Hunk #2 succeeded at 3603 (offset 3 lines). Hunk #3 succeeded at 3643 (offset 3 lines). Hunk #4 succeeded at 3670 (offset 3 lines). Hunk #5 succeeded at 3682 (offset 3 lines). Hunk #6 succeeded at 4077 (offset 3 lines). Hunk #7 succeeded at 4849 (offset 3 lines). Hunk #8 succeeded at 5020 (offset 3 lines). Hunk #9 succeeded at 7361 (offset 3 lines). patching file src/backend/optimizer/prep/prepunion.c patching file src/backend/optimizer/util/pathnode.c Hunk #1 succeeded at 1881 (offset 23 lines). Hunk #2 succeeded at 3083 (offset 23 lines). patching file src/backend/utils/adt/selfuncs.c Hunk #1 succeeded at 3443 (offset -1 lines). Hunk #2 succeeded at 3480 (offset -1 lines). Hunk #3 succeeded at 3514 (offset -1 lines). patching file src/include/nodes/pathnodes.h Hunk #1 succeeded at 1498 (offset -3 lines). Hunk #2 succeeded at 1515 (offset -3 lines). patching file src/include/optimizer/cost.h patching file src/include/utils/selfuncs.h patching file src/test/regress/expected/incremental_sort.out Hunk #1 FAILED at 1722. 1 out of 1 hunk FAILED -- saving rejects to file src/test/regress/expected/incremental_sort.out.rej patching file src/test/regress/expected/stats.out Hunk #1 succeeded at 1879 (offset 11 lines). patching file src/test/regress/sql/incremental_sort.sql Hunk #1 FAILED at 298. 1 out of 1 hunk FAILED -- saving rejects to file src/test/regress/sql/incremental_sort.sql.rej patching file src/test/regress/sql/stats.sql Hunk #1 succeeded at 930 (offset 5 lines). Unstaged changes after reset: M contrib/postgres_fdw/postgres_fdw.c M src/backend/optimizer/path/costsize.c M src/backend/optimizer/path/equivclass.c M src/backend/optimizer/path/indxpath.c M src/backend/optimizer/plan/createplan.c M src/backend/optimizer/plan/planner.c M src/backend/optimizer/prep/prepunion.c M src/backend/optimizer/util/pathnode.c M src/backend/utils/adt/selfuncs.c M src/include/nodes/pathnodes.h M src/include/optimizer/cost.h M src/include/utils/selfuncs.h M src/test/regress/expected/stats.out M src/test/regress/sql/stats.sql Removing src/test/regress/expected/incremental_sort.out.rej Removing src/test/regress/sql/incremental_sort.sql.rej === using 'git apply' to apply patch ./v0-0001-Employ-EquivalenceClass-to-adjust-ndistinct-estim.patch === Applied patch to 'contrib/postgres_fdw/postgres_fdw.c' cleanly. Applied patch to 'src/backend/optimizer/path/costsize.c' cleanly. Applied patch to 'src/backend/optimizer/path/equivclass.c' cleanly. Applied patch to 'src/backend/optimizer/path/indxpath.c' cleanly. Applied patch to 'src/backend/optimizer/plan/createplan.c' cleanly. Applied patch to 'src/backend/optimizer/plan/planner.c' cleanly. Applied patch to 'src/backend/optimizer/prep/prepunion.c' cleanly. Applied patch to 'src/backend/optimizer/util/pathnode.c' cleanly. Applied patch to 'src/backend/utils/adt/selfuncs.c' cleanly. Applied patch to 'src/include/nodes/pathnodes.h' cleanly. Applied patch to 'src/include/optimizer/cost.h' cleanly. Applied patch to 'src/include/utils/selfuncs.h' cleanly. Applied patch to 'src/test/regress/expected/incremental_sort.out' with conflicts. Applied patch to 'src/test/regress/expected/stats.out' cleanly. Applied patch to 'src/test/regress/sql/incremental_sort.sql' with conflicts. Applied patch to 'src/test/regress/sql/stats.sql' cleanly. U src/test/regress/expected/incremental_sort.out U src/test/regress/sql/incremental_sort.sql diff --cc src/test/regress/expected/incremental_sort.out index 5a1dd9fc022,b23dc13ca6f..00000000000 --- a/src/test/regress/expected/incremental_sort.out +++ b/src/test/regress/expected/incremental_sort.out @@@ -1723,42 -1723,52 +1723,94 @@@ order by t1.four, t1.two limit 1 (12 rows) -- ++<<<<<<< ours +-- Test incremental sort for Append/MergeAppend +-- +create table prt_tbl (a int, b int) partition by range (a); +create table prt_tbl_1 partition of prt_tbl for values from (0) to (100); +create table prt_tbl_2 partition of prt_tbl for values from (100) to (200); +insert into prt_tbl select i%200, i from generate_series(1,1000)i; +create index on prt_tbl_1(a); +create index on prt_tbl_2(a, b); +analyze prt_tbl; +set enable_seqscan to off; +set enable_bitmapscan to off; +-- Ensure we get an incremental sort for the subpath of Append +explain (costs off) select * from prt_tbl order by a, b; + QUERY PLAN +------------------------------------------------------------ + Append + -> Incremental Sort + Sort Key: prt_tbl_1.a, prt_tbl_1.b + Presorted Key: prt_tbl_1.a + -> Index Scan using prt_tbl_1_a_idx on prt_tbl_1 + -> Index Only Scan using prt_tbl_2_a_b_idx on prt_tbl_2 +(6 rows) + +-- Ensure we get an incremental sort for the subpath of MergeAppend +explain (costs off) select * from prt_tbl_1 union all select * from prt_tbl_2 order by a, b; + QUERY PLAN +------------------------------------------------------------ + Merge Append + Sort Key: prt_tbl_1.a, prt_tbl_1.b + -> Incremental Sort + Sort Key: prt_tbl_1.a, prt_tbl_1.b + Presorted Key: prt_tbl_1.a + -> Index Scan using prt_tbl_1_a_idx on prt_tbl_1 + -> Index Only Scan using prt_tbl_2_a_b_idx on prt_tbl_2 +(7 rows) + +reset enable_bitmapscan; +reset enable_seqscan; +drop table prt_tbl; ++======= + -- Commuting of sides in an expression doesn't influence cost estimation + -- + CREATE TABLE sort_ndist_t1 (x numeric, y numeric); + CREATE TABLE sort_ndist_t2 (x numeric, y numeric); + INSERT INTO sort_ndist_t1 (x,y) + SELECT gs%10, gs%1000 FROM generate_series(1,1E4) AS gs; + INSERT INTO sort_ndist_t2 (x,y) + SELECT gs, gs FROM generate_series(1,1E4) AS gs; + CREATE INDEX t1_idx ON sort_ndist_t1 (x); + CREATE INDEX t2_idx ON sort_ndist_t2 (x); + VACUUM ANALYZE sort_ndist_t1, sort_ndist_t2; + SET enable_hashjoin = 'off'; + -- Having lots of duplicates after the join it is more effective to use plain + -- Sort instead of incremental sort. + EXPLAIN (COSTS OFF) + SELECT t1.x, t1.y FROM sort_ndist_t1 t1, sort_ndist_t2 t2 + WHERE t1.x=t2.x + ORDER BY t1.x,t1.y; + QUERY PLAN + -------------------------------------------------------------------- + Sort + Sort Key: t1.x, t1.y + -> Nested Loop + -> Seq Scan on sort_ndist_t1 t1 + -> Memoize + Cache Key: t1.x + Cache Mode: logical + -> Index Only Scan using t2_idx on sort_ndist_t2 t2 + Index Cond: (x = t1.x) + (9 rows) + + EXPLAIN (COSTS OFF) -- the plan must be the same as above + SELECT t1.x, t1.y FROM sort_ndist_t1 t1, sort_ndist_t2 t2 + WHERE t2.x=t1.x + ORDER BY t1.x,t1.y; + QUERY PLAN + -------------------------------------------------------------------- + Sort + Sort Key: t1.x, t1.y + -> Nested Loop + -> Seq Scan on sort_ndist_t1 t1 + -> Memoize + Cache Key: t1.x + Cache Mode: logical + -> Index Only Scan using t2_idx on sort_ndist_t2 t2 + Index Cond: (x = t1.x) + (9 rows) + + RESET enable_hashjoin; ++>>>>>>> theirs diff --cc src/test/regress/sql/incremental_sort.sql index bbe658a7588,298a2782b95..00000000000 --- a/src/test/regress/sql/incremental_sort.sql +++ b/src/test/regress/sql/incremental_sort.sql @@@ -300,25 -300,30 +300,55 @@@ select * fro order by t1.four, t1.two limit 1; -- ++<<<<<<< ours +-- Test incremental sort for Append/MergeAppend +-- +create table prt_tbl (a int, b int) partition by range (a); +create table prt_tbl_1 partition of prt_tbl for values from (0) to (100); +create table prt_tbl_2 partition of prt_tbl for values from (100) to (200); +insert into prt_tbl select i%200, i from generate_series(1,1000)i; +create index on prt_tbl_1(a); +create index on prt_tbl_2(a, b); +analyze prt_tbl; + +set enable_seqscan to off; +set enable_bitmapscan to off; + +-- Ensure we get an incremental sort for the subpath of Append +explain (costs off) select * from prt_tbl order by a, b; + +-- Ensure we get an incremental sort for the subpath of MergeAppend +explain (costs off) select * from prt_tbl_1 union all select * from prt_tbl_2 order by a, b; + +reset enable_bitmapscan; +reset enable_seqscan; +drop table prt_tbl; ++======= + -- Commuting of sides in an expression doesn't influence cost estimation + -- + CREATE TABLE sort_ndist_t1 (x numeric, y numeric); + CREATE TABLE sort_ndist_t2 (x numeric, y numeric); + + INSERT INTO sort_ndist_t1 (x,y) + SELECT gs%10, gs%1000 FROM generate_series(1,1E4) AS gs; + INSERT INTO sort_ndist_t2 (x,y) + SELECT gs, gs FROM generate_series(1,1E4) AS gs; + CREATE INDEX t1_idx ON sort_ndist_t1 (x); + CREATE INDEX t2_idx ON sort_ndist_t2 (x); + VACUUM ANALYZE sort_ndist_t1, sort_ndist_t2; + + SET enable_hashjoin = 'off'; + + -- Having lots of duplicates after the join it is more effective to use plain + -- Sort instead of incremental sort. + EXPLAIN (COSTS OFF) + SELECT t1.x, t1.y FROM sort_ndist_t1 t1, sort_ndist_t2 t2 + WHERE t1.x=t2.x + ORDER BY t1.x,t1.y; + EXPLAIN (COSTS OFF) -- the plan must be the same as above + SELECT t1.x, t1.y FROM sort_ndist_t1 t1, sort_ndist_t2 t2 + WHERE t2.x=t1.x + ORDER BY t1.x,t1.y; + + RESET enable_hashjoin; ++>>>>>>> theirs