INSERT deadlocks (bug or feature?)

From: evgeny gridasov <eugrid(at)fpm(dot)kubsu(dot)ru>
To: pgsql-bugs(at)postgresql(dot)org
Subject: INSERT deadlocks (bug or feature?)
Date: 2005-05-27 10:06:07
Message-ID: 20050527140607.443a55af.eugrid@fpm.kubsu.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi everybody!

Recently, I've discovered an interesting feature (or a bug?) of PostgreSql (checked 7.4.x and 8.0.x):

One may define such tables:

create table ref(
id serial primary key,
name text);

create table dat(
id serial,
ref_id int references ref(id),
comment text);

Let us fill the ref table:

insert into ref(name) values('feature');
insert into ref(name) values('bug');

The test case:
For example we have 2 concurrent transactions (tr1 and tr2):

tr1: begin;
tr2: begin;
tr1: insert into dat(ref_id, comment) values (1, 'all ok');
tr2: insert into dat(ref_id, comment) values (2, 'all ok');
tr1: insert into dat(ref_id, comment) values (2, 'lockup');
tr2: insert into dat(ref_id, comment) values (1, 'deadlock');

... and we recieve a deadlock!
Easy to understand why: each insert statement generates query like:
SELECT 1 FROM ONLY "public"."ref" x WHERE "id" = $1 FOR UPDATE OF x

So, is this behaviour of postgresql is a bug or feature?

Thanks,
Eugene.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2005-05-27 14:15:32 Re: INSERT deadlocks (bug or feature?)
Previous Message Tomasz Brzezina 2005-05-27 09:22:51 UNION makes strange duplicates