pgsql: Ensure that whole-row Vars produce nonempty column names.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Ensure that whole-row Vars produce nonempty column names.
Date: 2014-11-10 20:21:36
Message-ID: E1XnvSy-0005yA-9V@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Ensure that whole-row Vars produce nonempty column names.

At one time it wasn't terribly important what column names were associated
with the fields of a composite Datum, but since the introduction of
operations like row_to_json(), it's important that looking up the rowtype
ID embedded in the Datum returns the column names that users would expect.
However, that doesn't work terribly well: you could get the column names
of the underlying table, or column aliases from any level of the query,
depending on minor details of the plan tree. You could even get totally
empty field names, which is disastrous for cases like row_to_json().

It seems unwise to change this behavior too much in stable branches,
however, since users might not have noticed that they weren't getting
the least-unintuitive choice of field names. Therefore, in the back
branches, only change the results when the child plan has returned an
actually-empty field name. (We assume that can't happen with a named
rowtype, so this also dodges the issue of possibly producing RECORD-typed
output from a Var with a named composite result type.) As in the sister
patch for HEAD, we can get a better name to use from the Var's
corresponding RTE. There is no need to touch the RowExpr code since it
was already using a copy of the RTE's alias list for RECORD cases.

Back-patch as far as 9.2. Before that we did not have row_to_json()
so there were no core functions potentially affected by bogus field
names. While 9.1 and earlier do have contrib's hstore(record) which
is also affected, those versions don't seem to produce empty field names
(at least not in the known problem cases), so we'll leave them alone.

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/07ab4ec4cf5447d79828bb536dcc69b16e0cd4f7

Modified Files
--------------
src/backend/executor/execQual.c | 95 ++++++++++++-------
src/backend/executor/execTuples.c | 43 +++++++++
src/include/executor/executor.h | 1 +
src/include/nodes/execnodes.h | 1 +
src/test/regress/expected/rowtypes.out | 160 ++++++++++++++++++++++++++++++++
src/test/regress/sql/rowtypes.sql | 44 +++++++++
6 files changed, 313 insertions(+), 31 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2014-11-10 20:30:46 pgsql: Fix potential NULL-pointer dereference.
Previous Message Alvaro Herrera 2014-11-10 19:13:45 pgsql: Further code and wording tweaks in BRIN