Re: Trx issues: SELECT FOR UPDATE LIMIT - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Trx issues: SELECT FOR UPDATE LIMIT
Date
Msg-id 22264.1051715264@sss.pgh.pa.us
Whole thread Raw
In response to Trx issues: SELECT FOR UPDATE LIMIT  (James Mancz <james@mancz.com>)
List pgsql-hackers
James Mancz <james@mancz.com> writes:
> client 2 can carry on processing now, 
> and its SELECT * FROM work WHERE alloc IS NULL LIMIT 1 FOR UPDATE;
> **returns no rows** despite the fact the second row matches.

This is annoying but I do not think it is readily fixable, because the
LIMIT filter acts before the FOR UPDATE processing.  When FOR UPDATE
rejects the first row because it's been changed by the previous updater,
that's all she wrote --- the LIMIT's not gonna produce more rows.

I have some old notes suggesting that maybe FOR UPDATE could be turned
into a plan node that could be stuck underneath the LIMIT node, but
I'm not sure that's workable.  It'd be a nontrivial change certainly,
and arguably unintuitive (the effects of SQL clauses normally act
left-to-right, but you'd be forcing LIMIT to occur after FOR UPDATE).

Those other databases presumably implement LIMIT in a different place
... I bet they don't handle LIMIT in sub-selects though, which is the
advantage to treating it as a plan step.
        regards, tom lane



pgsql-hackers by date:

Previous
From: James Mancz
Date:
Subject: Trx issues: SELECT FOR UPDATE LIMIT
Next
From: "John Liu"
Date:
Subject: pattern match, index use and performance