LMSouq
database Open

Why does MYSQL higher LIMIT offset slow the query down?

RA
Rahman
1 month ago
3 views
Problem Description
Scenario in short: A table with more than 16 million records [2GB in size]. The higher LIMIT offset with SELECT, the slower the query becomes, when using ORDER BY *primary_key* So SELECT * FROM large ORDER BY `id` LIMIT 0, 30 takes far less than SELECT * FROM large ORDER BY `id` LIMIT 10000, 30 That only orders 30 records and same eitherway. So it's not the overhead from ORDER BY. Now when fetching the latest 30 rows it takes around 180 seconds. How can I optimize that simple query?

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base