pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@2ndquadrant.com>
Cc: Oliver Seemann <oseemann@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: Update with subselect sometimes returns wrong result
Date: Sun, 01 Dec 2013 02:03:55 -0500
Message-ID: <22630.1385881435@sss.pgh.pa.us> (raw)
In-Reply-To: <22220.1385880062@sss.pgh.pa.us>
References: <CANCipfpfzoYnOz5jj=UZ70_R=CwDHv36dqWSpwsi27vpm1z5sA@mail.gmail.com>
	<25601.1385834264@sss.pgh.pa.us>
	<20131130214018.GJ31100@awork2.anarazel.de>
	<22220.1385880062@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (24+ messages)  latest in thread

Message-ID: <22630.1385881435@sss.pgh.pa.us>
Permalink:  ../22630.1385881435@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/22630.1385881435@sss.pgh.pa.us

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, andres@2ndquadrant.com, oseemann@gmail.com
  Subject: Re: Update with subselect sometimes returns wrong result
  In-Reply-To: <22630.1385881435@sss.pgh.pa.us>
  References: <CANCipfpfzoYnOz5jj=UZ70_R=CwDHv36dqWSpwsi27vpm1z5sA@mail.gmail.com> <25601.1385834264@sss.pgh.pa.us> <20131130214018.GJ31100@awork2.anarazel.de> <22220.1385880062@sss.pgh.pa.us> <22630.1385881435@sss.pgh.pa.us>

* 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