Re: Parallel Apply

From: vignesh C <vignesh21(at)gmail(dot)com>
To: "Hayato Kuroda (Fujitsu)" <kuroda(dot)hayato(at)fujitsu(dot)com>
Cc: shveta malik <shveta(dot)malik(at)gmail(dot)com>, Tomas Vondra <tomas(at)vondra(dot)me>, Dilip Kumar <dilipbalaut(at)gmail(dot)com>, Andrei Lepikhov <lepihov(at)gmail(dot)com>, wenhui qiu <qiuwenhuifx(at)gmail(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Peter Smith <smithpb2250(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "Zhijie Hou (Fujitsu)" <houzj(dot)fnst(at)fujitsu(dot)com>
Subject: Re: Parallel Apply
Date: 2026-10-07 05:49:43
Message-ID: CALDaNm1O7qbojBw2W5KhN1iCKzjSHF1cOQ86jVXQ3u-UhtThdw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

>
> Thanks for the contact. Here is an updated version.
>
> The version number now becomes v27 by the internal reviews. I adjusted each
> patches to work well and pass tests, and fixed test codes to extract the
> dependent transaction correctly.

I found that dependency tracking via foreign keys (get_local_fkeys(),
relation.c) never does anything for a self-referencing foreign key,
letting a transaction that is applied directly by the leader race
ahead of an earlier, still-in-flight parallel-applied transaction it
actually depends on, and hit a foreign key violation that correct
dependency tracking should have prevented.
get_local_fkeys() classifies each FK constraint on a table with:
if (con->confrelid == relid)
trig_type = RI_TRIGGER_PK;
else if (con->conrelid == relid)
trig_type = RI_TRIGGER_FK;

For a self-referencing FK, conrelid and confrelid are the same OID
(the table references itself), so both conditions are true and the
first one always wins. The constraint ends up recorded only in
entry->local_refkeys (as if the table were purely the referenced/PK
side of some other table's FK), and never in entry->local_fkeys (the
referencing/FK side). check_and_record_fkey_dependency() (worker.c)
only ever consults local_fkeys to decide whether an incoming row's FK
value must wait for an earlier transaction that inserted the
referenced key -- so for a self-referencing constraint, that check is
not merely unreliable, it structurally never runs at all.

The attached patch has a test case to reproduce this issue.

Regards,
Vignesh

Attachment Content-Type Size
0001-Test-showing-dependency-tracker-does-not-track-self-.patch application/octet-stream 13.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2026-10-07 06:04:19 Re: [PATCH] pg_walsummary: suppress limit output with --quiet
Previous Message Richard Guo 2026-10-07 05:46:28 Re: ERROR: unsupported join alias expression