Re: Introduce Index Aggregate - new GROUP BY strategy

Sergey Soloviev <sergey.soloviev@tantorlabs.ru>

From: Sergey Soloviev <sergey.soloviev@tantorlabs.ru>
To: pgsql-hackers@lists.postgresql.org
Date: 2025-12-10T14:22:01Z
Lists: pgsql-hackers

Attachments

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