Commit 3bffc522 authored by unknown's avatar unknown

A fix (bug #6089: FOUND_ROWS returns wrong values when no table/view is used).


mysql-test/r/ps.result:
  A fix (bug #6089: FOUND_ROWS returns wrong values when no table/view is used).
  The second FOUND_ROWS() should return 1.
sql/sql_class.cc:
  A fix (bug #6089: FOUND_ROWS returns wrong values when no table/view is used).
  limit_found_rows initialization added.
sql/sql_select.cc:
  A fix (bug #6089: FOUND_ROWS returns wrong values when no table/view is used).
  thd->limit_found_rows is set to 1 when no table is used.
parent 55833fb4
...@@ -135,7 +135,7 @@ FOUND_ROWS() ...@@ -135,7 +135,7 @@ FOUND_ROWS()
1 1
execute stmt1; execute stmt1;
FOUND_ROWS() FOUND_ROWS()
0 1
deallocate prepare stmt1; deallocate prepare stmt1;
drop table t1; drop table t1;
create table t1 create table t1
......
...@@ -246,3 +246,28 @@ SELECT FOUND_ROWS(); ...@@ -246,3 +246,28 @@ SELECT FOUND_ROWS();
FOUND_ROWS() FOUND_ROWS()
0 0
DROP TABLE t1; DROP TABLE t1;
SELECT 'foo';
foo
foo
SELECT FOUND_ROWS();
FOUND_ROWS()
1
SELECT SQL_CALC_FOUND_ROWS 'foo';
foo
foo
SELECT FOUND_ROWS();
FOUND_ROWS()
1
SELECT SQL_CALC_FOUND_ROWS 'foo' limit 0;
foo
SELECT FOUND_ROWS();
FOUND_ROWS()
1
SELECT FOUND_ROWS();
FOUND_ROWS()
1
SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0;
foo
SELECT FOUND_ROWS();
FOUND_ROWS()
2
...@@ -166,3 +166,18 @@ INSERT INTO t1 VALUES (0), (0), (1), (2); ...@@ -166,3 +166,18 @@ INSERT INTO t1 VALUES (0), (0), (1), (2);
SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = 0 GROUP BY a HAVING a > 10; SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = 0 GROUP BY a HAVING a > 10;
SELECT FOUND_ROWS(); SELECT FOUND_ROWS();
DROP TABLE t1; DROP TABLE t1;
#
# Bug #6089: queries which don't use any tables
#
SELECT 'foo';
SELECT FOUND_ROWS();
SELECT SQL_CALC_FOUND_ROWS 'foo';
SELECT FOUND_ROWS();
SELECT SQL_CALC_FOUND_ROWS 'foo' limit 0;
SELECT FOUND_ROWS();
SELECT FOUND_ROWS();
SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0;
SELECT FOUND_ROWS();
...@@ -177,6 +177,7 @@ THD::THD() ...@@ -177,6 +177,7 @@ THD::THD()
lock=locked_tables=0; lock=locked_tables=0;
used_tables=0; used_tables=0;
cuted_fields= sent_row_count= 0L; cuted_fields= sent_row_count= 0L;
limit_found_rows= 0;
statement_id_counter= 0UL; statement_id_counter= 0UL;
// Must be reset to handle error with THD's created for init of mysqld // Must be reset to handle error with THD's created for init of mysqld
lex->current_select= 0; lex->current_select= 0;
......
...@@ -1067,7 +1067,9 @@ JOIN::exec() ...@@ -1067,7 +1067,9 @@ JOIN::exec()
else else
error=(int) result->send_eof(); error=(int) result->send_eof();
} }
thd->limit_found_rows= thd->examined_row_count= 0; /* Single select (without union and limit) always returns 1 row */
thd->limit_found_rows= 1;
thd->examined_row_count= 0;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
thd->limit_found_rows= thd->examined_row_count= 0; thd->limit_found_rows= thd->examined_row_count= 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment