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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Ensure that whole-row Vars produce nonempty column names.
Дата
Msg-id E1XnvSy-0005yC-9a@gemulon.postgresql.org
обсуждение исходный текст
Список 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_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/19ccaf9d4685909257b9f0472916026b8c7eff0a

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 |  161 ++++++++++++++++++++++++++++++++
src/test/regress/sql/rowtypes.sql      |   44 +++++++++
6 files changed, 314 insertions(+), 31 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Ensure that whole-row Vars produce nonempty column names.
Следующее
От: Robert Haas
Дата:
Сообщение: pgsql: Fix potential NULL-pointer dereference.