Re: [BUGS] BUG #14870: wrong query results when using WITH with UPDATE
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marko Tiikkaja <marko@joh.to>
Cc: Andrei Gorita <andreigorita@gmail.com>,
Pg Bugs <pgsql-bugs@postgresql.org>
Date: 2018-02-19T21:05:39Z
Lists: pgsql-bugs
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix misbehavior of CTE-used-in-a-subplan during EPQ rechecks.
- 159efe4af450 11.0 landed
- ea6d67cf8e01 9.3.22 landed
- e11b6488e5a7 9.4.17 landed
- 795f2112ea28 9.6.8 landed
- 517e0fe866c6 10.3 landed
- 340d63bfb369 9.5.12 landed
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