Re: Strange deadlock in foreign key check - Mailing list pgsql-general

From Sophia Wright
Subject Re: Strange deadlock in foreign key check
Date
Msg-id CAJTwwh08=5tdg6sUreXJ1RM+j+FFONSSUzZXDrwvmXe1dkx7Tg@mail.gmail.com
Whole thread Raw
In response to Re: Strange deadlock in foreign key check  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Strange deadlock in foreign key check
List pgsql-general
On Fri, Aug 7, 2015 at 2:46 AM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
I would also take a look at Alvaro's explanation. My understanding is that for locking purposes the UNIQUE index is considered sort of like a FK, as it could be used as a FK. This then leads to the FOR UPDATE lock, which from Table 13.3 at the link I sent, conflicts with all the other row locks.
 
Like I said, I think it would make sense for a UNIQUE index in pk_rel, i.e. the fk_rel insert would try to lock pk_rel.id with KEY SHARE, and would end up locking any other UNIQUE fields as a result.

But I can't see why the pk_rel deletion would want a KEY SHARE lock on fk_rel. It must be using FOR KEY SHARE rather than FOR UPDATE, since it does not conflict with the update of fk_rel.pk_id in the first example. So why lock fk_rel at all, if the lock doesn't include fk_rel.pk_id? Isn't that the only bit that matters to a pk_rel deletion?

pgsql-general by date:

Previous
From: Melvin Davidson
Date:
Subject: Re: How to intelligently work with views that depend on other views
Next
From: Melvin Davidson
Date:
Subject: Re: How to intelligently work with views that depend on other views