From: | Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com> |
---|---|
To: | Konstantin <kostya2702(at)rambler(dot)ru> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #4648: needless deadlock on tables having foreign-key |
Date: | 2009-02-12 15:45:53 |
Message-ID: | 49944431.4020707@enterprisedb.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
Konstantin wrote:
> * Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com> [Thu, 12 Feb
> 2009 13:54:11 +0200]:
>> Hmm, the first UPDATE should've blocked already. It should've fired a
> RI
>> trigger to lock the parent tuple in shared mode, but it looks like
>> that's not happening for some reason.
>
> To tell the truth I expected another behavior.
> Consider example below. The difference with the first one is that there
> are no attempts to modify foreign key at all, but result is the same.
> ...
> Are you sure parent tuple should be lock in shared mode if
> a) foreign key is not modified explicitly at all
> b) new value of foreign key is the same as old (not changed).
Yeah, you're right, we do have that optimization. However, it doesn't
kick in when you update a tuple that you've already updated in the same
transaction. The reason is explained by this comment in trigger.c:
> * There is one exception when updating FK tables: if the
> * updated row was inserted by our own transaction and the
> * FK is deferred, we still need to fire the trigger. This
> * is because our UPDATE will invalidate the INSERT so the
> * end-of-transaction INSERT RI trigger will not do
> * anything, so we have to do the check for the UPDATE
> * anyway.
So this is an implementation artifact, due to the way foreign keys are
implemented in PostgreSQL.
--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2009-02-12 15:54:34 | Re: BUG #4648: needless deadlock on tables having foreign-key |
Previous Message | Gurjeet Singh | 2009-02-12 13:49:39 | Re: BUG #4650: can't specify table schema in CREATE TABLE AS |