TuningLens

MySQL guide · Published 24 September 2026 · Updated 24 September 2026

What does “Using filesort” mean in MySQL?

Direct answer: “Using filesort” means MySQL needs a separate sorting operation to produce the requested order; it does not mean that a disk file is necessarily used. It is a plan detail to investigate, not proof by itself that a query is slow.

Scope: MySQL 8.0 and 8.4, InnoDB examples. Check the manual for your exact release and storage engine. TuningLens editorial team · Reviewed by TuningLens editorial team.

How to read the plan

For a SELECT, start with a non-executing plan:

EXPLAIN
SELECT id, created_at
FROM orders
WHERE customer_id = 42
ORDER BY created_at DESC
LIMIT 20;

In traditional output, inspect the Extra column for Using filesort. MySQL can use an index to satisfy some ORDER BY clauses; otherwise it performs a sort. The sort may use memory or temporary disk space depending on workload and settings. Even an index-supported order is not automatically faster: the chosen plan depends on selectivity, row width, LIMIT, and other costs.

See the official MySQL ORDER BY optimization documentation and EXPLAIN output reference.

A safe index hypothesis

For the example query, a composite index beginning with the equality-filtered column and followed by the ordering column may be worth testing:

-- Review existing indexes and workload first.
CREATE INDEX ix_orders_customer_created
  ON orders (customer_id, created_at);

This is only a candidate. The optimizer might choose another access path; ties in created_at are not deterministic without a unique tiebreaker; and every index adds storage and write-maintenance cost. Consider whether the application needs stable ordering, for example ORDER BY created_at DESC, id DESC, and whether the index should include that tiebreaker.

When filesort deserves attention

Prioritize it when measurements show the query is costly, many rows reach the sort, or the same expensive sort dominates a frequent request. A small bounded sort may be harmless. Check estimated rows, chosen key, filters, selected columns, and actual workload frequency before changing indexes.

For MySQL 8.0.18 and later, EXPLAIN ANALYZE executes the SELECT while collecting actual iterator statistics. Use it with representative data in a safe environment because it runs the query.

Verify the change

  1. Record the original query, schema, indexes, MySQL version, and plan.
  2. Run representative tests and record baseline latency and returned rows.
  3. Test one candidate change in staging; compare plan, result correctness, latency distribution, and write impact.
  4. Repeat with representative parameter values and data volume before rollout.

Do not infer a speedup from the disappearance of “Using filesort” alone. The source output and timings are needed to assess whether the change helped.

Sources

Request beta access