pgsql: Improve NestLoopParam generation for lateral subqueries

Поиск
Список
Период
Сортировка
От David Rowley
Тема pgsql: Improve NestLoopParam generation for lateral subqueries
Дата
Msg-id E1rTClO-0039AR-5M@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Improve NestLoopParam generation for lateral subqueries

It was possible in cases where we had a LATERAL joined subquery that
when the same Var is mentioned in both the lateral references and in the
outer Vars of the scan clauses that the given Var wouldn't be assigned
to the same NestLoopParam.

This could cause issues in Memoize as the cache key would reference the
Var for the scan clauses but when the parameter for the lateral references
changed some code in Memoize would see that some other parameter had
changed that's not part of the cache key and end up purging the entire
cache as a result, thinking the cache had become stale.  This could
result in a Nested Loop -> Memoize plan being quite inefficient as, in
the worst case, the cache purging could result in never getting a cache
hit.  In no cases could this problem lead to incorrect query results.

Here we switch the order of operations so that we create NestLoopParam
for the lateral references first before doing replace_nestloop_params().
replace_nestloop_params() will find and reuse the existing NestLoopParam
in cases where the Var exists in both locations.

Author: Richard Guo
Reviewed-by: Tom Lane, David Rowley
Discussion: https://postgr.es/m/CAMbWs48XHJEK1Q1CzAQ7L9sTANTs9W1cepXu8%3DKc0quUL%2Btg4Q%40mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/2cca95e175463a7af95164498b889b1ea118583d

Modified Files
--------------
src/backend/optimizer/plan/createplan.c | 15 ++++++++++---
src/test/regress/expected/memoize.out   | 37 +++++++++++++++++++++++++++++++++
src/test/regress/sql/memoize.sql        | 17 +++++++++++++++
3 files changed, 66 insertions(+), 3 deletions(-)


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

Предыдущее
От: Michael Paquier
Дата:
Сообщение: pgsql: Revert "Add support for parsing of large XML data (>= 10MB)"
Следующее
От: Michael Paquier
Дата:
Сообщение: pgsql: Fix comment in index.c