Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VncB3-0002Ur-3G for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Dec 2013 22:41:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VncB1-0005B7-OW for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Dec 2013 22:41:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VncB1-0005B1-6b for pgsql-bugs@postgresql.org; Mon, 02 Dec 2013 22:41:15 +0000 Received: from moutng.kundenserver.de ([212.227.126.186]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VncAy-00052W-7I for pgsql-bugs@postgresql.org; Mon, 02 Dec 2013 22:41:14 +0000 Received: from anarazel.de (p5DDC640C.dip0.t-ipconnect.de [93.220.100.12]) by mrelayeu.kundenserver.de (node=mreu4) with ESMTP (Nemesis) id 0Lrlu6-1VcIMi3ZAE-013iGT; Mon, 02 Dec 2013 23:41:11 +0100 Received: by anarazel.de (Postfix, from userid 1000) id 2BAF9100BE5; Mon, 2 Dec 2013 23:41:10 +0100 (CET) Date: Mon, 2 Dec 2013 23:41:10 +0100 From: Andres Freund To: Oliver Seemann Cc: pgsql-bugs@postgresql.org Subject: Re: Update with subselect sometimes returns wrong result Message-ID: <20131202224110.GA30079@awork2.anarazel.de> References: <20131201121209.GH18793@alap2.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Provags-ID: V02:K0:CgkTgocAvpwL1aHRK283Iy9jsi6OseXNQnMtuK71uO+ FOqzWdJ66YbjtsktqlyerGTXhKIu6rDd77QHCPWeWq8VrabUY8 AviUIT3Bo4TNX41xSKiiFYOG/akDzNvjxuz9khU1GBoRGVfrAG pea7F886uQ8+8zhbyPwXkDW2136Oa+b86CSFLv2KglM2Iq0VF8 WBtRF8P8ht5LBo9sK0LVijmwkOWGttJ2ZBBKuaoKomu6bPGeDQ BQ5rBWPVfzP2MCDKP0UFch4riBWlAUsSuLEPbYjDWQzAMs9Sd/ WufE888P/C6lBroVbp3thmjQ2nUmO0rXUKF1/8zD8JdlWSDhuf YXJ4WYkXajsTAIL5+BefjQSSDvNlqaIpdxsDIySxp X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 2013-12-02 22:55:30 +0100, Oliver Seemann wrote: > 2013/12/1 Andres Freund : > > To get rid of that ambiguity, I suggest rewriting the query to look > > like: > > WITH locked_row AS ( > > SELECT id FROM t1 LIMIT 1 FOR UPDATE > > ) > > UPDATE t1 SET id = t1.id > > FROM (SELECT * FROM locked_row) locked > > WHERE t1.id = locked.id > > RETURNING t1.id; > > Thanks for looking into this and even providing a workaround! > > The patch you posted previously is incomplete, right? Because I can > still trigger the problem with the patch applied on top of git master. > (I use autovacuum_naptime = 1s to reliably trigger within 1-5 seconds). The patch isn't for this issue, it's for something Tom noticed while investigating it. Purely a performance optimization/fix for a performance regression - albeit a noticeable one. I'd judge that there's about zero chance that the issue can be fixed in the stable branches, the likelihood of breaking other working code due to the require semantic changes are far too great. Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs