pgsql: Repair issues with faulty generation of merge-append plans.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Repair issues with faulty generation of merge-append plans.
Дата
Msg-id E1hOq2T-0001C4-4K@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Repair issues with faulty generation of merge-append plans.

create_merge_append_plan failed to honor the CP_EXACT_TLIST flag:
it would generate the expected targetlist but then it felt free to
add resjunk sort targets to it.  This demonstrably leads to assertion
failures in v11 and HEAD, and it's probably just accidental that we
don't see the same in older branches.  I've not looked into whether
there would be any real-world consequences in non-assert builds.
In HEAD, create_append_plan has sprouted the same problem, so fix
that too (although we do not have any test cases that seem able to
reach that bug).  This is an oversight in commit 3fc6e2d7f which
invented the CP_EXACT_TLIST flag, so back-patch to 9.6 where that
came in.

convert_subquery_pathkeys would create pathkeys for subquery output
values if they match any EquivalenceClass known in the outer query
and are available in the subquery's syntactic targetlist.  However,
the second part of that condition is wrong, because such values might
not appear in the subquery relation's reltarget list, which would
mean that they couldn't be accessed above the level of the subquery
scan.  We must check that they appear in the reltarget list, instead.
This can lead to dropping knowledge about the subquery's sort
ordering, but I believe it's okay, because any sort key that the
outer query actually has any interest in would appear in the
reltarget list.

This second issue is of very long standing, but right now there's no
evidence that it causes observable problems before 9.6, so I refrained
from back-patching further than that.  We can revisit that choice if
somebody finds a way to make it cause problems in older branches.
(Developing useful test cases for these issues is really problematic;
fixing convert_subquery_pathkeys removes the only known way to exhibit
the create_merge_append_plan bug, and neither of the test cases added
by this patch causes a problem in all branches, even when considering
the issues separately.)

The second issue explains bug #15795 from Suresh Kumar R ("could not
find pathkey item to sort" with nested DISTINCT queries).  I stumbled
across the first issue while investigating that.

Discussion: https://postgr.es/m/15795-fadb56c8e44ee73c@postgresql.org

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/946cdf9ff771807885f49913b789fdc282b751bc

Modified Files
--------------
src/backend/optimizer/path/pathkeys.c   | 72 +++++++++++++++++++++++---------
src/backend/optimizer/plan/createplan.c | 32 ++++++++++++---
src/test/regress/expected/union.out     | 73 +++++++++++++++++++++++++++++++++
src/test/regress/sql/union.sql          | 28 +++++++++++++
4 files changed, 180 insertions(+), 25 deletions(-)


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

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: pgsql: doc: update PG 12 release notes, v2
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: pgsql: docs: fist draft version of the PG 12 release notes