pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix parallel-safety marking when moving initplans to another nod
Date: Wed, 12 Apr 2023 14:46:48 +0000
Message-ID: <E1pmbkF-002iQc-Jy@gemulon.postgresql.org> (raw)

Fix parallel-safety marking when moving initplans to another node.

Our policy since commit ab77a5a45 has been that a plan node having
any initplans is automatically not parallel-safe.  (This could be
relaxed, but not today.)  clean_up_removed_plan_level neglected
this, and could attach initplans to a parallel-safe child plan
node without clearing the plan's parallel-safe flag.  That could
lead to "subplan was not initialized" errors at runtime, in case
an initplan referenced another one and only the referencing one
got transmitted to parallel workers.

The fix in clean_up_removed_plan_level is trivial enough.
materialize_finished_plan also moves initplans from one node
to another, but it's okay because it already copies the source
node's parallel_safe flag.  The other place that does this kind
of thing is standard_planner's hack to inject a top-level Gather
when debug_parallel_query is active.  But that's actually dead
code given that we're correctly enforcing the "initplans aren't
parallel safe" rule, so just replace it with an Assert that
there are no initplans.

Also improve some related comments.

Normally we'd add a regression test case for this sort of bug.
The mistake itself is already reached by existing tests, but there
is accidentally no visible problem.  The only known test case that
creates an actual failure seems too indirect and fragile to justify
keeping it as a regression test (not least because it fails to fail
in v11, though the bug is clearly present there too).

Per report from Justin Pryzby.  Back-patch to all supported branches.

Discussion: https://postgr.es/m/ZDVt6MaNWkRDO1LQ@telsasoft.com

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/953ff99c20c5c7fbb7329a80d82722e31e462a43

Modified Files
--------------
src/backend/optimizer/plan/planner.c   |  8 +++-----
src/backend/optimizer/plan/setrefs.c   | 14 +++++++++++++-
src/backend/optimizer/plan/subselect.c |  8 +++++---
src/backend/optimizer/util/pathnode.c  |  2 +-
4 files changed, 22 insertions(+), 10 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1pmbkF-002iQc-Jy@gemulon.postgresql.org>
Permalink:  ../E1pmbkF-002iQc-Jy@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1pmbkF-002iQc-Jy@gemulon.postgresql.org

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix parallel-safety marking when moving initplans to another nod
  In-Reply-To: <E1pmbkF-002iQc-Jy@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