PL/pgSQL: allow parallel query for assignment statements

From: Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: PL/pgSQL: allow parallel query for assignment statements
Date: 2026-10-26 08:58:17
Message-ID: CAM2+6=VhgjTT=uENuDd4nk22abiW9nrLZZqnOKc9n_DYCL6AXQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Commit 61c2e1a95f ("Improve access to parallel query from procedural
languages") made exec_eval_expr() prepare expressions with
CURSOR_OPT_PARALLEL_OK, so that queries in IF, RETURN, RAISE, etc. can use
parallel plans. It missed exec_assign_expr(), which creates the plan
itself,
with cursorOptions 0, before calling exec_eval_expr(). As the plan already
exists by then, the PARALLEL_OK prepare in exec_eval_expr() never runs.

As a result, a query used in an assignment never gets a parallel plan:
x := sum(a) from tab;
while the same query used in, say, an IF condition can. The same applies to
DECLARE default expressions, which also go through exec_assign_expr().

The pre-planning in exec_assign_expr() is redundant, since exec_eval_expr()
creates the plan if needed, so the attached patch just removes it.

The patch also adds regression tests to select_parallel.sql, one for an
assignment statement and one for a DECLARE default. Each provokes an error
in a worker with debug_parallel_query = 1 and checks for the "parallel
worker" context line. Both tests fail without the fix.

Thoughts?

Thanks

--
*Jeevan Chalke*
*Senior Principal Engineer, Engineering Manager*
*Product Development*

enterprisedb.com <https://www.enterprisedb.com>

Attachment Content-Type Size
v1-0001-Allow-parallel-query-for-PL-pgSQL-assignment-stat.patch application/octet-stream 4.3 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Tender Wang 2026-10-26 09:05:03 Re: Self-join elimination discards differing row lock wait policies
Previous Message Ajin Cherian 2026-10-26 08:30:42 Re: Incorrect CONTEXT reported for errors from parallel apply worker in logical replication