I was rebasing a patch which requires me to make some changes in
get_cheapest_group_keys_order(). I noticed a few things in there that
I think we could do a little better on:
* The code uses pfree() on a list and it should be using list_free()
* There's a manually coded for loop over a list which seems to be done
so we can skip the first n elements of the list. for_each_from()
should be used for that.
* I think list_truncate(list_copy(list), n) is a pretty bad way to
copy the first n elements of a list, especially when n is likely to be
0 most of the time. I think we should just add a function called
list_copy_head(). We already have list_copy_tail().
* We could reduce some of the branching in the while loop and just set
cheapest_sort_cost to DBL_MAX to save having to check if we're doing
the first loop.
I think the first 3 are worth fixing in PG15 since all that code is
new to that version. The 4th, I'm so sure about.
Does anyone else have any thoughts?
David