pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Headland <pheadland@actuate.com>
To: pgsql-general@postgresql.org
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Subject: Race hazard deleting using CTID?
Date: Tue, 11 Aug 2009 11:29:26 -0700
Message-ID: <71F491F5DA99604A80DE49424BF3D02B0C7293A0@exchange8.actuate.com> (raw)
In-Reply-To: <162867790908111022y48e65d31kcf5a037c1b41857f@mail.gmail.com>
References: <71F491F5DA99604A80DE49424BF3D02B0C7290CA@exchange8.actuate.com>
	<20090811062503.86993bf6.darcy@druid.net>
	<162867790908110355g3b62cc56u1c74092dd01bbd8e@mail.gmail.com>
	<71F491F5DA99604A80DE49424BF3D02B0C7292EF@exchange8.actuate.com>
	<162867790908111022y48e65d31kcf5a037c1b41857f@mail.gmail.com>

I believe that the following statement was originally suggested by Tom Lane; I got it from Pavel Stehule's PostgreSQL Tips page.
My question is, does this code contain a race hazard, because the list from the SELECT might get changed by another session before the DELETE uses it?

  delete from del where ctid = any(array(select ctid from del limit 10))

If so, am I correct to think that adding FOR UPDATE to create the version below would eliminate the hazard?

  delete from del where ctid = any(array(select ctid from del limit 10 for update))

-- 
Peter Headland
Architect
Actuate Corporation



view thread (3+ messages)  latest in thread

Message-ID: <71F491F5DA99604A80DE49424BF3D02B0C7293A0@exchange8.actuate.com>
Permalink:  ../71F491F5DA99604A80DE49424BF3D02B0C7293A0@exchange8.actuate.com/
Also on:    postgresql.org/message-id/71F491F5DA99604A80DE49424BF3D02B0C7293A0@exchange8.actuate.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pheadland@actuate.com, pgsql-general@postgresql.org, tgl@sss.pgh.pa.us, pavel.stehule@gmail.com
  Subject: Re: Race hazard deleting using CTID?
  In-Reply-To: <71F491F5DA99604A80DE49424BF3D02B0C7293A0@exchange8.actuate.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox