The effect of a LIMIT clause on performance in MySQL?

前端 未结 2 896
执笔经年
执笔经年 2021-01-22 10:30

I suspect I know the answer to this already, but...

Given the following 3 MySQL statements:

SELECT SQL_CALC_FOUND_ROWS title FROM STUFF LIMIT 1000000, 1;         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-22 10:41

    That depends, if you add an ORDER BY and index the column that is being ordered it can be significantly faster.

    This is because it will be executed without scanning and sorting full result set. Using an index will product an index range scan which will be started and stopped as soon as soon as the required amount of rows are generated.

提交回复
热议问题