Bug #8689 | found_rows sometimes invalid if next query contains tables | ||
---|---|---|---|
Submitted: | 22 Feb 2005 15:12 | Modified: | 19 Aug 2005 1:42 |
Reporter: | Martin Friebe (Gold Quality Contributor) (OCA) | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S3 (Non-critical) |
Version: | 4.1.10 | OS: | Any (*) |
Assigned to: | Paul DuBois | CPU Architecture: | Any |
[22 Feb 2005 15:12]
Martin Friebe
[7 Jun 2005 11:28]
Timour Katchaounov
This is the intended behavior - the result of found_rows() is being reset when the next query begins execution, and generally may be updated at any time during execution. The only exception are queries that have no tables, when found_rows() is set in the end of the query. This allows us to issue the query "SELECT found_rows();" to retrieve the rows found by the previous query. If we run "select found_rows();" second time, we get "1" which is the number of rows the previous "select found_rows();" returned. For the particular examples in the bug report there is a very simple solution that is even more general than what is proposed in the bug report. The solution is to store the value of the current found_rows() in a user variable. Then this variable can be used at any time later on. In addition, this approach allows to remember the fownd_rows() of arbitrarily old queries. For example the first problematic query can be solved as: select SQL_CALC_FOUND_ROWS a from num where a = 1 limit 1; select found_rows() into @prev_found_rows; select * from num having @prev_found_rows = a; Perhaps this behavior should be documented better.
[19 Aug 2005 1:42]
Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant product(s).