summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <ram@gw.mysql.r18.ru>2004-05-28 15:01:16 +0500
committerunknown <ram@gw.mysql.r18.ru>2004-05-28 15:01:16 +0500
commit0cb0e7f5b9752e328d30d9704913f83508ef6161 (patch)
tree5f48561d37d69ca50e34a1c86a86666f1d7f4fa8
parenta4237f3dd9975aa54b3cbab8efb61ee9a74f5442 (diff)
downloadmariadb-git-0cb0e7f5b9752e328d30d9704913f83508ef6161.tar.gz
a fix.
(Bug#3738: SQL_CALC_FOUND_ROWS ignores WHERE if LIMIT used, Bug#3845: wrong FOUND_ROWS result)
-rw-r--r--mysql-test/r/select_found.result17
-rw-r--r--mysql-test/t/select_found.test19
-rw-r--r--sql/sql_select.cc6
3 files changed, 40 insertions, 2 deletions
diff --git a/mysql-test/r/select_found.result b/mysql-test/r/select_found.result
index 367bdd798b4..444124bcd67 100644
--- a/mysql-test/r/select_found.result
+++ b/mysql-test/r/select_found.result
@@ -206,3 +206,20 @@ WHERE ( r = 1 AND a IN ( 1, 2 ) AND ( u = 'w' OR u LIKE 'w/%' ) )
OR ( r = 1 AND a IN ( 3 ) AND ( u = 'w/U' OR u LIKE 'w/U/%' ) )
OR ( r = 1 AND a IN ( 1, 2, 3 ) AND ( u = 'w' ) );
drop table t1;
+CREATE TABLE t1 (a VARCHAR(16), UNIQUE(a));
+INSERT INTO t1 VALUES ('1'), ('2'), ('3');
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = '2' LIMIT 0, 1;
+a
+2
+SELECT FOUND_ROWS();
+FOUND_ROWS()
+1
+DROP TABLE t1;
+CREATE TABLE t1 (a INT);
+INSERT INTO t1 VALUES (0), (0), (1), (2);
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = 0 GROUP BY a HAVING a > 10;
+a
+SELECT FOUND_ROWS();
+FOUND_ROWS()
+0
+DROP TABLE t1;
diff --git a/mysql-test/t/select_found.test b/mysql-test/t/select_found.test
index e584fca206f..7599277a867 100644
--- a/mysql-test/t/select_found.test
+++ b/mysql-test/t/select_found.test
@@ -127,3 +127,22 @@ WHERE ( r = 1 AND a IN ( 1, 2 ) AND ( u = 'w' OR u LIKE 'w/%' ) )
OR ( r = 1 AND a IN ( 1, 2, 3 ) AND ( u = 'w' ) );
drop table t1;
+#
+# Bug #3738: we have a ref key
+#
+
+CREATE TABLE t1 (a VARCHAR(16), UNIQUE(a));
+INSERT INTO t1 VALUES ('1'), ('2'), ('3');
+SELECT SQL_CALC_FOUND_ROWS * FROM t1 WHERE a = '2' LIMIT 0, 1;
+SELECT FOUND_ROWS();
+DROP TABLE t1;
+
+#
+# Bug #3845: group by, having and empty result
+#
+
+CREATE TABLE t1 (a INT);
+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 FOUND_ROWS();
+DROP TABLE t1;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index b299e3af0b7..5b754186736 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -5348,7 +5348,8 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
if ((join->tables == 1) && !join->tmp_table && !join->sort_and_group
&& !join->send_group_parts && !join->having && !jt->select_cond &&
!(jt->select && jt->select->quick) &&
- !(jt->table->file->table_flags() & HA_NOT_EXACT_COUNT))
+ !(jt->table->file->table_flags() & HA_NOT_EXACT_COUNT) &&
+ (jt->ref.key < 0))
{
/* Join over all rows in table; Return number of found rows */
TABLE *table=jt->table;
@@ -5429,7 +5430,8 @@ end_send_group(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
DBUG_RETURN(-1); /* purecov: inspected */
if (end_of_records)
{
- join->send_records++;
+ if (!error)
+ join->send_records++;
DBUG_RETURN(0);
}
if (!error &&