pgsql: Fix EXPLAIN of dummy set operations some more. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix EXPLAIN of dummy set operations some more.
Date
Msg-id E1xDkv6-00000000Quc-0gAV@gemulon.postgresql.org
Whole thread
List pgsql-committers
Fix EXPLAIN of dummy set operations some more.

EXPLAIN failed to deal with varno-0 Vars that are made by prepunion.c
and can survive into a finished plan in the case where a provably
empty set operation is replaced by a dummy Result (which is possible
since 03d40e4b5).  Commit 928df067d tried to fix this, but it was a
couple bricks shy of a load.  First, it only dealt with varno-0 Vars
at the top level of the Result's tlist, but they could be buried
under coercion expressions.  Fix that by doing a recursive mutation.
Second, it always replaced varno 0 with varno 1, but that's just
wrong: the Result might represent a group of setop leaf queries that
do not include the leftmost leaf.  That led to displaying the wrong
variable(s) as outputs of the Result, risking confusion.  Fortunately,
we can get the actual child relids from the recently-added
Result.relids field, and use that to discover the leftmost child
represented by the Result.

This was found while discussing bug #19742, but it's really an
independent issue.

Author: shihao zhong <zhong950419@gmail.com>
Co-authored-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAGRkXqTFwygKmjLG_Y=kbXRHsePFmD6k+qrzVLP4_KrG+-=oRg@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/3e3edd1a6147a5c1b88464bc827add54d3fe50ad

Modified Files
--------------
src/backend/optimizer/plan/setrefs.c | 69 ++++++++++++++++++++++++++----------
src/test/regress/expected/union.out  | 20 +++++++++++
src/test/regress/sql/union.sql       |  9 +++++
3 files changed, 79 insertions(+), 19 deletions(-)


pgsql-committers by date:

Previous
From: David Rowley
Date:
Subject: pgsql: Fix tuplesort memory accounting for datum sorts on byref types
Next
From: Tom Lane
Date:
Subject: pgsql: Don't absorb child pathkeys into dummy AppendPaths for set-ops.