pgsql: Don't evaluate the FOR PORTION OF target under EXPLAIN

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Don't evaluate the FOR PORTION OF target under EXPLAIN
Date: 2026-09-08 13:31:26
Message-ID: E1x3vv2-00000003zyU-4ALA@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Don't evaluate the FOR PORTION OF target under EXPLAIN

ExecInitModifyTable() evaluated ForPortionOfExpr.targetRange
unconditionally at executor start-up, with no EXEC_FLAG_EXPLAIN_ONLY
guard. This caused three problems:

- EXPLAIN (GENERIC_PLAN) failed with "no value found for parameter 1".

- Plain EXPLAIN with FOR PORTION OF (null) raised "FOR PORTION OF
target must not be null".

- Plain EXPLAIN ran user functions appearing in the target a second
time, beyond the one evaluation the planner already does for
selectivity estimation.

Now we skip the evaluation and the accompanying null check in
explain-only mode.

Reported-by: Noah Misch <noah(at)leadboat(dot)com>
Author: Paul A. Jungwirth <pj(at)illuminatedcomputing(dot)com>
Discussion: https://www.postgresql.org/message-id/flat/CA%2BrenyXci9khYXJ8uSwzF30DVw%2Bzc4QwGb1RdsuOu_YtrFuy1g%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/140fdfcdf12d524541ff26491b8e2076a690e434

Modified Files
--------------
src/backend/executor/nodeModifyTable.c | 40 +++++++------
src/test/regress/expected/for_portion_of.out | 89 ++++++++++++++++++++++++++++
src/test/regress/sql/for_portion_of.sql | 44 ++++++++++++++
3 files changed, 156 insertions(+), 17 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2026-09-08 15:08:21 pgsql: pg_stash_advice: Fix failure to reload empty advice string.
Previous Message Álvaro Herrera 2026-09-08 12:07:54 pgsql: Reject REPACK (ANALYZE) in a transaction block