Loose index scan is made for this https://dev.mysql.com/doc/refman/8.0/en/group-by-optimizatio...
Postgres doesn't have it yet https://wiki.postgresql.org/wiki/Loose_indexscan