pgsql: Fix up join removal's interaction with PlaceHolderVars.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix up join removal's interaction with PlaceHolderVars.
Дата
Msg-id E1pP8Ms-001voE-9Q@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix up join removal's interaction with PlaceHolderVars.

The portion of join_is_removable() that checks PlaceHolderVars
can be made a little more accurate and intelligible than it was.
The key point is that we can allow join removal even if a PHV
mentions the target rel in ph_eval_at, if that mention was only
added as a consequence of forcing the PHV up to a join level
that's at/above the outer join we're trying to get rid of.
We can check that by testing for the OJ's relid appearing in
ph_eval_at, indicating that it's supposed to be evaluated after
the outer join, plus the existing test that the contained
expression doesn't actually mention the target rel.

While here, add an explicit check that there'll be something left
in ph_eval_at after we remove the target rel and OJ relid.  There
is an Assert later on about that, and I'm not too sure that the
case could happen for a PHV satisfying the other constraints,
but let's just check.  (There was previously a bms_is_subset test
that meant to cover this risk, but it's broken now because it
doesn't account for the fact that we'll also remove the OJ relid.)

The real reason for revisiting this code though is that the
Assert I left behind in 8538519db turns out to be easily
reachable, because if a PHV of this sort appears in an upper-level
qual clause then that clause's clause_relids will include the
PHV's ph_eval_at relids.  This is a mirage though: we have or soon
will remove these relids from the PHV's ph_eval_at, and therefore
they no longer belong in qual clauses' clause_relids either.
Remove that Assert in join_is_removable, and replace the similar
one in remove_rel_from_query with code to remove the deleted relids
from clause_relids.

Per bug #17773 from Robins Tharakan.

Discussion: https://postgr.es/m/17773-a592e6cedbc7bac5@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/cad56920513e5b7ccdd3d41b0ea893eb3383f863

Modified Files
--------------
src/backend/optimizer/plan/analyzejoins.c | 52 ++++++++++++++++++-------------
src/test/regress/expected/join.out        | 20 ++++++++++++
src/test/regress/sql/join.sql             |  8 +++++
3 files changed, 58 insertions(+), 22 deletions(-)


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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: doc: Fix SQL keywords lists
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Stamp 15.2.