Database Topic Archive

Slow Queries Articles

Query plans, EXPLAIN ANALYZE, planner regressions, pagination, joins, and statistics.

ORDER BY … LIMIT Regressions in MySQL and PostgreSQL
7 min read

The wrong-index ORDER BY LIMIT regression bites MySQL and PostgreSQL alike: the planner walks an ordering index expecting early matches that never come. Here is why LIMIT tempts both optimizers, and how to diagnose and fix it in each.