Hi Christopher,
Thanks for the swift feedback!
I read soe further myself, and it does look as if I just need to add the SQL_CALC_FOUND_ROWS to the very first SELECT in case of a UNION, so I'll give it a chance and replace SELECT by SELECT SQL_CALC_FOUND_ROWS in the returned statement, executing that and then executing the SELECT FOUND_ROWS(); statement.
I hope this will work.
thanks for the feedback though!
Main Topics
Browse All Topics





by: ChristoferDutzPosted on 2009-11-06 at 05:53:01ID: 25759044
It seems the "SQL_CALC_FOUND_ROWS" Option is added directly after the select keyword and is generally only valuable, when using the LIMIT Keyword to limit the amount of results.
in this case at first a limited query is executed:
"SELECT * FROM myTable LIMIT 100"
then adding the "SQL_CALC_FOUND_ROWS" Keyword:
"SELECT SQL_CALC_FOUND_ROWS * FROM myTable LIMIT 100"
Would result in the same result, but you would be able to issue a second query directly after the first:
"SELECT FOUND_ROWS();"
Which would return the amount of rows the query would have returned, if the uery wasn't limited.
Don't know if this is universal for all databases, but It seems to work with MySQL
So for your problem, you could add the Keyword to your query returned by MakeSQLQuery() and simply call
"SELECT FOUND_ROWS();" after that. But I doubt that it would perform much better. Perhaps limiting the query returned by MakeSQLQuery() by adding a LIMIT 1 at the end would make MySQL only collect statistics and not the Table data not needed for calculating the number of reults.