]> granicus.if.org Git - postgresql/commit
Implement SQL-standard LATERAL subqueries.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 7 Aug 2012 23:02:54 +0000 (19:02 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 7 Aug 2012 23:02:54 +0000 (19:02 -0400)
commit5ebaaa49445eb1ba7b299bbea3a477d4e4c0430b
tree1a72c939a655e9acbba1c71a1831dd38ee41db95
parent5078be480412790e4f1b2aeda04f8c65fc7a3b93
Implement SQL-standard LATERAL subqueries.

This patch implements the standard syntax of LATERAL attached to a
sub-SELECT in FROM, and also allows LATERAL attached to a function in FROM,
since set-returning function calls are expected to be one of the principal
use-cases.

The main change here is a rewrite of the mechanism for keeping track of
which relations are visible for column references while the FROM clause is
being scanned.  The parser "namespace" lists are no longer lists of bare
RTEs, but are lists of ParseNamespaceItem structs, which carry an RTE
pointer as well as some visibility-controlling flags.  Aside from
supporting LATERAL correctly, this lets us get rid of the ancient hacks
that required rechecking subqueries and JOIN/ON and function-in-FROM
expressions for invalid references after they were initially parsed.
Invalid column references are now always correctly detected on sight.

In passing, remove assorted parser error checks that are now dead code by
virtue of our having gotten rid of add_missing_from, as well as some
comments that are obsolete for the same reason.  (It was mainly
add_missing_from that caused so much fudging here in the first place.)

The planner support for this feature is very minimal, and will be improved
in future patches.  It works well enough for testing purposes, though.

catversion bump forced due to new field in RangeTblEntry.
41 files changed:
doc/src/sgml/keywords.sgml
doc/src/sgml/queries.sgml
doc/src/sgml/ref/select.sgml
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/geqo/geqo_eval.c
src/backend/optimizer/path/allpaths.c
src/backend/optimizer/path/costsize.c
src/backend/optimizer/path/joinpath.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/plan/initsplan.c
src/backend/optimizer/plan/planner.c
src/backend/optimizer/plan/subselect.c
src/backend/optimizer/prep/prepjointree.c
src/backend/optimizer/util/pathnode.c
src/backend/optimizer/util/var.c
src/backend/parser/analyze.c
src/backend/parser/gram.y
src/backend/parser/parse_agg.c
src/backend/parser/parse_clause.c
src/backend/parser/parse_expr.c
src/backend/parser/parse_relation.c
src/backend/parser/parse_target.c
src/backend/utils/adt/ruleutils.c
src/include/catalog/catversion.h
src/include/nodes/parsenodes.h
src/include/nodes/relation.h
src/include/optimizer/cost.h
src/include/optimizer/pathnode.h
src/include/optimizer/var.h
src/include/parser/kwlist.h
src/include/parser/parse_node.h
src/include/parser/parse_relation.h
src/interfaces/ecpg/preproc/ecpg.addons
src/test/regress/expected/join.out
src/test/regress/expected/rangefuncs.out
src/test/regress/expected/rules.out
src/test/regress/expected/union.out
src/test/regress/sql/join.sql