Why does MYSQL higher LIMIT offset slow the query down?

后端 未结 6 1230
忘掉有多难
忘掉有多难 2020-11-22 07:20

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 *prima

6条回答
  •  借酒劲吻你
    2020-11-22 08:03

    I found an interesting example to optimize SELECT queries ORDER BY id LIMIT X,Y. I have 35million of rows so it took like 2 minutes to find a range of rows.

    Here is the trick :

    select id, name, address, phone
    FROM customers
    WHERE id > 990
    ORDER BY id LIMIT 1000;
    

    Just put the WHERE with the last id you got increase a lot the performance. For me it was from 2minutes to 1 second :)

    Other interesting tricks here : http://www.iheavy.com/2013/06/19/3-ways-to-optimize-for-paging-in-mysql/

    It works too with strings

提交回复
热议问题