I have a dataset in MySQL where using limit is already an expensive query, and finding the number of results is expensive as well. Thus, I'd like to avoid doing another query to find the number of results. I cannot use MYSQL_CALC_FOUND_ROWS because the limit is inside a subquery:
SELECT * FROM items,
(
SELECT
item_id
FROM
(etc)
WHERE
some.field=<parameter>
AND (etc)
GROUP BY (something)
ORDER BY (something_else) DESC
LIMIT 15
) subset
WHERE item.id=subset.item_id
I could left join items and do away with the subquery, then be able to use MYSQL_CALC_FOUND_ROWS, however this is very, very, slow. I've tried all index optimizations and let's just assume it is out of the question.
This now becomes more a design question... how do I allow the user to page through this data when I don't know the last page? I only know if they've gone too far (eg: query returns no results).