How would you set a limit in the where clause? I see no way of getting exactly 20 records (unless you never delete a row, and it wouldnt be sortable)
Oct 28, 2021
2
Level 4
Laravel performance: How to use pagination with index?
When using Laravel's paginate(20) method, the MySQL query looks like this at the end:
limit 20 offset 0;
To my understanding, therefore Laravel has to scan the entire table instead of using an index. The right way to go would be to apply the limit in the where clause somehow.
How do you handle this? Is there a package or something that takes care of that? I don't really want to build my own paginator. Thanks!
Please or to participate in this conversation.