Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: Andrei Gorita <andreigorita(at)gmail(dot)com>, Pg Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE
Date: 2018-02-19 21:05:39
Message-ID: 2125.1519074339@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Sudalai 2018-02-20 11:00:07 Re: Segmentation Fault in logical decoding get/peek API
Previous Message Tom Lane 2018-02-19 19:43:16 Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE