Skip site navigation (1) Skip section navigation (2)

pgsql: Fix up planner infrastructure to support LATERAL properly.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix up planner infrastructure to support LATERAL properly.
Date: 2012-08-27 02:51:35
Message-ID: E1T5pQN-0001qq-VZ@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
Fix up planner infrastructure to support LATERAL properly.

This patch takes care of a number of problems having to do with failure
to choose valid join orders and incorrect handling of lateral references
pulled up from subqueries.  Notable changes:

* Add a LateralJoinInfo data structure similar to SpecialJoinInfo, to
represent join ordering constraints created by lateral references.
(I first considered extending the SpecialJoinInfo structure, but the
semantics are different enough that a separate data structure seems
better.)  Extend join_is_legal() and related functions to prevent trying
to form unworkable joins, and to ensure that we will consider joins that
satisfy lateral references even if the joins would be clauseless.

* Fill in the infrastructure needed for the last few types of relation scan
paths to support parameterization.  We'd have wanted this eventually
anyway, but it is necessary now because a relation that gets pulled up out
of a UNION ALL subquery may acquire a reltargetlist containing lateral
references, meaning that its paths *have* to be parameterized whether or
not we have any code that can push join quals down into the scan.

* Compute data about lateral references early in query_planner(), and save
in RelOptInfo nodes, to avoid repetitive calculations later.

* Assorted corner-case bug fixes.

There's probably still some bugs left, but this is a lot closer to being
real than it was before.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/9ff79b9d4e71822a875c0f5e38f5ec86c7fb079f

Modified Files
--------------
src/backend/nodes/copyfuncs.c             |   17 ++
src/backend/nodes/equalfuncs.c            |   12 ++
src/backend/nodes/outfuncs.c              |   16 ++
src/backend/optimizer/path/allpaths.c     |  107 ++++++------
src/backend/optimizer/path/costsize.c     |   52 ++++--
src/backend/optimizer/path/indxpath.c     |   17 ++-
src/backend/optimizer/path/joinpath.c     |   30 ++--
src/backend/optimizer/path/joinrels.c     |   86 +++++++++-
src/backend/optimizer/path/tidpath.c      |   12 ++-
src/backend/optimizer/plan/analyzejoins.c |   21 +++
src/backend/optimizer/plan/createplan.c   |   39 ++++-
src/backend/optimizer/plan/initsplan.c    |  267 ++++++++++++++++++++++++++---
src/backend/optimizer/plan/planagg.c      |    3 +-
src/backend/optimizer/plan/planmain.c     |    9 +
src/backend/optimizer/plan/planner.c      |   35 +++-
src/backend/optimizer/prep/prepjointree.c |    8 +-
src/backend/optimizer/prep/prepunion.c    |    1 +
src/backend/optimizer/util/pathnode.c     |   26 ++-
src/backend/optimizer/util/placeholder.c  |    8 +-
src/backend/optimizer/util/relnode.c      |   28 ++--
src/backend/optimizer/util/var.c          |    1 +
src/backend/rewrite/rewriteManip.c        |    3 +
src/include/nodes/nodes.h                 |    1 +
src/include/nodes/relation.h              |   44 +++++-
src/include/optimizer/cost.h              |    5 +-
src/include/optimizer/pathnode.h          |    8 +-
src/include/optimizer/planmain.h          |    2 +
src/include/optimizer/planner.h           |    2 +
src/test/regress/expected/join.out        |  122 ++++++++++++-
src/test/regress/sql/join.sql             |   17 ++
30 files changed, 817 insertions(+), 182 deletions(-)

pgsql-committers by date

Next:From: Bruce MomjianDate: 2012-08-27 03:21:59
Subject: pgsql: Update FreeBSD kernel configuration documentation.
Previous:From: Bruce MomjianDate: 2012-08-26 20:33:26
Subject: pgsql: Clarify documentation that primary key and unique constraintsar

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group