MySQL counts the total number of rows

I have a complex MySQL query, which takes a lot of time, choosing from the table more than 150 thousand rows and several JOINS and subqueries. I limit the number of results, but I need to know the total number of rows.

Is there a way to not repeat the request with COUNT(*)as a field to receive them? (repeating the request almost doubles the time it takes to complete the script)

+3
source share
2 answers

Actually, it might be faster to complete two queries (so you can just do the testing quickly):

, COUNT (*) ( " " "", EXPLAIN)

COUNT (*), ( ).

+2

MySQL SQL_CALC_FOUND_ROWS, SELECT . , SELECT FOUND_ROWS() AS rows, , .

+3

Source: https://habr.com/ru/post/1735162/


All Articles