Bug #486 FOUND_ROWS() always return a number with any SELECT
Submitted: 23 May 2003 13:24 Modified: 26 May 2003 9:12
Reporter: Rénald CASAGRAUDE Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:4.0.13 OS:Linux (Linux 2.4.20)
Assigned to: CPU Architecture:Any

[23 May 2003 13:24] Rénald CASAGRAUDE
Description:
In this page :
<http://www.mysql.com/doc/en/Miscellaneous_functions.html#IDX1367>
We can read :
"Returns the number of rows that the preceding SELECT SQL_CALC_FOUND_ROWS ... command would have returned, if it had not been restricted with LIMIT."

But FOUND_ROWS() seems to return the number of "rows that the preceding SELECT SQL_CALC_FOUND_ROWS ... command would have returned, if it had not been restricted with LIMIT" if the preceding SELECT contain SQL_CALC_FOUND_ROWS, but if the preceding SELECT doesn't contain SQL_CALC_FOUND_ROWS, FOUND_ROWS() return the number of rows returned by this preceding SELECT.

How to repeat:
-- Creating and populating the table --

CREATE TABLE `test_table` (
`test_field` VARCHAR( 10 ) NOT NULL
);

ALTER TABLE `test_table` DROP PRIMARY KEY ,
ADD PRIMARY KEY ( `test_field` )

INSERT INTO `test_table` ( `test_field` )
VALUES (
'alpha'
);

INSERT INTO `test_table` ( `test_field` )
VALUES (
'bravo'
);

INSERT INTO `test_table` ( `test_field` )
VALUES (
'tango'
);

-- This is the interactive section with mysql --
mysql> SELECT SQL_CALC_FOUND_ROWS test_field FROM test_table LIMIT 1;
+------------+
| test_field |
+------------+
| alpha      |
+------------+
1 row in set (0.00 sec)

mysql> SELECT FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
|            3 |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT test_field FROM test_table LIMIT 2;
+------------+
| test_field |
+------------+
| alpha      |
| bravo      |
+------------+
2 rows in set (0.00 sec)

mysql> SELECT FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
|            2 |
+--------------+
1 row in set (0.00 sec)

mysql> SELECT test_field FROM test_table;
+------------+
| test_field |
+------------+
| alpha      |
| bravo      |
| tango      |
+------------+
3 rows in set (0.00 sec)

mysql> SELECT FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
|            3 |
+--------------+
1 row in set (0.00 sec)

Suggested fix:
Be more precise on the documentation, or, if the documentation is right, changing the FOUND_ROWS() behavior : he keep the result from the preceding SELECT SQL_CALC_FOUND_ROWS.
[26 May 2003 9:12] 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).