ActiveRecord count with grouped relations

I’d like to try and revive discussion around these issues:

Originally, my thought for an easy solution was to hide the presence of group_values inside a subquery using from( as I suggested here:!topic/rubyonrails-core/mwBehQcEduU


Unfortunately some databases (MySQL) are really inefficient at dealing with functions on subqueries like this. And ultimately, relying on subqueries to fix it for us is a hack just to get around the problem with blindly calling count and expecting an integer. I keep running into this problem regularly enough that I really want to work something out for separate and predictable “row count” and “grouped count” methods. Maybe something like one of these ideas I sketched out:

Is there a way forward?

Andrew Vit