Re: Update with subselect sometimes returns wrong result

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Oliver Seemann <oseemann(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: Update with subselect sometimes returns wrong result
Date: 2013-11-30 17:57:44
Message-ID: 25601.1385834264@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Oliver Seemann <oseemann(at)gmail(dot)com> writes:
> Given the following table:

> CREATE TABLE t1 (id INTEGER);
> INSERT INTO t1 VALUES (0), (1);

> Then the following UPDATE should return exactly one row:

> UPDATE t1 SET id = t1.id
> FROM (SELECT id FROM t1 LIMIT 1 FOR UPDATE) AS subset
> WHERE t1.id = subset.id
> RETURNING t1.id

> And it does so, most of of the time. But when run repeatedly in a loop like
> in the attached script, then it will occasionally return 2 rows with two
> different id values, something the LIMIT 1 should prevent. In my tests it
> took from anywhere between 0 to 10 minutes and on average 1 to 2 minutes to
> trigger the problem.

I failed to reproduce the claimed misbehavior in git tip of any active
branch. I'd like to think this means we fixed the problem in the last
two months, but I don't see anything that looks like a promising candidate
in the commit logs. Perhaps there is some important contributing factor
you've not mentioned --- nondefault postgresql.conf settings, for
instance.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Marko Tiikkaja 2013-11-30 20:42:47 Re: Update with subselect sometimes returns wrong result
Previous Message Oliver Seemann 2013-11-30 07:32:44 Re: Update with subselect sometimes returns wrong result