Bug #6089 FOUND_ROWS returns wrong values when no table/view is used
Submitted: 14 Oct 2004 10:45 Modified: 2 Mar 2005 21:14
Reporter: Georg Richter Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:4.1 OS:Linux (Linux)
Assigned to: Ramil Kalimullin CPU Architecture:Any

[14 Oct 2004 10:45] Georg Richter
Description:
See how to repeat 

How to repeat:
5.0.2-alpha-debug-log 
[12:40] root@test> SELECT SQL_CALC_FOUND_ROWS "foo" UNION SELECT "bar"; 
+-----+ 
| foo | 
+-----+ 
| foo | 
| bar | 
+-----+ 
2 rows in set (0.00 sec) 
 
5.0.2-alpha-debug-log 
[12:41] root@test> SELECT FOUND_ROWS(); 
+--------------+ 
| FOUND_ROWS() | 
+--------------+ 
|            2 | 
+--------------+ 
1 row in set (0.00 sec) 
 
5.0.2-alpha-debug-log 
[12:41] root@test> SELECT SQL_CALC_FOUND_ROWS "foo" UNION SELECT "bar" LIMIT 0; 
Empty set (0.00 sec) 
 
5.0.2-alpha-debug-log 
[12:42] root@test> SELECT FOUND_ROWS(); 
+--------------+ 
| FOUND_ROWS() | 
+--------------+ 
|            1 | 
+--------------+ 
1 row in set (0.00 sec) 
 
5.0.2-alpha-debug-log 
[12:42] root@test> 
5.0.2-alpha-debug-log 
[12:42] root@test> SELECT SQL_CALC_FOUND_ROWS 'foo'; 
+-----+ 
| foo | 
+-----+ 
| foo | 
+-----+ 
1 row in set (0.00 sec) 
 
5.0.2-alpha-debug-log 
[12:42] root@test> SELECT FOUND_ROWS(); 
+--------------+ 
| FOUND_ROWS() | 
+--------------+ 
|            0 | 
+--------------+ 
1 row in set (0.00 sec)
[14 Oct 2004 12:07] MySQL Verification Team
Verified with 4.1.6 and 5.0.2
[15 Oct 2004 23:23] Konstantin Osipov
I'm not sure if it's the same issue, or should be moved to a separate bug, but
if found_rows() is used in any non-trivial query, it always returns 0:

mysql> select * FROM t1 limit 1;
+------+
| a    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

mysql> select found_rows();
+--------------+
| found_rows() |
+--------------+
|            1 |
+--------------+
1 row in set (0.00 sec)

mysql> select * FROM t1 limit 1;
+------+
| a    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

mysql> select *, found_rows() from t1 limit 1;
+------+--------------+
| a    | found_rows() |
+------+--------------+
|    1 |            0 |
+------+--------------+
1 row in set (0.00 sec)
[1 Mar 2005 11:19] Ramil Kalimullin
fixed in 4.1.11
[2 Mar 2005 15:32] Konstantin Osipov
Reviewed additional patch to make the previos patch prepared-statements friendly.
[2 Mar 2005 21:14] Paul DuBois
Noted in 4.1.11 changelog.