Best way to get result count before LIMIT was applied

前端 未结 5 912
后悔当初
后悔当初 2020-11-22 12:30

When paging through data that comes from a DB, you need to know how many pages there will be to render the page jump controls.

Currently I do that by running the que

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 12:36

    You could mitigate the performance penalty by not running the COUNT() query every time. Cache the number of pages for, say 5 minutes before the query is run again. Unless you're seeing a huge number of INSERTs, that should work just fine.

提交回复
热议问题