Bug #40497 | found_rows() function delivers unexpected result when used without SQL_CALC_FOUN | ||
---|---|---|---|
Submitted: | 4 Nov 2008 12:45 | Modified: | 26 Nov 2008 16:50 |
Reporter: | Gustaf Thorslund | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S3 (Non-critical) |
Version: | 5.0, 5.1, 6.0 | OS: | Any |
Assigned to: | Paul DuBois | CPU Architecture: | Any |
[4 Nov 2008 12:45]
Gustaf Thorslund
[4 Nov 2008 17:36]
Susanne Ebrecht
create table t(id serial, i integer); delimiter § create procedure p_t() begin declare i integer default 1; while i < 101 do insert into t(i) values(i); set i = i + 1; end while; end § delimiter ; call p_t; select count(*) from t; +----------+ | count(*) | +----------+ | 100 | +----------+ 1 row in set (0.03 sec) SELECT * FROM t LIMIT 50, 10; +----+------+ | id | i | +----+------+ | 51 | 51 | | 52 | 52 | | 53 | 53 | | 54 | 54 | | 55 | 55 | | 56 | 56 | | 57 | 57 | | 58 | 58 | | 59 | 59 | | 60 | 60 | +----+------+ 10 rows in set (0.00 sec) SELECT FOUND_ROWS(); +--------------+ | FOUND_ROWS() | +--------------+ | 60 | +--------------+ 1 row in set (0.02 sec) The behaviour is contrary to documentation. Fixing the behaviour would break lots of user code so fixing the documentation would make more sense.
[18 Nov 2008 18:43]
Susanne Ebrecht
The documentation in http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows says: "In the absence of the SQL_CALC_FOUND_ROWS option in the most recent successful SELECT statement, FOUND_ROWS() returns the number of rows in the result set returned by that statement." It would be nice to add here that when LIMIT is used in the SELECT statement is will return the number of rows up to the limit. With an example LIMIT 50,10 will return 60 rows.
[26 Nov 2008 16:50]
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 products. New wording: In the absence of the SQL_CALC_FOUND_ROWS option in the most recent successful SELECT statement, FOUND_ROWS() returns the number of rows in the result set returned by that statement. If the statement includes a LIMIT clause, FOUND_ROWS() returns the number of rows up to the limit. For example, FOUND_ROWS() returns 10 or 60, respectively, if the statement includes LIMIT 10 or LIMIT 50, 10.