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

Commit1ec2d0b

Browse files
committed
Fix misleading comment for get_cheapest_group_keys_order
The header comment for get_cheapest_group_keys_order() claimed that theoutput arguments were set to a newly allocated list which may be freed bythe calling function, however, this was not always true as the functionwould simply leave these arguments untouched in some cases.This tripped me up when working on1349d27 as I mistakenly assumed Icould perform a list_concat with the output parameters. That turned outbad due to list_concat modifying the original input lists.In passing, make it more clear that the number of distinct values isimportant to reduce tiebreaks during sorts. Also, explain what then_preordered parameter means.Backpatch-through: 15, where get_cheapest_group_keys_order was introduced.
1 parentf6c70b8 commit1ec2d0b

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

‎src/backend/optimizer/path/pathkeys.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -565,22 +565,25 @@ pathkey_sort_cost_comparator(const void *_a, const void *_b)
565565

566566
/*
567567
* get_cheapest_group_keys_order
568-
*Reorders the group pathkeys/clauses to minimize the comparison cost.
568+
*Reorders the group pathkeys /clauses to minimize the comparison cost.
569569
*
570-
* Given a list of pathkeys, we try to reorder them in a way that minimizes
571-
* the CPU cost of sorting. This depends mainly on the cost of comparator
572-
* function (the pathkeys may use different data types) and the number of
573-
* distinct values in each column (which affects the number of comparator
574-
* calls for the following pathkeys).
570+
* Given the list of pathkeys in '*group_pathkeys', we try to arrange these
571+
* in an order that minimizes the sort costs that will be incurred by the
572+
* GROUP BY. The costs mainly depend on the cost of the sort comparator
573+
* function(s) and the number of distinct values in each column of the GROUP
574+
* BY clause (*group_clauses). Sorting on subsequent columns is only required
575+
* for tiebreak situations where two values sort equally.
575576
*
576577
* In case the input is partially sorted, only the remaining pathkeys are
577-
* considered.
578-
*
579-
* Returns true if the keys/clauses have been reordered (or might have been),
580-
* and a new list is returned through an argument. The list is a new copy
581-
* and may be freed using list_free.
582-
*
583-
* Returns false if no reordering was possible.
578+
* considered. 'n_preordered' denotes how many of the leading *group_pathkeys
579+
* the input is presorted by.
580+
*
581+
* Returns true and sets *group_pathkeys and *group_clauses to the newly
582+
* ordered versions of the lists that were passed in via these parameters.
583+
* If no reordering was deemed necessary then we return false, in which case
584+
* the *group_pathkeys and *group_clauses lists are left untouched. The
585+
* original *group_pathkeys and *group_clauses parameter values are never
586+
* destructively modified in place.
584587
*/
585588
staticbool
586589
get_cheapest_group_keys_order(PlannerInfo*root,doublenrows,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp