postgresql/src/backend
Tom Lane f449873623 Ensure that RowExprs and whole-row Vars produce the expected 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.
That did not work terribly well before this patch: 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().

To fix this for whole-row Vars, look to the RTE referenced by the Var, and
make sure its column aliases are applied to the rowtype associated with
the result Datums.  This is a tad scary because we might have to return
a transient RECORD type even though the Var is declared as having some
named rowtype.  In principle it should be all right because the record
type will still be physically compatible with the named rowtype; but
I had to weaken one Assert in ExecEvalConvertRowtype, and there might be
third-party code containing similar assumptions.

Similarly, RowExprs have to be willing to override the column names coming
from a named composite result type and produce a RECORD when the column
aliases visible at the site of the RowExpr differ from the underlying
table's column names.

In passing, revert the decision made in commit 398f70ec07 to add
an alias-list argument to ExecTypeFromExprList: better to provide that
functionality in a separate function.  This also reverts most of the code
changes in d685814835, which we don't need because we're no longer
depending on the tupdesc found in the child plan node's result slot to be
blessed.

Back-patch to 9.4, but not earlier, since this solution changes the results
in some cases that users might not have realized were buggy.  We'll apply a
more restricted form of this patch in older branches.
2014-11-10 15:21:14 -05:00
..
access Fix generation of SP-GiST vacuum WAL records. 2014-11-07 21:18:34 +02:00
bootstrap Revert "Fix bogus %name-prefix option syntax in all our Bison files." 2014-05-28 19:21:01 -04:00
catalog Remove obsolete commentary. 2014-10-28 18:36:16 -04:00
commands Drop no-longer-needed buffers during ALTER DATABASE SET TABLESPACE. 2014-11-04 13:24:10 -05:00
executor Ensure that RowExprs and whole-row Vars produce the expected column names. 2014-11-10 15:21:14 -05:00
foreign Update copyright for 2014 2014-01-07 16:05:30 -05:00
lib pgindent run for 9.4 2014-05-06 12:12:18 -04:00
libpq Message improvements 2014-10-12 01:02:56 -04:00
main Make fallback implementation of pg_memory_barrier() work. 2014-05-17 18:29:46 -04:00
nodes Avoid core dump in _outPathInfo() for Path without a parent RelOptInfo. 2014-10-17 22:33:04 -04:00
optimizer Improve planning of btree index scans using ScalarArrayOpExpr quals. 2014-10-26 16:12:26 -04:00
parser Support ALTER SYSTEM RESET command. 2014-09-12 23:15:04 +09:00
po Translation updates 2014-10-05 23:22:24 -04:00
port Fix spinlock implementation for some !solaris sparc platforms. 2014-09-09 23:36:32 +02:00
postmaster Eliminate one background-worker-related flag variable. 2014-10-04 22:15:06 -04:00
regex Fix incorrect search for "x?" style matches in creviterdissect(). 2014-09-23 20:26:21 -04:00
replication Improve documentation about binary/textual output mode for output plugins. 2014-10-01 13:21:59 +02:00
rewrite Assorted message improvements 2014-08-29 00:01:34 -04:00
snowball Fix ancient encoding error in hungarian.stop. 2014-06-10 22:48:31 -04:00
storage "Pin", rather than "keep", dynamic shared memory mappings and segments. 2014-10-30 11:44:22 -04:00
tcop Log ALTER SYSTEM statements as DDL 2014-09-22 20:52:56 -04:00
tsearch Cope with more than 64K phrases in a thesaurus dictionary. 2014-11-06 20:52:47 -05:00
utils Fix normalization of numeric values in JSONB GIN indexes. 2014-11-06 11:41:18 -05:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
Makefile Get rid of use of dlltool in Mingw builds. 2014-02-11 12:56:20 -05:00
nls.mk Add libpgcommon to backend gettext source files 2013-10-19 13:49:05 -04:00