postgresql/src/backend
David Rowley d8a295389b 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
2023-10-09 16:37:05 +13:00
..
access Fix another typo in e0b1ee17dc 2023-10-07 20:36:47 +03:00
archive Redesign archive modules 2023-02-17 14:26:42 +09:00
backup In basebackup.c, refactor to create read_file_data_into_buffer. 2023-10-03 11:00:40 -04:00
bootstrap Make error messages about WAL segment size more consistent 2023-08-28 15:17:04 +02:00
catalog Remove IndexInfo.ii_OpclassOptions field 2023-10-03 17:51:02 +02:00
commands Push attcompression and attstorage handling into BuildDescForRelation() 2023-10-05 16:20:46 +02:00
executor Fix memory leak in Memoize code 2023-10-05 20:30:47 +13:00
foreign Expand some more uses of "deleg" to "delegation" or "delegated". 2023-05-21 10:55:18 -04:00
jit Revert "Add soft error handling to some expression nodes" 2023-10-02 13:48:15 +09:00
lib Make binaryheap available to frontend code. 2023-09-18 12:18:33 -07:00
libpq Refactor ListenSocket array. 2023-10-05 15:05:25 +03:00
main Remove obsolete defense against strxfrm() bugs. 2023-04-20 13:20:14 +12:00
nodes Remove IndexInfo.ii_OpclassOptions field 2023-10-03 17:51:02 +02:00
optimizer Strip off ORDER BY/DISTINCT aggregate pathkeys in create_agg_path 2023-10-09 16:37:05 +13:00
parser Add some notes about why "ALTER TYPE enum DROP VALUE" is hard. 2023-10-03 11:41:42 -04:00
partitioning Add missing ObjectIdGetDatum() in syscache lookup calls for Oids 2023-07-20 15:18:25 +09:00
po Translation updates 2023-08-07 12:39:30 +02:00
port Add GUC parameter "huge_pages_status" 2023-07-06 14:42:36 +09:00
postmaster Fix crash on syslogger startup 2023-10-06 10:22:02 +03:00
regex All supported systems have locale_t. 2023-07-09 11:55:18 +12:00
replication Tidy-up some appendStringInfo*() usages 2023-10-03 17:09:52 +13:00
rewrite Add TupleDescGetDefault() 2023-09-27 18:52:40 +01:00
snowball Fix the install rule for snowball_create.sql. 2023-05-23 11:15:57 -04:00
statistics Take pg_attribute out of VacAttrStats 2023-07-03 07:18:57 +02:00
storage Remove extra parenthesis from comment. 2023-10-06 18:30:00 +09:00
tcop Fix recovery conflict SIGUSR1 handling. 2023-09-07 12:39:24 +12:00
tsearch Limit to_tsvector_byid's initial array allocation to something sane. 2023-09-25 11:50:28 -04:00
utils Improve JsonLexContext's freeability 2023-10-05 10:59:08 +02:00
.gitignore
Makefile Add system view pg_wait_events 2023-08-20 15:35:02 +09:00
common.mk Blind attempt to fix LLVM dependency in the backend 2022-09-15 10:53:48 +07:00
meson.build Add win32ver data to meson-built postgres.exe. 2023-06-12 07:40:38 -07:00
nls.mk Add missing gettext triggers 2023-05-10 13:51:51 +02:00