Re: PG19: two RI fast-path issues found while testing the batching revert

Поиск
Список
Период
Сортировка
Искать

Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
Вложения:
Hi Nik,

On Fri, Sep 11, 2026 at 1:02 AM Nikolay Samokhvalov  wrote:
>
> Hi hackers,
>
> After talking to Andrey Borodin yesterday, we thought it would be
> useful to check for remaining issues after the RI batching revert. I
> used the harness I'm building for general testing of new Postgres
> features. It found no issues caused by the revert itself, but found
> these two apparently pre-existing bugs that I think should be fixed.
>
> I haven't had time to verify the findings myself or fully read the
> output. This is the first time I'm sending a report without doing
> that. I still think it's useful given the circumstances, and my
> confidence is fairly high: the harness is designed to look for false
> positives and try to refute its findings.

Thanks for doing this.

> Both reproducers were run against compiled REL_19_STABLE at
> 5dec175fb4, with and without the v5 batching-removal series.
>
> Column-level SELECT rejected by the FK fast path
>
> Run as superuser:
>
> begin;
> create role fk_owner;
> create schema fk_test authorization fk_owner;
> set role fk_owner;
> set search_path = fk_test, pg_catalog;
>
> create table p (id int primary key, payload text);
> insert into p values (1, 'x');
> create table f (id int references p);
>
> revoke select on p from fk_owner;
> grant select (id) on p to fk_owner;
>
> select 1 from p where id = 1 for key share; -- succeeds
> insert into f values (1);
> -- ERROR: permission denied for table p
> rollback;
>
> The referenced-table owner has SELECT on the key column. The
> partitioned-parent SPI path accepts the same grants, but
> ri_CheckPermissions() checks only table-level SELECT.
>
> FK insert uses a dropped cast function
>
> Run in one session:
>
> begin;
> create schema cast_test;
> set local search_path = cast_test, pg_catalog;
>
> create type k as (v int);
> create function cast1(k) returns int
>   language sql immutable strict as 'select $1.v';
> create cast (k as int) with function cast1(k) as implicit;
>
> create table p (id int primary key);
> create table f (id k references p);
> insert into p values (1);
> insert into f values (row(1)::k);
>
> drop cast (k as int);
> create function cast2(k) returns int
>   language sql immutable strict as 'select $1.v';
> create cast (k as int) with function cast2(k) as implicit;
> drop function cast1(k);
>
> select row(1)::k::int; -- returns 1
> insert into f values (row(1)::k);
> -- ERROR: cache lookup failed for function 
> rollback;
>
> Both cast functions have identical behavior, and the DDL succeeds
> without cascade. Looks like the RI cast cache isn't invalidated.

Looking at these now.  The first issue is clearly a fast-path code
problem. The 2nd one interacts with the existing non-fast-path code so
I'll need to check if the bug predates fast-path.

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Nikolay Samokhvalov <nik@postgres.ai>
Дата:
Вложения:
On Sat, Sep 12, 2026 at 8:04 AM Nikolay Samokhvalov  wrote:
> I'd keep the dead list for now. No runtime issue found in v2.

Hi Amit,

I kept iterating with our new PostgresAI harness and found one more
issue while testing v2.

`ri_HashCompareOp()` can process a cast invalidation inside
`fmgr_info_cxt()`, before publishing `entry->info`. The callback sees
NULL and has nothing to detach, so the outer call publishes the old
cast information afterward.

In the affected backend, a direct cast maps 2 to 102, but RI still
looks for parent 2. A fresh backend uses the new cast. This can occur
when function initialization processes a pending cast invalidation
during cache construction.

Reproduced on master and PG19. The same comparison-cache construction
sequence is present in the PG14–18 v2 patches.

Function initialization can load a C library and run its `_PG_init()`.
Nested RI from there can populate the same cache entry. The outer call
then overwrites it, leaking the comparison context; fast-path metadata
has the same problem.

In case helpful, attached is an incremental fix for master/PG19, on
top of v2. It retries after invalidation and keeps an entry already
populated by a nested call. The fast-path check uses a per-constraint
generation, since a nested reload can set `valid` back to true before
the outer call resumes. PG14–18 need only the comparison-cache
changes.

The fix passes checks for invalidation during construction, nested
initialization, and both together. On master, regression, isolation,
and injection-point suites pass with the earlier memory-test
correction applied.

Thanks,
Nik

Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
Hi Nik,

On Tue, Sep 15, 2026 at 11:14 AM Nikolay Samokhvalov  wrote:
>
> On Fri, Sep 11, 2026 at 2:25 AM Amit Langote
>  wrote:
> > For 0001, SPI's FOR KEY SHARE also requires UPDATE privilege on at
> > least one column. I've used ExecCheckOneRelPerms() to cover that along
> > with column-level SELECT. The tests exercise both per-row and batched
> > checks, including rejection without UPDATE and acceptance with UPDATE
> > on an unrelated column.
>
> I kept testing with my AI harness and found another case on master and
> PG19. Replacing a loose cross-type equality member leaves the FK's stored
> operator unchanged. An uncached fast-path check then errors; warmed
> metadata is not invalidated by the pg_amop change. The replacement calls
> the same int48eq function, so the family semantics are unchanged and SPI
> continues to enforce the FK normally.
>
> Attached are standalone fixes for master a625fc57 and PG19 f4b511ae.
> They invalidate the metadata on pg_amop changes and use SPI unless the
> stored operator is still an equality member. On master, buffered rows
> also need the SPI fallback if the family changes between AFTER triggers.
>
> Both assertion builds pass the native foreign_key test, full regression
> and isolation suites, and the injection-point suites. The tests cover
> warmed and uncached metadata and missing keys on both sides of the DDL.

Thanks for the report and the patch.

I've added an open item:

RI fastpath misses pg_amop updates
Commit: 2da86c1ef9b
Owner: Amit Langote

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Melanie Plageman <melanieplageman@gmail.com>
Дата:
On Tue, Sep 15, 2026 at 11:12 PM Amit Langote  wrote:
>
> Thanks for the report and the patch.
>
> I've added an open item:
>
> RI fastpath misses pg_amop updates
> Commit: 2da86c1ef9b
> Owner: Amit Langote

Will the fix be something like what Nikolay proposed or something
different that solves both the issue in the fast path and the
pre-existing issue with the cached cast functions?

