Skip to content

Commit 8d03b05

Browse files
author
Kailasnath Nagarkar
committed
Bug #24714857: FOUND_ROWS() RETURNS 1 WHEN NO ROWS FOUND
This patch is specific to mysql-5.7 ISSUE: FOUND_ROWS() returned 1 even though the previous select did not return any rows. This was happening because the statistics returned by InnoDB returned 1 for the select even though there are no rows. The same count was further returned by FOUND_ROWS(). FIX: In InnoDB, while determining statistics, check whether its for temporary table. If its temporary table, do not increment the row count.
1 parent b236870 commit 8d03b05

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

mysql-test/r/func_found_rows.result

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#
2+
# Bug #24714857 FOUND_ROWS() RETURNS 1 WHEN NO ROWS FOUND
3+
#
4+
CREATE TABLE tbl (
5+
col_text TEXT
6+
);
7+
SELECT SQL_CALC_FOUND_ROWS col_text FROM tbl AS tbl1
8+
UNION ALL
9+
SELECT col_text FROM tbl AS tbl2
10+
ORDER BY col_text
11+
LIMIT 0, 2;
12+
col_text
13+
SELECT FOUND_ROWS();
14+
FOUND_ROWS()
15+
0
16+
DROP TABLE tbl;

mysql-test/t/func_found_rows.test

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--echo #
2+
--echo # Bug #24714857 FOUND_ROWS() RETURNS 1 WHEN NO ROWS FOUND
3+
--echo #
4+
5+
CREATE TABLE tbl (
6+
col_text TEXT
7+
);
8+
9+
SELECT SQL_CALC_FOUND_ROWS col_text FROM tbl AS tbl1
10+
UNION ALL
11+
SELECT col_text FROM tbl AS tbl2
12+
ORDER BY col_text
13+
LIMIT 0, 2;
14+
15+
SELECT FOUND_ROWS();
16+
17+
DROP TABLE tbl;

storage/innobase/handler/ha_innodb.cc

+5-2
Original file line numberDiff line numberDiff line change
@@ -13883,9 +13883,12 @@ ha_innobase::info_low(
1388313883
HA_STATUS_TIME flag set, while the left join optimizer does not
1388413884
set that flag, we add one to a zero value if the flag is not
1388513885
set. That way SHOW TABLE STATUS will show the best estimate,
13886-
while the optimizer never sees the table empty. */
13886+
while the optimizer never sees the table empty.
13887+
However, if it is internal temporary table used by optimizer,
13888+
the count should be accurate */
1388713889

13888-
if (n_rows == 0 && !(flag & HA_STATUS_TIME)) {
13890+
if (n_rows == 0 && !(flag & HA_STATUS_TIME)
13891+
&& table_share->table_category != TABLE_CATEGORY_TEMPORARY) {
1388913892
n_rows++;
1389013893
}
1389113894

0 commit comments

Comments
 (0)