Calculating COUNT(*) of a MAX() + GROUP BY query
To determine the number of distinct groups a distinct query over the grouping columns is sufficient. No temp table is needed.

SELECT COUNT(DISTINCT col1, col2) FROM tbl

Depending on the data type of your grouping columns it might be beneficial to define a two-column index on (col1, col2).

Have a look at MySQL's GROUP BY Optimization documentation to see how this works.