postgresql/src/backend
Tom Lane f330a6d140 Fix mishandling of FieldSelect-on-whole-row-Var in nested lateral queries.
If an inline-able SQL function taking a composite argument is used in a
LATERAL subselect, and the composite argument is a lateral reference,
the planner could fail with "variable not found in subplan target list",
as seen in bug #11703 from Karl Bartel.  (The outer function call used in
the bug report and in the committed regression test is not really necessary
to provoke the bug --- you can get it if you manually expand the outer
function into "LATERAL (SELECT inner_function(outer_relation))", too.)

The cause of this is that we generate the reltargetlist for the referenced
relation before doing eval_const_expressions() on the lateral sub-select's
expressions (cf find_lateral_references()), so what's scheduled to be
emitted by the referenced relation is a whole-row Var, not the simplified
single-column Var produced by optimizing the function's FieldSelect on the
whole-row Var.  Then setrefs.c fails to match up that lateral reference to
what's available from the outer scan.

Preserving the FieldSelect optimization in such cases would require either
major planner restructuring (to recursively do expression simplification
on sub-selects much earlier) or some amazingly ugly kluge to change the
reltargetlist of a possibly-already-planned relation.  It seems better
just to skip the optimization when the Var is from an upper query level;
the case is not so common that it's likely anyone will notice a few
wasted cycles.

AFAICT this problem only occurs for uplevel LATERAL references, so
back-patch to 9.3 where LATERAL was added.
2014-10-20 12:23:42 -04:00
..
access Message improvements 2014-10-12 01:06:35 -04:00
bootstrap Revert "Fix bogus %name-prefix option syntax in all our Bison files." 2014-05-28 19:21:01 -04:00
catalog Split builtins.h to a new header ruleutils.h 2014-10-08 18:10:47 -03:00
commands Shorten warning about hash creation 2014-10-18 10:36:09 -04:00
executor C comments: adjust execTuples.c for new structure 2014-10-13 16:54:38 -04:00
foreign Implement IMPORT FOREIGN SCHEMA. 2014-07-10 15:01:43 -04:00
lib pgindent run for 9.4 2014-05-06 12:12:18 -04:00
libpq Message improvements 2014-10-12 01:06:35 -04:00
main Add a basic atomic ops API abstracting away platform/architecture details. 2014-09-25 23:49:05 +02:00
nodes Avoid core dump in _outPathInfo() for Path without a parent RelOptInfo. 2014-10-17 22:33:52 -04:00
optimizer Fix mishandling of FieldSelect-on-whole-row-Var in nested lateral queries. 2014-10-20 12:23:42 -04:00
parser interval: tighten precision specification 2014-10-18 10:31:00 -04:00
po Translation updates 2014-10-05 23:23:50 -04:00
port Add a basic atomic ops API abstracting away platform/architecture details. 2014-09-25 23:49:05 +02:00
postmaster Eliminate one background-worker-related flag variable. 2014-10-04 21:25:41 -04:00
regex Fix incorrect search for "x?" style matches in creviterdissect(). 2014-09-23 20:26:14 -04:00
replication Fix typos. 2014-10-20 10:33:16 -04:00
rewrite Implement SKIP LOCKED for row-level locks 2014-10-07 17:23:34 -03:00
snowball Finish adding file version information to installed Windows binaries. 2014-08-18 22:59:53 -04:00
storage Fix deadlock with LWLockAcquireWithVar and LWLockWaitForVar. 2014-10-14 10:06:47 +03:00
tcop Log ALTER SYSTEM statements as DDL 2014-09-22 20:50:17 -04:00
tsearch pgindent run for 9.4 2014-05-06 12:12:18 -04:00
utils Fix typos. 2014-10-20 10:23:40 -04:00
.gitignore Add gitignore for mingw/cygwin build outputs 2011-06-09 18:11:47 +02:00
Makefile Get rid of use of dlltool in Mingw builds. 2014-02-11 12:56:20 -05:00
common.mk Remove maintainer-check target, fold into normal build 2013-10-10 20:11:56 -04:00
nls.mk Add libpgcommon to backend gettext source files 2013-10-19 13:49:05 -04:00