pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Strip off ORDER BY/DISTINCT aggregate pathkeys in create_agg_pat
2+ messages / 1 participants
[nested] [flat]

* pgsql: Strip off ORDER BY/DISTINCT aggregate pathkeys in create_agg_pat
@ 2023-10-09 03:37  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: David Rowley @ 2023-10-09 03:37 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Strip off ORDER BY/DISTINCT aggregate pathkeys in create_agg_path

1349d2790 added code to adjust the PlannerInfo.group_pathkeys so that
ORDER BY / DISTINCT aggregate functions could obtain pre-sorted inputs
to allow faster execution.  That commit forgot to adjust the pathkeys in
create_agg_path().  Some code in there assumed that it was always fine
to make the AggPath's pathkeys the same as its subpath's.  That seems to
have been ok up until 1349d2790, but since that commit adds pathkeys for
columns which are within the aggregate function, those columns won't be
available above the aggregate node.  This can result in "could not find
pathkey item to sort" during create_plan().

The fix here is to strip off the additional pathkeys added by
adjust_group_pathkeys_for_groupagg().  It seems that the pathkeys here
will only ever be group_pathkeys, so all we need to do is check if the
length of the pathkey list is longer than the num_groupby_pathkeys and
get rid of the additional ones only if we see extras.

Reported-by: Justin Pryzby
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/ZQhYYRhUxpW3PSf9%40telsasoft.com
Backpatch-through: 16, where 1349d2790 was introduced

Branch
------
master

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

Modified Files
--------------
src/backend/optimizer/util/pathnode.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Strip off ORDER BY/DISTINCT aggregate pathkeys in create_agg_pat
@ 2023-10-09 03:37  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: David Rowley @ 2023-10-09 03:37 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Strip off ORDER BY/DISTINCT aggregate pathkeys in create_agg_path

1349d2790 added code to adjust the PlannerInfo.group_pathkeys so that
ORDER BY / DISTINCT aggregate functions could obtain pre-sorted inputs
to allow faster execution.  That commit forgot to adjust the pathkeys in
create_agg_path().  Some code in there assumed that it was always fine
to make the AggPath's pathkeys the same as its subpath's.  That seems to
have been ok up until 1349d2790, but since that commit adds pathkeys for
columns which are within the aggregate function, those columns won't be
available above the aggregate node.  This can result in "could not find
pathkey item to sort" during create_plan().

The fix here is to strip off the additional pathkeys added by
adjust_group_pathkeys_for_groupagg().  It seems that the pathkeys here
will only ever be group_pathkeys, so all we need to do is check if the
length of the pathkey list is longer than the num_groupby_pathkeys and
get rid of the additional ones only if we see extras.

Reported-by: Justin Pryzby
Reviewed-by: Richard Guo
Discussion: https://postgr.es/m/ZQhYYRhUxpW3PSf9%40telsasoft.com
Backpatch-through: 16, where 1349d2790 was introduced

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/9154ededfc99e7637cd61b4ca10f28796125ece2

Modified Files
--------------
src/backend/optimizer/util/pathnode.c | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-10-09 03:37 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-10-09 03:37 pgsql: Strip off ORDER BY/DISTINCT aggregate pathkeys in create_agg_pat David Rowley <drowley@postgresql.org>
2023-10-09 03:37 pgsql: Strip off ORDER BY/DISTINCT aggregate pathkeys in create_agg_pat David Rowley <drowley@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox