By far, Wordpress, Implements pagination by means of SQL_CALC_ROWS_FOUND. But my benchmark have shown that this implementation is 1.1 Million % slower than my queries without it. So I am thinking of replacing it and implement a faster rows_counting method. The problem is, how do we integrate that in Wordpress?

Approach to Solution

I found a blog post that could be a solution. Its an old post however that same issue is still standing as it is today. The post benchmarks SQL_CALC_ROWS_FOUND vs. Ordinary SQL + Count, and it was found out that ordinary query (without sql_calc_rows_fount) to get your requests followed by COUNT to determine the number of results was magnitude times faster than the existing implementation

We can disable, the SQL_CALC_ROWS_FOUND by:


as indicated in this blog, so when Wordpress runs its usual queries we get the same results as usual, but without paginations! All results were there but no page numbers! Fast but partially useful, since pagination depends on the calculated results found, but we just disabled that calculations. We can get that by Implementing SELECT Count, however, how do we pass the results to wordpress so it can do the Paginations?


Apache 2.4 (fpm), php7, mysql5.7, MyIsam, 8 Core Intel Xeon, 24Gb Ram, SSD.

  • Very interesting question, would love to see some solution for this. Nothing that comes to my mind now sadly. Maybe using previous pre_get_posts filter somehow? – user1049961 Feb 10 '18 at 11:34
  • .nobody in wordpress cared to speeding it up? – James Guana Feb 15 '18 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.