Re: Unnecessary checks for new rows by some RI trigger functions?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Antonin Houska <ah(at)cybertec(dot)at>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Unnecessary checks for new rows by some RI trigger functions?
Date: 2019-02-22 14:29:41
Message-ID: 24924.1550845781@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Antonin Houska <ah(at)cybertec(dot)at> writes:
> Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> It's quite easy to demonstrate that the second part of Antonin's
>> proposed patch (ie, don't check for new rows in the FK table during
>> ri_restrict) is wrong:

> When I was running this example, the other session got blocked until the first
> (serializable) transaction committed. To achieve this ERROR (or FK violated
> due to my patch proposal) I had to run the other session's INSERT before the
> first session's DELETE.

Oh, right, I copied and pasted out of my terminal windows in the wrong
order :-(. The INSERT indeed must happen before the DELETE (and the
TABLE or SELECT before that, so as to establish the serializable
transaction's snapshot before the insertion). Sorry about that.

Not sure what I think about your new proposed patch. What problem
do you think it solves? Also, don't think I believe this:

+ * crosscheck_snapshot is actually used only for UPDATE / DELETE
+ * queries.

The commands we're issuing here are SELECT FOR UPDATE^H^H^HSHARE,
and those should chase up to the newest row version and do a
crosscheck just as UPDATE / DELETE would do. If they don't, there's
a hazard of mis-enforcing the FK constraint in the face of
concurrent updates.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Euler Taveira 2019-02-22 14:37:08 Re: psql show URL with help
Previous Message Magnus Hagander 2019-02-22 14:24:52 Re: Checksum errors in pg_stat_database