Обсуждение: pgsql: Make truncate_useless_pathkeys() consider WindowFuncs

Поиск
Список
Период
Сортировка

pgsql: Make truncate_useless_pathkeys() consider WindowFuncs

От
David Rowley
Дата:
Make truncate_useless_pathkeys() consider WindowFuncs

truncate_useless_pathkeys() seems to have neglected to account for
PathKeys that might be useful for WindowClause evaluation.  Modify it so
that it properly accounts for that.

Making this work required adjusting two things:

1. Change from checking query_pathkeys to check sort_pathkeys instead.
2. Add explicit check for window_pathkeys

For #1, query_pathkeys gets set in standard_qp_callback() according to the
sort order requirements for the first operation to be applied after the
join planner is finished, so this changes depending on which upper
planner operations a particular query needs.  If the query has window
functions and no GROUP BY, then query_pathkeys gets set to
window_pathkeys.  Before this change, this meant PathKeys useful for the
ORDER BY were not accounted for in queries with window functions.

Because of #1, #2 is now required so that we explicitly check to ensure
we don't truncate away PathKeys useful for window functions.

Author: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAApHDvrj3HTKmXoLMbUjTO=_MNMxM=cnuCSyBKidAVibmYPnrg@mail.gmail.com

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/path/pathkeys.c | 24 ++++++++++++++++++++++--
src/test/regress/expected/window.out  | 16 ++++++++++++++++
src/test/regress/sql/window.sql       | 13 +++++++++++++
3 files changed, 51 insertions(+), 2 deletions(-)