Hi!
I have looked again at planner's code and found mistake in cost calculation:
1. There was an extra `LOG2(numGroups)` multipler that accounts height of
btree index, but actually it is extra multiplier. Now cost is calculated as
much like sort: input_tuples * (2.0 * cpu_operator_cost * numGroupCols).
2. IndexAgg requires spilling index on disk to save sort order, but code that
calculates this cost used this value without HAVING quals adjustment.
After fixing these parts, more plans started to use Index Aggregate node.
New patches have this fixed.
Also, patches contains several minor fixes of compiler warnings to which I
did not pay attention during development, but CI pipeline complained about.
---
Sergey Soloviev
TantorLabs: https://tantorlabs.com