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

Started by Peter Eisentraut3 months ago1 messagescommitters
Jump to latest
#1Peter Eisentraut
peter@eisentraut.org

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@leadboat.com>
Author: Paul A. Jungwirth <pj@illuminatedcomputing.com>
Discussion: /messages/by-id/CA+renyXci9khYXJ8uSwzF30DVw+zc4QwGb1RdsuOu_YtrFuy1g@mail.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(-)