- Melanie


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Thu, Sep 17, 2026 at 0:41 Melanie Plageman <melanieplageman@gmail.com> wrote:
On Tue, Sep 15, 2026 at 11:12 PM Amit Langote <amitlangote09@gmail.com> wrote:
>
> Thanks for the report and the patch.
>
> I've added an open item:
>
> RI fastpath misses pg_amop updates
> Commit: 2da86c1ef9b
> Owner: Amit Langote

Will the fix be something like what Nikolay proposed or something
different that solves both the issue in the fast path and the
pre-existing issue with the cached cast functions?

There’s some overlap but I’m planning to fix the cast issue separately, that is, not combine it with the fix for this open item which I’d like to fix by beta4 freeze.

- Amit

Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
Вложения:
Hi,

On Thu, Sep 17, 2026 at 8:00 AM Amit Langote  wrote:
>
> On Thu, Sep 17, 2026 at 0:41 Melanie Plageman  wrote:
>>
>> On Tue, Sep 15, 2026 at 11:12 PM Amit Langote  wrote:
>> >
>> > Thanks for the report and the patch.
>> >
>> > I've added an open item:
>> >
>> > RI fastpath misses pg_amop updates
>> > Commit: 2da86c1ef9b
>> > Owner: Amit Langote
>>
>> Will the fix be something like what Nikolay proposed or something
>> different that solves both the issue in the fast path and the
>> pre-existing issue with the cached cast functions?
>
>
> There’s some overlap but I’m planning to fix the cast issue separately, that is, not combine it with the fix for this open item which I’d like to fix by beta4 freeze.

Attached are the patches for fixing the two open items, which I plan
to push tomorrow.

Patch 0001 needs to fix a batching specific function (or it won't
compile) so there are separate versions for master and 19.

For 0002, I am attaching only the patch that fixes the per-row fast
path, which has the same shape in both master and 19.  Nik had posted
one patch to fix both paths, but I decided to break it into one patch
that fixes the per-row path (which applies to both master and 19) and
another that is only needed in master for fixing the batching path for
the same opfamily change errors. I'm adding the latter to the list of
patches I now have locally for fixing the various batching path issues
I am aware of.

-- 
Thanks, Amit Langote

Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Fri, Sep 18, 2026 at 6:21 PM Amit Langote  wrote:
> On Thu, Sep 17, 2026 at 8:00 AM Amit Langote  wrote:
> > On Thu, Sep 17, 2026 at 0:41 Melanie Plageman  wrote:
> >> On Tue, Sep 15, 2026 at 11:12 PM Amit Langote  wrote:
> >> > Thanks for the report and the patch.
> >> >
> >> > I've added an open item:
> >> >
> >> > RI fastpath misses pg_amop updates
> >> > Commit: 2da86c1ef9b
> >> > Owner: Amit Langote
> >>
> >> Will the fix be something like what Nikolay proposed or something
> >> different that solves both the issue in the fast path and the
> >> pre-existing issue with the cached cast functions?
> >
> >
> > There’s some overlap but I’m planning to fix the cast issue separately, that is, not combine it with the fix for this open item which I’d like to fix by beta4 freeze.
>
> Attached are the patches for fixing the two open items, which I plan
> to push tomorrow.
>
> Patch 0001 needs to fix a batching specific function (or it won't
> compile) so there are separate versions for master and 19.
>
> For 0002, I am attaching only the patch that fixes the per-row fast
> path, which has the same shape in both master and 19.  Nik had posted
> one patch to fix both paths, but I decided to break it into one patch
> that fixes the per-row path (which applies to both master and 19) and
> another that is only needed in master for fixing the batching path for
> the same opfamily change errors. I'm adding the latter to the list of
> patches I now have locally for fixing the various batching path issues
> I am aware of.

I have pushed 0001 and 0002 now and closed the open items.

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Nathan Bossart <nathandbossart@gmail.com>
Дата:
On Sat, Sep 19, 2026 at 04:05:30PM +0900, Amit Langote wrote:
> I have pushed 0001 and 0002 now and closed the open items.

There's still an open item for "RI fastpath doesn't call
ExecutorCheckPerms_hook".  Can that one be marked as resolved?

-- 
nathan


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
Hi Nathan,

On Thu, Sep 24, 2026 at 12:14 AM Nathan Bossart
 wrote:
> On Sat, Sep 19, 2026 at 04:05:30PM +0900, Amit Langote wrote:
> > I have pushed 0001 and 0002 now and closed the open items.
>
> There's still an open item for "RI fastpath doesn't call
> ExecutorCheckPerms_hook".  Can that one be marked as resolved?

Sorry, just noticed I had copy-pasted the wrong link for a new item I
added on Tuesday.  The correct link is this:

https://www.postgresql.org/message-id/CA%2BHiwqE4oLLTJqRA%3DpzahLGcnXVPxgYtNsLvOm_-tW04rOqSXw%40mail.gmail.com

I will push the patch and close this item later today.

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Thu, Sep 24, 2026 at 8:53 AM Amit Langote  wrote:
>
> Hi Nathan,
>
> On Thu, Sep 24, 2026 at 12:14 AM Nathan Bossart
>  wrote:
> > On Sat, Sep 19, 2026 at 04:05:30PM +0900, Amit Langote wrote:
> > > I have pushed 0001 and 0002 now and closed the open items.
> >
> > There's still an open item for "RI fastpath doesn't call
> > ExecutorCheckPerms_hook".  Can that one be marked as resolved?
>
> Sorry, just noticed I had copy-pasted the wrong link for a new item I
> added on Tuesday.  The correct link is this:
>
> https://www.postgresql.org/message-id/CA%2BHiwqE4oLLTJqRA%3DpzahLGcnXVPxgYtNsLvOm_-tW04rOqSXw%40mail.gmail.com
>
> I will push the patch and close this item later today.

Done.

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
Вложения:
Hi,

