Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd8a2953

Browse files
committed
Strip off ORDER BY/DISTINCT aggregate pathkeys in create_agg_path
1349d27 added code to adjust the PlannerInfo.group_pathkeys so thatORDER BY / DISTINCT aggregate functions could obtain pre-sorted inputsto allow faster execution. That commit forgot to adjust the pathkeys increate_agg_path(). Some code in there assumed that it was always fineto make the AggPath's pathkeys the same as its subpath's. That seems tohave been ok up until1349d27, but since that commit adds pathkeys forcolumns which are within the aggregate function, those columns won't beavailable above the aggregate node. This can result in "could not findpathkey item to sort" during create_plan().The fix here is to strip off the additional pathkeys added byadjust_group_pathkeys_for_groupagg(). It seems that the pathkeys herewill only ever be group_pathkeys, so all we need to do is check if thelength of the pathkey list is longer than the num_groupby_pathkeys andget rid of the additional ones only if we see extras.Reported-by: Justin PryzbyReviewed-by: Richard GuoDiscussion:https://postgr.es/m/ZQhYYRhUxpW3PSf9%40telsasoft.comBackpatch-through: 16, where1349d27 was introduced
1 parent77db132 commitd8a2953

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

‎src/backend/optimizer/util/pathnode.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3133,10 +3133,26 @@ create_agg_path(PlannerInfo *root,
31333133
pathnode->path.parallel_safe=rel->consider_parallel&&
31343134
subpath->parallel_safe;
31353135
pathnode->path.parallel_workers=subpath->parallel_workers;
3136+
31363137
if (aggstrategy==AGG_SORTED)
3137-
pathnode->path.pathkeys=subpath->pathkeys;/* preserves order */
3138+
{
3139+
/*
3140+
* Attempt to preserve the order of the subpath. Additional pathkeys
3141+
* may have been added in adjust_group_pathkeys_for_groupagg() to
3142+
* support ORDER BY / DISTINCT aggregates. Pathkeys added there
3143+
* belong to columns within the aggregate function, so we must strip
3144+
* these additional pathkeys off as those columns are unavailable
3145+
* above the aggregate node.
3146+
*/
3147+
if (list_length(subpath->pathkeys)>root->num_groupby_pathkeys)
3148+
pathnode->path.pathkeys=list_copy_head(subpath->pathkeys,
3149+
root->num_groupby_pathkeys);
3150+
else
3151+
pathnode->path.pathkeys=subpath->pathkeys;/* preserves order */
3152+
}
31383153
else
31393154
pathnode->path.pathkeys=NIL;/* output is unordered */
3155+
31403156
pathnode->subpath=subpath;
31413157

31423158
pathnode->aggstrategy=aggstrategy;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp