Tea_J wrote:borrowing bradgrafeliman's words and tweaking it:
SUB QUERY
QUERY # 1: "count the rows from the result of the following operation: ( Query # 2) Retrieve all 1.3 million rows from the result set into my memory space, then discard all the results"
QUERY # 3: "Retrieve again the rows needed but this time return 100 rows only if available)"
You may have borrowed the words, but you failed to adjust the context.
The results retrieved from Query #2 could be very different from what you have in mind, i.e., the database engine could be smart enough to only retrieve primary keys, or perform some other optimisation. In your proposed scenario, you would be retrieving the data that you want to use as well, which could be substantially more.
Unless you happen to have the webserver and the database server on the same machine, the retrieval of the rows will not be into your memory space. Consequently, only the final result, i.e., the row count and the rows that you actually want, would be sent across the network and into your memory space.
Tea_J wrote:So this is still an extra load on the server and I dont know if it is half as bad as retrieving all 1.3million records in the first place .. the SQL_CALC_FOUND_ROWS also has been known to slow down select queries.
Obviously it will slow down select queries: it has to do more work. If you don't know but need to know in order to choose, then test and find out.
Tea_J wrote:dynamically modify the SELECT statement to use COUNT(*) instead of doing a full select, using regex..
Wouldn't it make more sense to dynamically construct the SQL statement?