Re: Fwd: Dead lock

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Dave Crooke <dcrooke(at)gmail(dot)com>
Cc: Elias Ghanem <e(dot)ghanem(at)acteos(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Fwd: Dead lock
Date: 2010-06-14 20:44:26
Message-ID: AANLkTik4XC9oxIQFX4ei_Xyez4lPb00NENkbukhYr0DH@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On Mon, Jun 14, 2010 at 11:58 AM, Dave Crooke <dcrooke(at)gmail(dot)com> wrote:
> If you're doing straight SQL bulk updates, then as someone suggested, you could use an ORDER BY on a subquery, but I don't know if that is a guarantee, if you're not actually displaying the results then the DB may be technically allowed to optimize it out from underneath you. The only way to be sure is a cursor / procedure.

'order by' should be safe if you use SELECT...FOR UPDATE. update
doesn't have an order by clause. Using cursor/procedure vs a query
is not the material point; you have to make sure locks are acquired in
a regular way.

update foo set x=x where id in (select * from bar order by x) does
look dangerous.

I think:
update foo set x=x where id in (select * from bar order by x for update)
should be ok. I don't usually do it that way.

merlin

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Bruce Momjian 2010-06-14 20:46:11 Re: Re: Command Prompt 8.4.4 PRMs compiled with debug/assert enabled
Previous Message Scott Marlowe 2010-06-14 20:16:39 Re: query hangs