pgsql: Fix qual-clause-misplacement issues with pulled-up LATERAL subqu

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix qual-clause-misplacement issues with pulled-up LATERAL subqu
Дата
Msg-id E1VBT7X-0002Pl-S3@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix qual-clause-misplacement issues with pulled-up LATERAL subqueries.

In an example such as
SELECT * FROM
  i LEFT JOIN LATERAL (SELECT * FROM j WHERE i.n = j.n) j ON true;
it is safe to pull up the LATERAL subquery into its parent, but we must
then treat the "i.n = j.n" clause as a qual clause of the LEFT JOIN.  The
previous coding in deconstruct_recurse mistakenly labeled the clause as
"is_pushed_down", resulting in wrong semantics if the clause were applied
at the join node, as per an example submitted awhile ago by Jeremy Evans.
To fix, postpone processing of such clauses until we return back up to
the appropriate recursion depth in deconstruct_recurse.

In addition, tighten the is-safe-to-pull-up checks in is_simple_subquery;
we previously missed the possibility that the LATERAL subquery might itself
contain an outer join that makes lateral references in lower quals unsafe.

A regression test case equivalent to Jeremy's example was already in my
commit of yesterday, but was giving the wrong results because of this
bug.  This patch fixes the expected output for that, and also adds a
test case for the second problem.

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/b19e5a696ab28be5d55949048194922152091aa1

Modified Files
--------------
src/backend/optimizer/README              |    9 +-
src/backend/optimizer/plan/initsplan.c    |  161 +++++++++++++++++++++++------
src/backend/optimizer/prep/prepjointree.c |  153 +++++++++++++++++++++++----
src/test/regress/expected/join.out        |   76 ++++++++++++--
src/test/regress/sql/join.sql             |    9 ++
5 files changed, 343 insertions(+), 65 deletions(-)


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

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: pgsql: Fix pg_upgrade failure from servers older than 9.3
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix qual-clause-misplacement issues with pulled-up LATERAL subqu