pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marko Tiikkaja <marko@joh.to>
Cc: Andrei Gorita <andreigorita@gmail.com>
Cc: Pg Bugs <pgsql-bugs@postgresql.org>
Subject: Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE
Date: Mon, 19 Feb 2018 16:05:39 -0500
Message-ID: <2125.1519074339@sss.pgh.pa.us> (raw)
In-Reply-To: <7584.1519069396@sss.pgh.pa.us>
References: <20171024155358.1471.82377@wrigleys.postgresql.org>
	<CAL9smLBOO8w9j2Y0zrRcdt-Kw2hiC8Ntdwro1FDq=j+z8Q9LqA@mail.gmail.com>
	<CAL9smLAa=LZTaN6Xm_cqY8mXCiQNB9FXLXr6thgtBi5Fo8WtEQ@mail.gmail.com>
	<7584.1519069396@sss.pgh.pa.us>

I wrote:
> The answer turns out to be that if EPQ is fired, then we instantiate a new
> copy of the whole outer plan tree (though apparently not the InitPlan),
> resulting in an additional ExecInitCteScan call that allocates an
> additional read pointer on the same tuplestore, and it's that one being
> the active one that causes the observed misbehavior.

Oh, on closer inspection I had that backwards: the EPQ plan tree would
normally contain only the child node(s) of the ModifyTable node, but
EvalPlanQualStart also duplicates all InitPlan or SubPlan node trees,
because it can't tell which of them might get used within the EPQ subtree.
So we get one extra ExecInitCteScan call, even though no actual access
to the tuplestore could happen.

So we can now characterize the problem case as "CTE is read within an
InitPlan or SubPlan, and the query as a whole encounters an EPQ recheck".

			regards, tom lane




view thread (6+ messages)

Message-ID: <2125.1519074339@sss.pgh.pa.us>
Permalink:  ../2125.1519074339@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2125.1519074339@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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, marko@joh.to, andreigorita@gmail.com
  Subject: Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE
  In-Reply-To: <2125.1519074339@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