Re: Strang behaviour SELECT ... LIMIT n FOR UPDATE - Mailing list pgsql-sql

From Tom Lane
Subject Re: Strang behaviour SELECT ... LIMIT n FOR UPDATE
Date
Msg-id 20830.1196281987@sss.pgh.pa.us
Whole thread Raw
In response to Re: Strang behaviour SELECT ... LIMIT n FOR UPDATE  ("Daniel Caune" <daniel.caune@ubisoft.com>)
Responses Re: Strang behaviour SELECT ... LIMIT n FOR UPDATE  ("Daniel Caune" <daniel.caune@ubisoft.com>)
List pgsql-sql
"Daniel Caune" <daniel.caune@ubisoft.com> writes:
> I did the following test, removing all the where-clause from the SELECT statement.  Every statement completes
immediately,i.e. it doesn't block.
 

I think you left out some critical information, like who else was doing
what to the table.

What it looks like to me is that the third and fourth rows in this view
were live according to your transaction snapshot, but were committed
dead as of current time, and so FOR UPDATE wouldn't return them.

> agoratokens=> select id from "Tokens" where id IN (47, 104, 44, 42) limit 3 for update;
> This time, the statement returns the row where id equals to 44.

No, it returns *some* row where id equals 44.  Not necessarily the same
one seen in the seqscan.  (I imagine this query is using an index, and
so would visit rows in a different physical order.)  Printing the ctid
of the rows would confirm or disprove that theory.
        regards, tom lane


pgsql-sql by date:

Previous
From: "Daniel Caune"
Date:
Subject: Re: Strang behaviour SELECT ... LIMIT n FOR UPDATE
Next
From: "Daniel Caune"
Date:
Subject: Re: Strang behaviour SELECT ... LIMIT n FOR UPDATE