In MySQL, filesort is the catch-all algorithm for producing sorted results for ORDER-BY or GROUP-BY queries. MySQL has two algorithms for filesort, both the original and the modified algorithms are described in the user manual. The most commonly used algorithm is the so called modified algorithm, it is used for all cases except when BLOB and TEXT column are involved.
In 5.7.3, Tor Didriksen in the optimizer team introduced one more optimization that applies to the modified algorithm. Let us first take a look at how MySQL´s modified filesort algorithm worked up to 5.7.2.
- Read the rows that match the WHERE clause.
- For each row, record a tuple of values consisting of the sort key value and the additional fields referenced by the query.
- When the sort buffer becomes full, sort the tuples …