Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE - Mailing list pgsql-bugs

From Tom Lane
Subject Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE
Date
Msg-id 2125.1519074339@sss.pgh.pa.us
Whole thread Raw
In response to Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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


pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE
Next
From: Sudalai
Date:
Subject: Re: Segmentation Fault in logical decoding get/peek API