While reviewing the RI fast path after the batching removal, with help
from Claude Opus 5.5, I found more issues suggesting that directly
calling the cast function using FunctionCall3() might not be such a
good idea.  Nikolay's report upthread, where a cast is redefined while
ri_triggers.c's internal cache still uses the old definition causing
"cache lookup failed for function", is only one of the issues caused
by it.  When comparing how the corresponding SPI query containing the
same cast handles necessary cases, Opus found more issues resulting
from directly calling the cast function.  For example, a cast
returning NULL also raises an internal "function ... returned NULL"
instead of a FK violation as shown here (Opus' example):

CREATE TABLE pk (id int4 PRIMARY KEY);
INSERT INTO pk VALUES (1);
CREATE TYPE word AS ENUM ('one', 'none');
CREATE FUNCTION word_to_int4(word) RETURNS int4
    LANGUAGE sql IMMUTABLE AS $$ SELECT CASE WHEN $1::text = 'one'
THEN 1 END $$;
CREATE CAST (word AS int4) WITH FUNCTION word_to_int4(word) AS IMPLICIT;
CREATE TABLE fk_word (a word REFERENCES pk, n int);
INSERT INTO fk_word VALUES ('one', 0);
INSERT 0 1
INSERT INTO fk_word VALUES ('none', 0);
ERROR:  function 16397 returned NULL

If the PK table is partitioned, the fast path is not taken, and you
get proper handling of the cast function defined this way:

CREATE TABLE pk (id int4 PRIMARY KEY) PARTITION BY LIST (id);
CREATE TABLE pk_part PARTITION OF pk DEFAULT;
INSERT INTO pk VALUES (1);
CREATE TYPE word AS ENUM ('one', 'none');
CREATE FUNCTION word_to_int4(word) RETURNS int4
    LANGUAGE sql IMMUTABLE AS $$ SELECT CASE WHEN $1::text = 'one'
THEN 1 END $$;
CREATE CAST (word AS int4) WITH FUNCTION word_to_int4(word) AS IMPLICIT;
CREATE TABLE fk_word (a word REFERENCES pk, n int);
INSERT INTO fk_word VALUES ('one', 0);
INSERT INTO fk_word VALUES ('none', 0);
ERROR:  insert or update on table "fk_word" violates foreign key
constraint "fk_word_a_fkey"
DETAIL:  Key (a)=(none) is not present in table "pk".

So I propose fixing the fast-path selection criteria to avoid it when
such a cast is necessary, as done in the attached 0001.  0002 is a
patch to drop the code added in the fast-path commit to facilitate
this cast handling as it is now dead code.  0001+0002 apply on top of
the other fix I posted at [1], which I plan to commit tomorrow.

Note that these errors are also reachable in the
RI_FKey_fk_upd_check_required() -> ri_KeysEqual() path, which predates
the addition of the fast-path.  It compares the old and new key of an
updated referencing row by calling the cast function the same way, so
with the setup of the first example above:

UPDATE fk_word SET a = 'none';
ERROR:  function 16467 returned NULL

I wrote a patch to fix that too (0003).  The lack of field complaints
might stem from people rarely setting things up this way in the real
world, but I think it's worth committing. The fix is simple: when a
cast function would be needed, compare the bytes of the old and new
values instead. At worst, this runs a check that could have been
skipped.

I would like to commit 0001 and 0002 before RC1 next week, since
without them a foreign key using such a cast is checked differently
depending on whether the fast path or SPI handles it.  I can wait for
others to opine on whether 0003 is warranted (I haven't checked the
back-patching pain).

--
Thanks, Amit Langote

[1] https://www.postgresql.org/message-id/CA%2BHiwqFaipkMsZ8XP-9sMk21h0Q7rih%3DNpJQXsBAaD39VtnrOA%40mail.gmail.com

Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Mon, Oct 5, 2026 at 10:18 PM Amit Langote  wrote:
>
> Hi,
>
> While reviewing the RI fast path after the batching removal, with help
> from Claude Opus 5.5, I found more issues suggesting that directly
> calling the cast function using FunctionCall3() might not be such a
> good idea.  Nikolay's report upthread, where a cast is redefined while
> ri_triggers.c's internal cache still uses the old definition causing
> "cache lookup failed for function", is only one of the issues caused
> by it.  When comparing how the corresponding SPI query containing the
> same cast handles necessary cases, Opus found more issues resulting
> from directly calling the cast function.  For example, a cast
> returning NULL also raises an internal "function ... returned NULL"
> instead of a FK violation as shown here (Opus' example):
>
> CREATE TABLE pk (id int4 PRIMARY KEY);
> INSERT INTO pk VALUES (1);
> CREATE TYPE word AS ENUM ('one', 'none');
> CREATE FUNCTION word_to_int4(word) RETURNS int4
>     LANGUAGE sql IMMUTABLE AS $$ SELECT CASE WHEN $1::text = 'one'
> THEN 1 END $$;
> CREATE CAST (word AS int4) WITH FUNCTION word_to_int4(word) AS IMPLICIT;
> CREATE TABLE fk_word (a word REFERENCES pk, n int);
> INSERT INTO fk_word VALUES ('one', 0);
> INSERT 0 1
> INSERT INTO fk_word VALUES ('none', 0);
> ERROR:  function 16397 returned NULL
>
> If the PK table is partitioned, the fast path is not taken, and you
> get proper handling of the cast function defined this way:
>
> CREATE TABLE pk (id int4 PRIMARY KEY) PARTITION BY LIST (id);
> CREATE TABLE pk_part PARTITION OF pk DEFAULT;
> INSERT INTO pk VALUES (1);
> CREATE TYPE word AS ENUM ('one', 'none');
> CREATE FUNCTION word_to_int4(word) RETURNS int4
>     LANGUAGE sql IMMUTABLE AS $$ SELECT CASE WHEN $1::text = 'one'
> THEN 1 END $$;
> CREATE CAST (word AS int4) WITH FUNCTION word_to_int4(word) AS IMPLICIT;
> CREATE TABLE fk_word (a word REFERENCES pk, n int);
> INSERT INTO fk_word VALUES ('one', 0);
> INSERT INTO fk_word VALUES ('none', 0);
> ERROR:  insert or update on table "fk_word" violates foreign key
> constraint "fk_word_a_fkey"
> DETAIL:  Key (a)=(none) is not present in table "pk".
>
> So I propose fixing the fast-path selection criteria to avoid it when
> such a cast is necessary, as done in the attached 0001.  0002 is a
> patch to drop the code added in the fast-path commit to facilitate
> this cast handling as it is now dead code.  0001+0002 apply on top of
> the other fix I posted at [1], which I plan to commit tomorrow.
>
> Note that these errors are also reachable in the
> RI_FKey_fk_upd_check_required() -> ri_KeysEqual() path, which predates
> the addition of the fast-path.  It compares the old and new key of an
> updated referencing row by calling the cast function the same way, so
> with the setup of the first example above:
>
> UPDATE fk_word SET a = 'none';
> ERROR:  function 16467 returned NULL
>
> I wrote a patch to fix that too (0003).  The lack of field complaints
> might stem from people rarely setting things up this way in the real
> world, but I think it's worth committing. The fix is simple: when a
> cast function would be needed, compare the bytes of the old and new
> values instead. At worst, this runs a check that could have been
> skipped.
>
> I would like to commit 0001 and 0002 before RC1 next week, since
> without them a foreign key using such a cast is checked differently
> depending on whether the fast path or SPI handles it.  I can wait for
> others to opine on whether 0003 is warranted (I haven't checked the
> back-patching pain).

Added an open item, though I'll try to commit 0001 and 0002 no later
than tomorrow.

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
"Matheus Alcantara" <matheusssilv97@gmail.com>
Дата:
On Mon Oct 5, 2026 at 10:18 AM -03, Amit Langote wrote:
> So I propose fixing the fast-path selection criteria to avoid it when
> such a cast is necessary, as done in the attached 0001.  0002 is a
> patch to drop the code added in the fast-path commit to facilitate
> this cast handling as it is now dead code.  0001+0002 apply on top of
> the other fix I posted at [1], which I plan to commit tomorrow.
>
> [ ... ]
>
> I would like to commit 0001 and 0002 before RC1 next week, since
> without them a foreign key using such a cast is checked differently
> depending on whether the fast path or SPI handles it.  I can wait for
> others to opine on whether 0003 is warranted (I haven't checked the
> back-patching pain).
>

Hi, thanks for the patches! I've reviewed and tested 0001 and 0002 and I
dind't find any issues.

I also noticed that a user-defined WITH INOUT AS IMPLICIT cast now works
through SPI. Before 0001 it failed with "no conversion function" from
ri_HashCompareOp(), so perhaps it's worth adding a test for it.

The pg_cast invalidation also seems to work fine. I tested it with a
session that had cached the fast path for a FK using a binary cast,
while another session replaced the cast with a function returning NULL,
and the next insert on the first session went through SPI and reported
the FK violation. The same works when the cast is replaced within the
same transaction.

I have just a single comment: I'm wondering if the tests that 0001
rewords (fk_defer_main, the fkint invalidation test, fp_reentry and the
ri_snapshot STABLE test) now all seems to go through SPI, so they no
longer test the fast path issues they were written for, what do you
think?

Some minor comments:

- "getBaseType(fk_type) != righttype &&" on the new check seems
  redundant since IsBinaryCoercible() already handles the same type and
  domain cases.

- The "typedef struct RI_CompareHashEntry RI_CompareHashEntry;" added
  by 2da86c1ef9 before FastPathMeta is not needed anymore.

- The ri_check_fastpath_index() header comment only mentions index
  properties, but the new check depends on the FK table. The comment
  before the fast path call on RI_FKey_check() also only mentions
  non-partitioned and non-temporal FKs.

- "pk_fast" on the ri_snapshot test now also goes through SPI, so the
  name is a may be misleading.


I'll review 0003 next.

--
Matheus Alcantara
EDB: https://www.enterprisedb.com


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
Вложения:
Hi Matheus,

On Wed, Oct 7, 2026 at 5:33 AM Matheus Alcantara
 wrote:
>
> On Mon Oct 5, 2026 at 10:18 AM -03, Amit Langote wrote:
> > So I propose fixing the fast-path selection criteria to avoid it when
> > such a cast is necessary, as done in the attached 0001.  0002 is a
> > patch to drop the code added in the fast-path commit to facilitate
> > this cast handling as it is now dead code.  0001+0002 apply on top of
> > the other fix I posted at [1], which I plan to commit tomorrow.
> >
> > [ ... ]
> >
> > I would like to commit 0001 and 0002 before RC1 next week, since
> > without them a foreign key using such a cast is checked differently
> > depending on whether the fast path or SPI handles it.  I can wait for
> > others to opine on whether 0003 is warranted (I haven't checked the
> > back-patching pain).
> >
>
> Hi, thanks for the patches! I've reviewed and tested 0001 and 0002 and I
> dind't find any issues.

Thanks for the review.

> I also noticed that a user-defined WITH INOUT AS IMPLICIT cast now works
> through SPI. Before 0001 it failed with "no conversion function" from
> ri_HashCompareOp(), so perhaps it's worth adding a test for it.

+1, added in v2 (0001's ri_cast tests).

> The pg_cast invalidation also seems to work fine. I tested it with a
> session that had cached the fast path for a FK using a binary cast,
> while another session replaced the cast with a function returning NULL,
> and the next insert on the first session went through SPI and reported
> the FK violation. The same works when the cast is replaced within the
> same transaction.
>
> I have just a single comment: I'm wondering if the tests that 0001
> rewords (fk_defer_main, the fkint invalidation test, fp_reentry and the
> ri_snapshot STABLE test) now all seems to go through SPI, so they no
> longer test the fast path issues they were written for, what do you
> think?

Good point.  fk_defer_main and fp_reentry were written for batching,
which is gone, so there's no fast-path code left for them to test;
I've kept them as they are, now going through SPI.  The fkint
invalidation test and the ri_snapshot test cover the fast path's
handling of its cached metadata being invalidated mid-check and its
pushing of the check's snapshot as the active one, so in v2 they use
the equality function of a custom opclass instead of a cast, the only
user code a fast-path check still runs, which also makes the pk_fast
name accurate again.

> Some minor comments:
>
> - "getBaseType(fk_type) != righttype &&" on the new check seems
>   redundant since IsBinaryCoercible() already handles the same type and
>   domain cases.
>
> - The "typedef struct RI_CompareHashEntry RI_CompareHashEntry;" added
>   by 2da86c1ef9 before FastPathMeta is not needed anymore.
>
> - The ri_check_fastpath_index() header comment only mentions index
>   properties, but the new check depends on the FK table. The comment
>   before the fast path call on RI_FKey_check() also only mentions
>   non-partitioned and non-temporal FKs.
>
> - "pk_fast" on the ri_snapshot test now also goes through SPI, so the
>   name is a may be misleading.

All addressed in v2.

> I'll review 0003 next.

In no hurry, but thanks.  I've added a test case with a WITH INOUT
cast to 0003 as well, which covers UPDATEs of the referencing row:
without 0003, they fail with "no conversion function" even when the
key doesn't change.

I'll push 0001 and 0002 tomorrow barring objections.

--
Thanks, Amit Langote

Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Wed, Oct 7, 2026 at 8:47 PM Amit Langote  wrote:
>
> Hi Matheus,
>
> On Wed, Oct 7, 2026 at 5:33 AM Matheus Alcantara
>  wrote:
> >
> > On Mon Oct 5, 2026 at 10:18 AM -03, Amit Langote wrote:
> > > So I propose fixing the fast-path selection criteria to avoid it when
> > > such a cast is necessary, as done in the attached 0001.  0002 is a
> > > patch to drop the code added in the fast-path commit to facilitate
> > > this cast handling as it is now dead code.  0001+0002 apply on top of
> > > the other fix I posted at [1], which I plan to commit tomorrow.
> > >
> > > [ ... ]
> > >
> > > I would like to commit 0001 and 0002 before RC1 next week, since
> > > without them a foreign key using such a cast is checked differently
> > > depending on whether the fast path or SPI handles it.  I can wait for
> > > others to opine on whether 0003 is warranted (I haven't checked the
> > > back-patching pain).
> > >
> >
> > Hi, thanks for the patches! I've reviewed and tested 0001 and 0002 and I
> > dind't find any issues.
>
> Thanks for the review.
>
> > I also noticed that a user-defined WITH INOUT AS IMPLICIT cast now works
> > through SPI. Before 0001 it failed with "no conversion function" from
> > ri_HashCompareOp(), so perhaps it's worth adding a test for it.
>
> +1, added in v2 (0001's ri_cast tests).
>
> > The pg_cast invalidation also seems to work fine. I tested it with a
> > session that had cached the fast path for a FK using a binary cast,
> > while another session replaced the cast with a function returning NULL,
> > and the next insert on the first session went through SPI and reported
> > the FK violation. The same works when the cast is replaced within the
> > same transaction.
> >
> > I have just a single comment: I'm wondering if the tests that 0001
> > rewords (fk_defer_main, the fkint invalidation test, fp_reentry and the
> > ri_snapshot STABLE test) now all seems to go through SPI, so they no
> > longer test the fast path issues they were written for, what do you
> > think?
>
> Good point.  fk_defer_main and fp_reentry were written for batching,
> which is gone, so there's no fast-path code left for them to test;
> I've kept them as they are, now going through SPI.  The fkint
> invalidation test and the ri_snapshot test cover the fast path's
> handling of its cached metadata being invalidated mid-check and its
> pushing of the check's snapshot as the active one, so in v2 they use
> the equality function of a custom opclass instead of a cast, the only
> user code a fast-path check still runs, which also makes the pk_fast
> name accurate again.
>
> > Some minor comments:
> >
> > - "getBaseType(fk_type) != righttype &&" on the new check seems
> >   redundant since IsBinaryCoercible() already handles the same type and
> >   domain cases.
> >
> > - The "typedef struct RI_CompareHashEntry RI_CompareHashEntry;" added
> >   by 2da86c1ef9 before FastPathMeta is not needed anymore.
> >
> > - The ri_check_fastpath_index() header comment only mentions index
> >   properties, but the new check depends on the FK table. The comment
> >   before the fast path call on RI_FKey_check() also only mentions
> >   non-partitioned and non-temporal FKs.
> >
> > - "pk_fast" on the ri_snapshot test now also goes through SPI, so the
> >   name is a may be misleading.
>
> All addressed in v2.
>
> > I'll review 0003 next.
>
> In no hurry, but thanks.  I've added a test case with a WITH INOUT
> cast to 0003 as well, which covers UPDATEs of the referencing row:
> without 0003, they fail with "no conversion function" even when the
> key doesn't change.
>
> I'll push 0001 and 0002 tomorrow barring objections.

Forgot the Backpatch-through: 19 tag, which I've added in my local tree.

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Matheus Alcantara <matheusssilv97@gmail.com>
Дата:
On 07/10/26 08:47, Amit Langote wrote:
> Thanks for the review.
> 
>> I also noticed that a user-defined WITH INOUT AS IMPLICIT cast now works
>> through SPI. Before 0001 it failed with "no conversion function" from
>> ri_HashCompareOp(), so perhaps it's worth adding a test for it.
> 
> +1, added in v2 (0001's ri_cast tests).
> 
>> The pg_cast invalidation also seems to work fine. I tested it with a
>> session that had cached the fast path for a FK using a binary cast,
>> while another session replaced the cast with a function returning NULL,
>> and the next insert on the first session went through SPI and reported
>> the FK violation. The same works when the cast is replaced within the
>> same transaction.
>>
>> I have just a single comment: I'm wondering if the tests that 0001
>> rewords (fk_defer_main, the fkint invalidation test, fp_reentry and the
>> ri_snapshot STABLE test) now all seems to go through SPI, so they no
>> longer test the fast path issues they were written for, what do you
>> think?
> 
> Good point.  fk_defer_main and fp_reentry were written for batching,
> which is gone, so there's no fast-path code left for them to test;
> I've kept them as they are, now going through SPI.  The fkint
> invalidation test and the ri_snapshot test cover the fast path's
> handling of its cached metadata being invalidated mid-check and its
> pushing of the check's snapshot as the active one, so in v2 they use
> the equality function of a custom opclass instead of a cast, the only
> user code a fast-path check still runs, which also makes the pk_fast
> name accurate again.
> 
>> Some minor comments:
>>
>> - "getBaseType(fk_type) != righttype &&" on the new check seems
>>    redundant since IsBinaryCoercible() already handles the same type and
>>    domain cases.
>>
>> - The "typedef struct RI_CompareHashEntry RI_CompareHashEntry;" added
>>    by 2da86c1ef9 before FastPathMeta is not needed anymore.
>>
>> - The ri_check_fastpath_index() header comment only mentions index
>>    properties, but the new check depends on the FK table. The comment
>>    before the fast path call on RI_FKey_check() also only mentions
>>    non-partitioned and non-temporal FKs.
>>
>> - "pk_fast" on the ri_snapshot test now also goes through SPI, so the
>>    name is a may be misleading.
> 
> All addressed in v2.
> 

Thanks for the new version. I've tested v2 and it looks good to me.

> I'll push 0001 and 0002 tomorrow barring objections.
> 

+1 from me.


--
Matheus Alcantara
EDB: https://www.enterprisedb.com


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Melanie Plageman <melanieplageman@gmail.com>
Дата:
On Wed, Oct 7, 2026 at 10:04 AM Matheus Alcantara
 wrote:
>
> On 07/10/26 08:47, Amit Langote wrote:
>
> Thanks for the new version. I've tested v2 and it looks good to me.
>
> > I'll push 0001 and 0002 tomorrow barring objections.
> >
>
> +1 from me.

What are the status of these patches? Have they been committed?

- Melanie


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Thu, Oct 15, 2026 at 0:08 Melanie Plageman <melanieplageman@gmail.com> wrote:
On Wed, Oct 7, 2026 at 10:04 AM Matheus Alcantara
<matheusssilv97@gmail.com> wrote:
>
> On 07/10/26 08:47, Amit Langote wrote:
>
> Thanks for the new version. I've tested v2 and it looks good to me.
>
> > I'll push 0001 and 0002 tomorrow barring objections.
> >
>
> +1 from me.

What are the status of these patches? Have they been committed?

No, they have not. I’ll commit these today.

- Amit

Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Thu, Oct 15, 2026 at 7:55 AM Amit Langote  wrote:
> On Thu, Oct 15, 2026 at 0:08 Melanie Plageman  wrote:
>>
>> On Wed, Oct 7, 2026 at 10:04 AM Matheus Alcantara
>>  wrote:
>> >
>> > On 07/10/26 08:47, Amit Langote wrote:
>> >
>> > Thanks for the new version. I've tested v2 and it looks good to me.
>> >
>> > > I'll push 0001 and 0002 tomorrow barring objections.
>> > >
>> >
>> > +1 from me.
>>
>> What are the status of these patches? Have they been committed?
>
> No, they have not. I’ll commit these today.

Done, sorry for the delay.

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Thu, Oct 15, 2026 at 5:07 PM Amit Langote  wrote:
> > No, they have not. I’ll commit these today.
>
> Done, sorry for the delay.

Commit 6aecabcd5ed seems to have caused a test failure on buildfarm
member trilobite [1]. The log indicates that a client backend crashed
with a segmentation fault:

    2026-10-22 10:03:23.907 CEST [13117:8] LOG:  client backend (PID
16078) was terminated by signal 11: Segmentation fault
    2026-10-22 10:03:23.907 CEST [13117:9] DETAIL:  Failed process was
running: INSERT INTO fp_reentry_fk SELECT row(1)::fp_vch FROM
generate_series(1, 2);

Codex came up with the following minimal reproduction:

--------------------------------------------------
SET debug_discard_caches = 1;

CREATE TABLE p (id int PRIMARY KEY);
INSERT INTO p VALUES (1), (2);
CREATE TYPE t AS (v int);

CREATE FUNCTION c(t) RETURNS int LANGUAGE plpgsql AS $$
BEGIN
  IF $1.v = 1 THEN
    INSERT INTO f VALUES (ROW(2)::t);
  END IF;
  RETURN $1.v;
END$$;

CREATE CAST (t AS int) WITH FUNCTION c(t) AS IMPLICIT;
CREATE TABLE f (a t REFERENCES p);
INSERT INTO f VALUES (ROW(1)::t);
--------------------------------------------------

This issue should be added into Open Items for v19?

Regards,

[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=trilobite&dt=2026-10-22%2005%3A52%3A17


-- 
Fujii Masao


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
Hi Fujii-san,

On Thu, Oct 22, 2026 at 6:18 PM Fujii Masao  wrote:
>
> On Thu, Oct 15, 2026 at 5:07 PM Amit Langote  wrote:
> > > No, they have not. I’ll commit these today.
> >
> > Done, sorry for the delay.
>
> Commit 6aecabcd5ed seems to have caused a test failure on buildfarm
> member trilobite [1]. The log indicates that a client backend crashed
> with a segmentation fault:
>
>     2026-10-22 10:03:23.907 CEST [13117:8] LOG:  client backend (PID
> 16078) was terminated by signal 11: Segmentation fault
>     2026-10-22 10:03:23.907 CEST [13117:9] DETAIL:  Failed process was
> running: INSERT INTO fp_reentry_fk SELECT row(1)::fp_vch FROM
> generate_series(1, 2);
>
> Codex came up with the following minimal reproduction:
>
> --------------------------------------------------
> SET debug_discard_caches = 1;
>
> CREATE TABLE p (id int PRIMARY KEY);
> INSERT INTO p VALUES (1), (2);
> CREATE TYPE t AS (v int);
>
> CREATE FUNCTION c(t) RETURNS int LANGUAGE plpgsql AS $$
> BEGIN
>   IF $1.v = 1 THEN
>     INSERT INTO f VALUES (ROW(2)::t);
>   END IF;
>   RETURN $1.v;
> END$$;
>
> CREATE CAST (t AS int) WITH FUNCTION c(t) AS IMPLICIT;
> CREATE TABLE f (a t REFERENCES p);
> INSERT INTO f VALUES (ROW(1)::t);
> --------------------------------------------------
>
> This issue should be added into Open Items for v19?

It's actually an old bug affecting all stable releases as I explained in:
https://postgr.es/m/CA+HiwqGZ9Rx5Lkh8+or4HK+jjHKQTZCgwgL50J=0mqL_9Cmu7g@mail.gmail.com

Tom reported that same trilobite failure there.

The patch for the same issue though with a different crashing example
is also being discussed here:
https://postgr.es/m/CA+HiwqGjcSqmsruvq94V0ARNx0Gec6Va9J-G2DQXafVKfEravQ@mail.gmail.com

I am about to post a new patch at the second thread.




--
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Thu, Oct 22, 2026 at 8:09 PM Amit Langote  wrote:
> On Thu, Oct 22, 2026 at 6:18 PM Fujii Masao  wrote:
> >
> > On Thu, Oct 15, 2026 at 5:07 PM Amit Langote  wrote:
> > > > No, they have not. I’ll commit these today.
> > >
> > > Done, sorry for the delay.
> >
> > Commit 6aecabcd5ed seems to have caused a test failure on buildfarm
> > member trilobite [1]. The log indicates that a client backend crashed
> > with a segmentation fault:
> >
> >     2026-10-22 10:03:23.907 CEST [13117:8] LOG:  client backend (PID
> > 16078) was terminated by signal 11: Segmentation fault
> >     2026-10-22 10:03:23.907 CEST [13117:9] DETAIL:  Failed process was
> > running: INSERT INTO fp_reentry_fk SELECT row(1)::fp_vch FROM
> > generate_series(1, 2);
> >
> > Codex came up with the following minimal reproduction:
> >
> > --------------------------------------------------
> > SET debug_discard_caches = 1;
> >
> > CREATE TABLE p (id int PRIMARY KEY);
> > INSERT INTO p VALUES (1), (2);
> > CREATE TYPE t AS (v int);
> >
> > CREATE FUNCTION c(t) RETURNS int LANGUAGE plpgsql AS $$
> > BEGIN
> >   IF $1.v = 1 THEN
> >     INSERT INTO f VALUES (ROW(2)::t);
> >   END IF;
> >   RETURN $1.v;
> > END$$;
> >
> > CREATE CAST (t AS int) WITH FUNCTION c(t) AS IMPLICIT;
> > CREATE TABLE f (a t REFERENCES p);
> > INSERT INTO f VALUES (ROW(1)::t);
> > --------------------------------------------------
> >
> > This issue should be added into Open Items for v19?
>
> It's actually an old bug affecting all stable releases as I explained in:
> https://postgr.es/m/CA+HiwqGZ9Rx5Lkh8+or4HK+jjHKQTZCgwgL50J=0mqL_9Cmu7g@mail.gmail.com
>
> Tom reported that same trilobite failure there.
>
> The patch for the same issue though with a different crashing example
> is also being discussed here:
> https://postgr.es/m/CA+HiwqGjcSqmsruvq94V0ARNx0Gec6Va9J-G2DQXafVKfEravQ@mail.gmail.com
>
> I am about to post a new patch at the second thread.

To clarify, the test case that crashed trilobite started going through
the SPI path instead of the fast path with 6aecabcd5ed. The SPI path
has a bug that causes the crash, but the fast path doesn’t have the
same bug. So the issue was not found until that commit made the test
start going through the SPI path.

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Thu, Oct 22, 2026 at 8:16 PM Amit Langote  wrote:
> On Thu, Oct 22, 2026 at 8:09 PM Amit Langote  wrote:
> > On Thu, Oct 22, 2026 at 6:18 PM Fujii Masao  wrote:
> > > On Thu, Oct 15, 2026 at 5:07 PM Amit Langote  wrote:
> > > > > No, they have not. I’ll commit these today.
> > > >
> > > > Done, sorry for the delay.
> > >
> > > Commit 6aecabcd5ed seems to have caused a test failure on buildfarm
> > > member trilobite [1]. The log indicates that a client backend crashed
> > > with a segmentation fault:
> > >
> > >     2026-10-22 10:03:23.907 CEST [13117:8] LOG:  client backend (PID
> > > 16078) was terminated by signal 11: Segmentation fault
> > >     2026-10-22 10:03:23.907 CEST [13117:9] DETAIL:  Failed process was
> > > running: INSERT INTO fp_reentry_fk SELECT row(1)::fp_vch FROM
> > > generate_series(1, 2);
> > >
> > > Codex came up with the following minimal reproduction:
> > >
> > > --------------------------------------------------
> > > SET debug_discard_caches = 1;
> > >
> > > CREATE TABLE p (id int PRIMARY KEY);
> > > INSERT INTO p VALUES (1), (2);
> > > CREATE TYPE t AS (v int);
> > >
> > > CREATE FUNCTION c(t) RETURNS int LANGUAGE plpgsql AS $$
> > > BEGIN
> > >   IF $1.v = 1 THEN
> > >     INSERT INTO f VALUES (ROW(2)::t);
> > >   END IF;
> > >   RETURN $1.v;
> > > END$$;
> > >
> > > CREATE CAST (t AS int) WITH FUNCTION c(t) AS IMPLICIT;
> > > CREATE TABLE f (a t REFERENCES p);
> > > INSERT INTO f VALUES (ROW(1)::t);
> > > --------------------------------------------------
> > >
> > > This issue should be added into Open Items for v19?
> >
> > It's actually an old bug affecting all stable releases as I explained in:
> > https://postgr.es/m/CA+HiwqGZ9Rx5Lkh8+or4HK+jjHKQTZCgwgL50J=0mqL_9Cmu7g@mail.gmail.com
> >
> > Tom reported that same trilobite failure there.
> >
> > The patch for the same issue though with a different crashing example
> > is also being discussed here:
> > https://postgr.es/m/CA+HiwqGjcSqmsruvq94V0ARNx0Gec6Va9J-G2DQXafVKfEravQ@mail.gmail.com
> >
> > I am about to post a new patch at the second thread.
>
> To clarify, the test case that crashed trilobite started going through
> the SPI path instead of the fast path with 6aecabcd5ed. The SPI path
> has a bug that causes the crash, but the fast path doesn’t have the
> same bug. So the issue was not found until that commit made the test
> start going through the SPI path.

Sorry, I should also have mentioned that the test case was added as
part of the fast-path work so it had no chance of running through the
SPI path before 6aecabcd5.

-- 
Thanks, Amit Langote


Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
Вложения:
On Thu, Oct 22, 2026 at 8:54 PM Amit Langote  wrote:
> On Thu, Oct 22, 2026 at 8:16 PM Amit Langote  wrote:
> > On Thu, Oct 22, 2026 at 8:09 PM Amit Langote  wrote:
> > > On Thu, Oct 22, 2026 at 6:18 PM Fujii Masao  wrote:
> > > > On Thu, Oct 15, 2026 at 5:07 PM Amit Langote  wrote:
> > > > > > No, they have not. I’ll commit these today.
> > > > >
> > > > > Done, sorry for the delay.
> > > >
> > > > Commit 6aecabcd5ed seems to have caused a test failure on buildfarm
> > > > member trilobite [1]. The log indicates that a client backend crashed
> > > > with a segmentation fault:
> > > >
> > > >     2026-10-22 10:03:23.907 CEST [13117:8] LOG:  client backend (PID
> > > > 16078) was terminated by signal 11: Segmentation fault
> > > >     2026-10-22 10:03:23.907 CEST [13117:9] DETAIL:  Failed process was
> > > > running: INSERT INTO fp_reentry_fk SELECT row(1)::fp_vch FROM
> > > > generate_series(1, 2);
> > > >
> > > > Codex came up with the following minimal reproduction:
> > > >
> > > > --------------------------------------------------
> > > > SET debug_discard_caches = 1;
> > > >
> > > > CREATE TABLE p (id int PRIMARY KEY);
> > > > INSERT INTO p VALUES (1), (2);
> > > > CREATE TYPE t AS (v int);
> > > >
> > > > CREATE FUNCTION c(t) RETURNS int LANGUAGE plpgsql AS $$
> > > > BEGIN
> > > >   IF $1.v = 1 THEN
> > > >     INSERT INTO f VALUES (ROW(2)::t);
> > > >   END IF;
> > > >   RETURN $1.v;
> > > > END$$;
> > > >
> > > > CREATE CAST (t AS int) WITH FUNCTION c(t) AS IMPLICIT;
> > > > CREATE TABLE f (a t REFERENCES p);
> > > > INSERT INTO f VALUES (ROW(1)::t);
> > > > --------------------------------------------------
> > > >
> > > > This issue should be added into Open Items for v19?
> > >
> > > It's actually an old bug affecting all stable releases as I explained in:
> > > https://postgr.es/m/CA+HiwqGZ9Rx5Lkh8+or4HK+jjHKQTZCgwgL50J=0mqL_9Cmu7g@mail.gmail.com
> > >
> > > Tom reported that same trilobite failure there.
> > >
> > > The patch for the same issue though with a different crashing example
> > > is also being discussed here:
> > > https://postgr.es/m/CA+HiwqGjcSqmsruvq94V0ARNx0Gec6Va9J-G2DQXafVKfEravQ@mail.gmail.com
> > >
> > > I am about to post a new patch at the second thread.
> >
> > To clarify, the test case that crashed trilobite started going through
> > the SPI path instead of the fast path with 6aecabcd5ed. The SPI path
> > has a bug that causes the crash, but the fast path doesn’t have the
> > same bug. So the issue was not found until that commit made the test
> > start going through the SPI path.
>
> Sorry, I should also have mentioned that the test case was added as
> part of the fast-path work so it had no chance of running through the
> SPI path before 6aecabcd5.

Given that this is the second report and perhaps others have been
distracted by the red trilobite, I propose to commit the attached
patch, which removes the crashing test case for now. I’ll re-add it
with the commit that fixes the bug causing the crash, which needs a
bit more time to get some details right.

Barring objections, I will commit it first thing tomorrow morning JST
or in about 10 hours.  Apologies for not having done this sooner.


--
Thanks, Amit Langote

Re: PG19: two RI fast-path issues found while testing the batching revert

От:
Amit Langote <amitlangote09@gmail.com>
Дата:
On Thu, Oct 22, 2026 at 10:14 PM Amit Langote  wrote:
> On Thu, Oct 22, 2026 at 8:54 PM Amit Langote  wrote:
> > On Thu, Oct 22, 2026 at 8:16 PM Amit Langote  wrote:
> > > On Thu, Oct 22, 2026 at 8:09 PM Amit Langote  wrote:
> > > > On Thu, Oct 22, 2026 at 6:18 PM Fujii Masao  wrote:
> > > > > On Thu, Oct 15, 2026 at 5:07 PM Amit Langote  wrote:
> > > > > > > No, they have not. I’ll commit these today.
> > > > > >
> > > > > > Done, sorry for the delay.
> > > > >
> > > > > Commit 6aecabcd5ed seems to have caused a test failure on buildfarm
> > > > > member trilobite [1]. The log indicates that a client backend crashed
> > > > > with a segmentation fault:
> > > > >
> > > > >     2026-10-22 10:03:23.907 CEST [13117:8] LOG:  client backend (PID
> > > > > 16078) was terminated by signal 11: Segmentation fault
> > > > >     2026-10-22 10:03:23.907 CEST [13117:9] DETAIL:  Failed process was
> > > > > running: INSERT INTO fp_reentry_fk SELECT row(1)::fp_vch FROM
> > > > > generate_series(1, 2);
> > > > >
> > > > > Codex came up with the following minimal reproduction:
> > > > >
> > > > > --------------------------------------------------
> > > > > SET debug_discard_caches = 1;
> > > > >
> > > > > CREATE TABLE p (id int PRIMARY KEY);
> > > > > INSERT INTO p VALUES (1), (2);
> > > > > CREATE TYPE t AS (v int);
> > > > >
> > > > > CREATE FUNCTION c(t) RETURNS int LANGUAGE plpgsql AS $$
> > > > > BEGIN
> > > > >   IF $1.v = 1 THEN
> > > > >     INSERT INTO f VALUES (ROW(2)::t);
> > > > >   END IF;
> > > > >   RETURN $1.v;
> > > > > END$$;
> > > > >
> > > > > CREATE CAST (t AS int) WITH FUNCTION c(t) AS IMPLICIT;
> > > > > CREATE TABLE f (a t REFERENCES p);
> > > > > INSERT INTO f VALUES (ROW(1)::t);
> > > > > --------------------------------------------------
> > > > >
> > > > > This issue should be added into Open Items for v19?
> > > >
> > > > It's actually an old bug affecting all stable releases as I explained in:
> > > > https://postgr.es/m/CA+HiwqGZ9Rx5Lkh8+or4HK+jjHKQTZCgwgL50J=0mqL_9Cmu7g@mail.gmail.com
> > > >
> > > > Tom reported that same trilobite failure there.
> > > >
> > > > The patch for the same issue though with a different crashing example
> > > > is also being discussed here:
> > > > https://postgr.es/m/CA+HiwqGjcSqmsruvq94V0ARNx0Gec6Va9J-G2DQXafVKfEravQ@mail.gmail.com
> > > >
> > > > I am about to post a new patch at the second thread.
> > >
> > > To clarify, the test case that crashed trilobite started going through
> > > the SPI path instead of the fast path with 6aecabcd5ed. The SPI path
> > > has a bug that causes the crash, but the fast path doesn’t have the
> > > same bug. So the issue was not found until that commit made the test
> > > start going through the SPI path.
> >
> > Sorry, I should also have mentioned that the test case was added as
> > part of the fast-path work so it had no chance of running through the
> > SPI path before 6aecabcd5.
>
> Given that this is the second report and perhaps others have been
> distracted by the red trilobite, I propose to commit the attached
> patch, which removes the crashing test case for now. I’ll re-add it
> with the commit that fixes the bug causing the crash, which needs a
> bit more time to get some details right.
>
> Barring objections, I will commit it first thing tomorrow morning JST
> or in about 10 hours.  Apologies for not having done this sooner.

Done. I understand a trilobite run takes a while to complete, but
hopefully it picks up the commit and turns green sooner rather than
later.

-- 
Thanks, Amit Langote


FAQ