Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vn14c-000413-Ei for pgsql-bugs@arkaria.postgresql.org; Sun, 01 Dec 2013 07:04:10 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Vn14b-0007KJ-Ph for pgsql-bugs@arkaria.postgresql.org; Sun, 01 Dec 2013 07:04:09 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vn14Z-0007KA-PN for pgsql-bugs@postgresql.org; Sun, 01 Dec 2013 07:04:07 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Vn14S-0003cc-Iy for pgsql-bugs@postgresql.org; Sun, 01 Dec 2013 07:04:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id rB173tB3022631; Sun, 1 Dec 2013 02:03:55 -0500 From: Tom Lane To: Andres Freund cc: Oliver Seemann , pgsql-bugs@postgresql.org Subject: Re: Update with subselect sometimes returns wrong result In-reply-to: <22220.1385880062@sss.pgh.pa.us> References: <25601.1385834264@sss.pgh.pa.us> <20131130214018.GJ31100@awork2.anarazel.de> <22220.1385880062@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Sun, 01 Dec 2013 01:41:02 -0500" Date: Sun, 01 Dec 2013 02:03:55 -0500 Message-ID: <22630.1385881435@sss.pgh.pa.us> 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 I wrote: > Anyway, at this point I'm not so much wondering why it fails as why it > (seems to) work *any* of the time. And how is it that VACUUM sometimes > manages to flip it from working state to not-working state? (Once you're > in the state where the UPDATE will say it updated two rows, it's 100% > reproducible.) Oh, hah; the case where it works is where the generated plan is the other way around: Update on t1 -> Nested Loop Join Filter: (t1.id = subset.id) -> Subquery Scan on subset -> Limit -> LockRows -> Seq Scan on t1 t1_1 -> Seq Scan on t1 so that we never rescan the LockRows node. heap_lock_tuple followed by heap_update works sanely, the other way round not so much. The apparent dependency on VACUUM is probably coming from updating the table's relpages/reltuples counts to new values in a way that causes the planner to think one version or the other is a bit cheaper. I'd still kind of like to know how HEAP_XMAX_IS_MULTI is getting involved, but it seems that the fundamental problem here is we haven't thought through what the interactions of LockRows and ModifyTable operations in the same query ought to be. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs