Why MySQL Uses Temporary Tables for GROUP BY and How to Optimize It
When MySQL's query optimizer cannot use a suitable index for a GROUP BY, it reads the needed rows, creates a temporary table, and performs sorting, which can degrade performance unless sort_buffer_size is properly configured and large result sets are avoided.
