Bug #486 FOUND_ROWS() always return a number with any SELECT
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.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.048 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.