MySQL

Sort Buffer Exhaustion

warning
performanceUpdated Mar 2, 2026

Sort operations exceeding sort_buffer_size, requiring multi-pass merge sorts and temporary files. Causes significant performance degradation for queries with ORDER BY, GROUP BY, or large JOINs requiring sorting.

Technologies:
How to detect:

mysql.performance.sort_merge_passes rate > 10/sec with mysql.performance.sort_rows high and events_statements_sum_sort_scan or events_statements_sum_sort_range elevated

Recommended action:

Query performance_schema.events_statements_summary_by_digest for queries with high SUM_SORT_MERGE_PASSES and SUM_SORT_ROWS. Increase sort_buffer_size for session or globally (be cautious - allocated per connection performing sort). Add indexes to eliminate sorts where possible - covering indexes can provide sorted results without explicit sort. Review mysql.performance.sort_scan vs mysql.performance.sort_range - sort_scan indicates full table scan before sort, requiring index. For large result sets, consider application-level pagination to reduce sort volume.