]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix misbehavior of CTE-used-in-a-subplan during EPQ rechecks.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 Feb 2018 21:00:18 +0000 (16:00 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 19 Feb 2018 21:00:18 +0000 (16:00 -0500)
commit795f2112ea284c6b4e33305e4110d1652cded200
treeab6274f9e4437c3fdf6391583924c245e6d7ae22
parentf68b52c9f9965aad1b0b9f9f8f6c5d08021ce810
Fix misbehavior of CTE-used-in-a-subplan during EPQ rechecks.

An updating query that reads a CTE within an InitPlan or SubPlan could get
incorrect results if it updates rows that are concurrently being modified.
This is caused by CteScanNext supposing that nothing inside its recursive
ExecProcNode call could change which read pointer is selected in the CTE's
shared tuplestore.  While that's normally true because of scoping
considerations, it can break down if an EPQ plan tree gets built during the
call, because EvalPlanQualStart builds execution trees for all subplans
whether they're going to be used during the recheck or not.  And it seems
like a pretty shaky assumption anyway, so let's just reselect our own read
pointer here.

Per bug #14870 from Andrei Gorita.  This has been broken since CTEs were
implemented, so back-patch to all supported branches.

Discussion: https://postgr.es/m/20171024155358.1471.82377@wrigleys.postgresql.org
src/backend/executor/nodeCtescan.c
src/test/isolation/expected/eval-plan-qual.out
src/test/isolation/specs/eval-plan-qual.spec