From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix EXPLAIN's column alias output for mismatched child tables.
Date: Tue, 03 Dec 2019 00:08:19 +0000
Message-ID: <E1ibvjn-0001RQ-1x@gemulon.postgresql.org> (raw)
Fix EXPLAIN's column alias output for mismatched child tables.
If an inheritance/partitioning parent table is assigned some column
alias names in the query, EXPLAIN mapped those aliases onto the
child tables' columns by physical position, resulting in bogus output
if a child table's columns aren't one-for-one with the parent's.
To fix, make expand_single_inheritance_child() generate a correctly
re-mapped column alias list, rather than just copying the parent
RTE's alias node. (We have to fill the alias field, not just
adjust the eref field, because ruleutils.c will ignore eref in
favor of looking at the real column names.)
This means that child tables will now always have alias fields in
plan rtables, where before they might not have. That results in
a rather substantial set of regression test output changes:
EXPLAIN will now always show child tables with aliases that match
the parent table (usually with "_N" appended for uniqueness).
But that seems like a net positive for understandability, since
the parent alias corresponds to something that actually appeared
in the original query, while the child table names didn't.
(Note that this does not change anything for cases where an explicit
table alias was written in the query for the parent table; it
just makes cases without such aliases behave similarly to that.)
Hence, while we could avoid these subsidiary changes if we made
inherit.c more complicated, we choose not to.
Discussion: https://postgr.es/m/12424.1575168015@sss.pgh.pa.us
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/55a1954da16e041f895e5c3a6abff13c5e3a4a2f
Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out | 296 ++--
src/backend/optimizer/util/inherit.c | 74 +-
src/test/regress/expected/aggregates.out | 52 +-
src/test/regress/expected/alter_table.out | 18 +-
src/test/regress/expected/inherit.out | 486 +++---
src/test/regress/expected/partition_aggregate.out | 762 ++++-----
src/test/regress/expected/partition_join.out | 228 +--
src/test/regress/expected/partition_prune.out | 1765 +++++++++++----------
src/test/regress/expected/rowsecurity.out | 128 +-
src/test/regress/expected/select_parallel.out | 56 +-
src/test/regress/expected/tablesample.out | 14 +-
src/test/regress/expected/union.out | 12 +-
src/test/regress/expected/updatable_views.out | 96 +-
src/test/regress/expected/update.out | 32 +-
src/test/regress/expected/with.out | 30 +-
src/test/regress/sql/partition_prune.sql | 5 +
16 files changed, 2072 insertions(+), 1982 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Fix EXPLAIN's column alias output for mismatched child tables.
In-Reply-To: <E1ibvjn-0001RQ-1x@gemulon.postgresql.org>
References: <E1ibvjn-0001RQ-1x@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