Assume a houses
table with lot's of fields, related images tables, and 3 other related tables. I have an expensive query that retrieves all houses
data, with all data from the related tables. Do I need to run the same expensive MySql query twice in the case of pagination: once for current result page and once to get the total number of records?
I'm using server-side pagination with Limit 0,10
, and need to return the total number of houses along with the data. It doesn't make sense to me to run the same expensive query with the count(*)
function, just because I'm limiting the result-set for pagination.
Is there another way to instruct MySQL to count the whole query, but bring back only the current pagination data?
I hope my question is clear... thanks