pgsql: Fix planner problems with LATERAL references in PlaceHolderVars.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix planner problems with LATERAL references in PlaceHolderVars.
Дата
Msg-id E1VAqlj-0006xE-1B@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix planner problems with LATERAL references in PlaceHolderVars.

The planner largely failed to consider the possibility that a
PlaceHolderVar's expression might contain a lateral reference to a Var
coming from somewhere outside the PHV's syntactic scope.  We had a previous
report of a problem in this area, which I tried to fix in a quick-hack way
in commit 4da6439bd8553059766011e2a42c6e39df08717f, but Antonin Houska
pointed out that there were still some problems, and investigation turned
up other issues.  This patch largely reverts that commit in favor of a more
thoroughly thought-through solution.  The new theory is that a PHV's
ph_eval_at level cannot be higher than its original syntactic level.  If it
contains lateral references, those don't change the ph_eval_at level, but
rather they create a lateral-reference requirement for the ph_eval_at join
relation.  The code in joinpath.c needs to handle that.

Another issue is that createplan.c wasn't handling nested PlaceHolderVars
properly.

In passing, push knowledge of lateral-reference checks for join clauses
into join_clause_is_movable_to.  This is mainly so that FDWs don't need
to deal with it.

This patch doesn't fix the original join-qual-placement problem reported by
Jeremy Evans (and indeed, one of the new regression test cases shows the
wrong answer because of that).  But the PlaceHolderVar problems need to be
fixed before that issue can be addressed, so committing this separately
seems reasonable.

Branch
------
master

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

Modified Files
--------------
contrib/postgres_fdw/postgres_fdw.c       |   31 +---
src/backend/nodes/copyfuncs.c             |    3 +-
src/backend/nodes/equalfuncs.c            |   21 ++-
src/backend/nodes/outfuncs.c              |    4 +-
src/backend/optimizer/README              |   14 ++
src/backend/optimizer/path/allpaths.c     |   16 +-
src/backend/optimizer/path/costsize.c     |    7 +-
src/backend/optimizer/path/indxpath.c     |   52 ++----
src/backend/optimizer/path/joinpath.c     |  103 +++++++++--
src/backend/optimizer/path/joinrels.c     |   10 +-
src/backend/optimizer/path/orindxpath.c   |    2 +-
src/backend/optimizer/path/tidpath.c      |    3 +-
src/backend/optimizer/plan/analyzejoins.c |   28 +--
src/backend/optimizer/plan/createplan.c   |  100 ++++++-----
src/backend/optimizer/plan/initsplan.c    |  187 +++++++++++++++-----
src/backend/optimizer/plan/planmain.c     |   13 +-
src/backend/optimizer/prep/prepjointree.c |   44 +++--
src/backend/optimizer/util/placeholder.c  |  113 ++++++++++---
src/backend/optimizer/util/relnode.c      |    2 +
src/backend/optimizer/util/restrictinfo.c |   23 ++-
src/backend/optimizer/util/var.c          |   24 ++-
src/include/nodes/relation.h              |   41 +++--
src/include/optimizer/restrictinfo.h      |    2 +-
src/test/regress/expected/join.out        |  263 ++++++++++++++++++++++++-----
src/test/regress/sql/join.sql             |   41 +++++
25 files changed, 838 insertions(+), 309 deletions(-)


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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: pgsql: release notes: update 9.3 major feature list
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix planner problems with LATERAL references in PlaceHolderVars.