pgsql: Fix EXPLAIN's column alias output for mismatched child tables. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix EXPLAIN's column alias output for mismatched child tables.
Date
Msg-id E1ibvjn-0001RQ-1x@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
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(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Add a reverse-translation column number array to struct AppendRe
Next
From: Michael Paquier
Date:
Subject: pgsql: Fix failures with TAP tests of pg_ctl on Windows