=== Applying patches on top of PostgreSQL commit ID 23c07b4604387b98efd25246b185b57be237d7ca === /etc/rc.d/jail: WARNING: Per-jail configuration via jail_* variables is obsolete. Please consider migrating to /etc/jail.conf. Tue Sep 8 00:14:26 UTC 2026 On branch cf/6923 nothing to commit, working tree clean === using 'git am' to apply patch ./v1-0001-FK-RI-Add-heavy-weight-locking-option-for-RI-chec.patch === Applying: FK-RI: Add heavy-weight locking option for RI checks .git/rebase-apply/patch:389: trailing whitespace. * locked by the RowExclusive lock on the backing index .git/rebase-apply/patch:410: trailing whitespace. * locked by the RowExclusive lock on the backing index .git/rebase-apply/patch:452: trailing whitespace. * locked by the RowExclusive lock on the backing index .git/rebase-apply/patch:558: trailing whitespace. * We do need to take a predicate lock on the heap page, though, warning: 4 lines add whitespace errors. Using index info to reconstruct a base tree... M doc/src/sgml/ref/alter_table.sgml M src/backend/catalog/heap.c M src/backend/catalog/index.c M src/backend/catalog/pg_constraint.c M src/backend/commands/tablecmds.c M src/backend/commands/trigger.c M src/backend/commands/typecmds.c M src/backend/parser/gram.y M src/backend/utils/adt/ri_triggers.c M src/backend/utils/adt/ruleutils.c M src/include/nodes/parsenodes.h M src/test/isolation/isolation_schedule Falling back to patching base and 3-way merge... Auto-merging src/test/isolation/isolation_schedule CONFLICT (content): Merge conflict in src/test/isolation/isolation_schedule Auto-merging src/include/nodes/parsenodes.h Auto-merging src/backend/utils/adt/ruleutils.c Auto-merging src/backend/utils/adt/ri_triggers.c CONFLICT (content): Merge conflict in src/backend/utils/adt/ri_triggers.c Auto-merging src/backend/parser/gram.y Auto-merging src/backend/commands/typecmds.c Auto-merging src/backend/commands/trigger.c Auto-merging src/backend/commands/tablecmds.c Auto-merging src/backend/catalog/pg_constraint.c Auto-merging src/backend/catalog/index.c Auto-merging src/backend/catalog/heap.c Auto-merging doc/src/sgml/ref/alter_table.sgml error: Failed to merge in the changes. hint: Use 'git am --show-current-patch=diff' to see the failed patch Patch failed at 0001 FK-RI: Add heavy-weight locking option for RI checks 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 ./v1-0001-FK-RI-Add-heavy-weight-locking-option-for-RI-chec.patch === patching file doc/src/sgml/ref/alter_table.sgml Hunk #1 succeeded at 107 (offset -6 lines). Hunk #2 succeeded at 120 (offset -6 lines). patching file doc/src/sgml/ref/create_table.sgml patching file src/backend/catalog/heap.c Hunk #1 succeeded at 2249 (offset 1 line). Hunk #2 succeeded at 2304 (offset 1 line). patching file src/backend/catalog/index.c Hunk #1 succeeded at 2009 (offset 15 lines). patching file src/backend/catalog/pg_constraint.c Hunk #1 succeeded at 73 (offset 3 lines). Hunk #2 succeeded at 204 (offset 3 lines). patching file src/backend/commands/tablecmds.c Hunk #1 succeeded at 10893 (offset 9 lines). Hunk #2 succeeded at 11446 (offset 9 lines). Hunk #3 succeeded at 11710 (offset 9 lines). Hunk #4 succeeded at 11851 (offset 9 lines). Hunk #5 succeeded at 12580 (offset 9 lines). Hunk #6 succeeded at 21987 (offset 435 lines). patching file src/backend/commands/trigger.c Hunk #1 succeeded at 843 (offset 12 lines). patching file src/backend/commands/typecmds.c Hunk #1 succeeded at 3675 (offset 16 lines). Hunk #2 succeeded at 3784 (offset 16 lines). patching file src/backend/parser/gram.y Hunk #1 succeeded at 607 (offset -3 lines). Hunk #2 succeeded at 4147 (offset -75 lines). Hunk #3 succeeded at 4156 (offset -75 lines). Hunk #4 succeeded at 4418 (offset -75 lines). Hunk #5 succeeded at 4437 (offset -75 lines). Hunk #6 succeeded at 4545 (offset -75 lines). patching file src/backend/utils/adt/ri_triggers.c Hunk #1 succeeded at 43 (offset 1 line). Hunk #2 succeeded at 59 (offset 2 lines). Hunk #3 succeeded at 101 (offset 2 lines). Hunk #4 succeeded at 128 (offset 2 lines). Hunk #5 succeeded at 512 (offset 57 lines). Hunk #6 succeeded at 602 (offset 67 lines). Hunk #7 succeeded at 642 (offset 67 lines). Hunk #8 succeeded at 778 (offset 67 lines). Hunk #9 succeeded at 816 (offset 67 lines). Hunk #10 succeeded at 958 (offset 67 lines). Hunk #11 succeeded at 1060 (offset 67 lines). Hunk #12 succeeded at 1113 (offset 67 lines). Hunk #13 succeeded at 1125 (offset 67 lines). Hunk #14 succeeded at 1184 (offset 67 lines). Hunk #15 succeeded at 1301 (offset 67 lines). Hunk #16 succeeded at 1485 (offset 67 lines). Hunk #17 succeeded at 2600 (offset 67 lines). Hunk #18 FAILED at 3206. Hunk #19 succeeded at 3441 (offset 165 lines). 1 out of 19 hunks FAILED -- saving rejects to file src/backend/utils/adt/ri_triggers.c.rej patching file src/backend/utils/adt/ruleutils.c Hunk #1 succeeded at 2297 (offset -353 lines). patching file src/include/catalog/pg_constraint.h patching file src/include/nodes/parsenodes.h Hunk #1 succeeded at 2932 (offset -46 lines). patching file src/test/isolation/expected/fk-lock-key-index-no-conflicts.out patching file src/test/isolation/expected/fk-lock-key-index-with-conflicts.out patching file src/test/isolation/isolation_schedule Hunk #1 FAILED at 38. 1 out of 1 hunk FAILED -- saving rejects to file src/test/isolation/isolation_schedule.rej patching file src/test/isolation/specs/fk-lock-key-index-no-conflicts.spec patching file src/test/isolation/specs/fk-lock-key-index-with-conflicts.spec Unstaged changes after reset: M doc/src/sgml/ref/alter_table.sgml M doc/src/sgml/ref/create_table.sgml M src/backend/catalog/heap.c M src/backend/catalog/index.c M src/backend/catalog/pg_constraint.c M src/backend/commands/tablecmds.c M src/backend/commands/trigger.c M src/backend/commands/typecmds.c M src/backend/parser/gram.y M src/backend/utils/adt/ri_triggers.c M src/backend/utils/adt/ruleutils.c M src/include/catalog/pg_constraint.h M src/include/nodes/parsenodes.h Removing src/backend/utils/adt/ri_triggers.c.rej Removing src/test/isolation/expected/fk-lock-key-index-no-conflicts.out Removing src/test/isolation/expected/fk-lock-key-index-with-conflicts.out Removing src/test/isolation/isolation_schedule.rej Removing src/test/isolation/specs/fk-lock-key-index-no-conflicts.spec Removing src/test/isolation/specs/fk-lock-key-index-with-conflicts.spec === using 'git apply' to apply patch ./v1-0001-FK-RI-Add-heavy-weight-locking-option-for-RI-chec.patch === /work/patches/./v1-0001-FK-RI-Add-heavy-weight-locking-option-for-RI-chec.patch:398: trailing whitespace. * locked by the RowExclusive lock on the backing index /work/patches/./v1-0001-FK-RI-Add-heavy-weight-locking-option-for-RI-chec.patch:419: trailing whitespace. * locked by the RowExclusive lock on the backing index /work/patches/./v1-0001-FK-RI-Add-heavy-weight-locking-option-for-RI-chec.patch:461: trailing whitespace. * locked by the RowExclusive lock on the backing index /work/patches/./v1-0001-FK-RI-Add-heavy-weight-locking-option-for-RI-chec.patch:567: trailing whitespace. * We do need to take a predicate lock on the heap page, though, Applied patch to 'doc/src/sgml/ref/alter_table.sgml' cleanly. Applied patch to 'doc/src/sgml/ref/create_table.sgml' cleanly. Applied patch to 'src/backend/catalog/heap.c' cleanly. Applied patch to 'src/backend/catalog/index.c' cleanly. Applied patch to 'src/backend/catalog/pg_constraint.c' cleanly. Applied patch to 'src/backend/commands/tablecmds.c' cleanly. Applied patch to 'src/backend/commands/trigger.c' cleanly. Applied patch to 'src/backend/commands/typecmds.c' cleanly. Applied patch to 'src/backend/parser/gram.y' cleanly. Applied patch to 'src/backend/utils/adt/ri_triggers.c' with conflicts. Applied patch to 'src/backend/utils/adt/ruleutils.c' cleanly. Applied patch to 'src/include/catalog/pg_constraint.h' cleanly. Applied patch to 'src/include/nodes/parsenodes.h' cleanly. Falling back to direct application... Falling back to direct application... Applied patch to 'src/test/isolation/isolation_schedule' with conflicts. Falling back to direct application... Falling back to direct application... U src/backend/utils/adt/ri_triggers.c U src/test/isolation/isolation_schedule warning: 4 lines add whitespace errors. diff --cc src/backend/utils/adt/ri_triggers.c index d4545618634,1633714fa9a..00000000000 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@@ -3281,33 -3203,48 +3366,74 @@@ ri_FastPathFlushArray(RI_FastPathEntry { Datum found_val; bool found_null; - bool concurrently_updated; - ScanKeyData recheck_skey[1]; /* ++<<<<<<< ours + * No key recheck is needed here, so we have no use for + * concurrently_updated. Unlike ri_FastPathProbeOne(), which takes + * the index scan's word for it that the tuple matches, this path + * compares the key against every buffered FK value below, and it does + * so using found_val, which is read out of the version we actually + * locked. A concurrent key update is therefore caught by that + * comparison: the batch item that led us to this tuple is left + * unmatched and reported as a violation. + */ + if (!ri_LockPKTuple(pk_rel, pk_slot, snapshot, NULL)) + continue; + + /* + * Extract the PK value from the matched and locked tuple. + * + * A foreign key may reference a nullable unique column, not just a + * NOT NULL primary key. If ri_LockPKTuple() chased an update chain + * to a version whose referenced key is now NULL, that version cannot + * equal any buffered (non-null) FK value, so skip it. This mirrors + * the SPI path, where the requalifying "pkatt = $n" yields NULL and + * the row is not returned. + */ + found_val = slot_getattr(pk_slot, riinfo->pk_attnums[0], &found_null); + if (found_null) + continue; ++======= + * If the FK is configured to lock the index (with conflockkeyindex), + * then we don't need to lock tuples nor check for concurrent + * updates, as those would've had to lock the index to be effective. + * We do need to take a predicate lock on the heap page, though, + */ + if (riinfo->conflockkeyindex) + { + /* nothing to do */ + } + else + { + if (!ri_LockPKTuple(pk_rel, pk_slot, snapshot, + &concurrently_updated)) + continue; + + /* Extract the PK value from the matched and locked tuple */ + found_val = slot_getattr(pk_slot, riinfo->pk_attnums[0], + &found_null); + Assert(!found_null); + + if (concurrently_updated) + { + /* + * Build a single-key scankey for recheck. We need the actual PK + * value that was found, not the FK search value. + */ + ScanKeyEntryInitialize(&recheck_skey[0], 0, 1, + fpmeta->strats[0], + fpmeta->subtypes[0], + idx_rel->rd_indcollation[0], + fpmeta->regops[0], + found_val); + + if (!recheck_matched_pk_tuple(idx_rel, recheck_skey, 1, + pk_slot)) + continue; + } + } ++>>>>>>> theirs /* * Linear scan to mark all batch items matching this PK value. diff --cc src/test/isolation/isolation_schedule index 1fcf4e63238,b9a63a23e2c..00000000000 --- a/src/test/isolation/isolation_schedule +++ b/src/test/isolation/isolation_schedule @@@ -39,7 -38,8 +39,12 @@@ test: fk-snapsho test: fk-snapshot-2 test: fk-snapshot-3 test: fk-concurrent-pk-upd ++<<<<<<< ours +test: fk-fastpath-null-key ++======= + test: fk-lock-key-index-no-conflicts + test: fk-lock-key-index-with-conflicts ++>>>>>>> theirs test: subxid-overflow test: eval-plan-qual test: eval-plan-qual-trigger