From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Fix misbehavior of CTE-used-in-a-subplan during EPQ rechecks.
Date: Mon, 19 Feb 2018 21:00:41 +0000
Message-ID: <E1ensYD-0001Pi-D2@gemulon.postgresql.org> (raw)
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
Branch
------
REL9_4_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/e11b6488e5a70f870bc7069d7f08a9570ccd3fc2
Modified Files
--------------
src/backend/executor/nodeCtescan.c | 13 +++++++++++++
src/test/isolation/expected/eval-plan-qual.out | 15 +++++++++++++++
src/test/isolation/specs/eval-plan-qual.spec | 9 +++++++++
3 files changed, 37 insertions(+)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Fix misbehavior of CTE-used-in-a-subplan during EPQ rechecks.
In-Reply-To: <E1ensYD-0001Pi-D2@gemulon.postgresql.org>
References: <E1ensYD-0001Pi-D2@gemulon.postgresql.org>
* 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