Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TK9wy-0005kt-3H for pgsql-performance@postgresql.org; Fri, 05 Oct 2012 15:36:28 +0000 Received: from moutng.kundenserver.de ([212.227.17.8]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TK9ww-0007po-BF for pgsql-performance@postgresql.org; Fri, 05 Oct 2012 15:36:27 +0000 Received: from alap2.localnet (p549F1993.dip.t-dialin.net [84.159.25.147]) by mrelayeu.kundenserver.de (node=mrbap4) with ESMTP (Nemesis) id 0LdmTL-1Tk6te0uBP-00iWrN; Fri, 05 Oct 2012 17:36:17 +0200 From: Andres Freund Organization: 2ndQuadrant.com To: pgsql-performance@postgresql.org Subject: Re: how to avoid deadlock on masive update with multiples delete Date: Fri, 5 Oct 2012 17:36:14 +0200 User-Agent: KMail/1.13.7 (Linux/3.5.0-rc3-andres-00231-g002b758; KDE/4.8.4; x86_64; ; ) Cc: Tom Lane , Maciek Sakrejda , Claudio Freire , Jeff Janes , Anibal David Acosta References: <005701cda238$ba4d0350$2ee709f0$@devshock.com> <9895.1349451103@sss.pgh.pa.us> In-Reply-To: <9895.1349451103@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Message-Id: <201210051736.16460.andres@2ndquadrant.com> X-Provags-ID: V02:K0:W/8BmYVeInhhbYwsoXXLsipQdjd2ttpSdGPAYo/WWJ5 CTpJUbToYmrZomgIZalcYwSPAaz+IZBN/UV1d7EJ8GGMqOoDeH MeACJz8DFRhr8XqTSV3pNJevIlfMC2ag4xpNGQuB4kaHyHN8UA nW5q/l7iSy23FGiBtwnyOSkuihp1scvRHSvWWcPk2l4X5CVd9u /qn9E97YRi8wYa9en9X/ZcePwATmndrf43ZA6dWXpk43Ort/6s tURRiXSJxng+PxzbmpV6Q2+L86Fa23aF85QjkV3xE7ERL//GBp MbZkbev00otE+iEftp+eZ1cRXiJ5czueihYR61SfawsvFjDIfb /xMjCbv02ZB48oW2XGA81fZ1VWKH+QdN0UiGjNHtOk9p2RRhn2 6IP0kB/0b0dSw== X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201210/30 X-Sequence-Number: 47989 On Friday, October 05, 2012 05:31:43 PM Tom Lane wrote: > Maciek Sakrejda writes: > > Presumably something like this?: > > maciek=# CREATE TABLE test AS SELECT g, random() FROM > > generate_series(1,1000) g; > > CREATE > > maciek=# EXPLAIN DELETE FROM test USING (SELECT g FROM test ORDER BY > > ctid) x where x.g = test.g; > > There's no guarantee that the planner won't re-sort the rows coming from > the sub-select, unfortunately. More often than not you can prevent the planner from doing that by putting a OFFSET 0 in the query. Not 100% but better than nothing. We really need ORDER BY for DML. Andres -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services