summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2014-06-05 15:59:46 +0200
committerSergei Golubchik <sergii@pisem.net>2014-06-05 15:59:46 +0200
commit2d2697ea8d6b6ef07836c9af06fc0d4eca6aa77b (patch)
tree7d08a0107411367968a068e7726ba0c7d92aa3c4
parentfde6ee61bbdeb051a169aac8da56e24bf2accdce (diff)
downloadmariadb-git-2d2697ea8d6b6ef07836c9af06fc0d4eca6aa77b.tar.gz
MDEV-6221 SQL_CALC_FOUND_ROWS yields wrong result again
replace another old "was there a filesort?" test with a correct "did filesort calculate found_rows?" test.
-rw-r--r--mysql-test/r/select_found.result17
-rw-r--r--mysql-test/t/select_found.test16
-rw-r--r--sql/sql_select.cc3
3 files changed, 34 insertions, 2 deletions
diff --git a/mysql-test/r/select_found.result b/mysql-test/r/select_found.result
index 933c69055a1..04eb2c90d31 100644
--- a/mysql-test/r/select_found.result
+++ b/mysql-test/r/select_found.result
@@ -315,3 +315,20 @@ select found_rows();
found_rows()
128
drop table t1, t2;
+create table t1 (i1 int, v1 int, primary key(i1,v1));
+insert into t1 values (1,1),(2,2),(3,3);
+create table t2 (i2 int primary key, v2 int);
+insert into t2 values (1,5),(2,5),(3,10);
+select 1 as res from t1 left join t2 on i1 = i2 where v2 = 5 or v1 = 5 or v1 = 10 order by v1;
+res
+1
+1
+select sql_calc_found_rows 1 as res from t1 left join t2 on i1 = i2 where v2 = 5 or v1 = 5 or v1 = 10 order by v1 limit 1;
+select found_rows() as count;
+count
+2
+select sql_calc_found_rows 1 as res from t1 left join t2 on i1 = i2 where v2 = 5 order by v1 limit 1;
+select found_rows() as count;
+count
+2
+drop table t1, t2;
diff --git a/mysql-test/t/select_found.test b/mysql-test/t/select_found.test
index 5571d51830b..d529dc415e7 100644
--- a/mysql-test/t/select_found.test
+++ b/mysql-test/t/select_found.test
@@ -241,3 +241,19 @@ select found_rows();
drop table t1, t2;
+#
+# MDEV-6221 SQL_CALC_FOUND_ROWS yields wrong result again
+#
+create table t1 (i1 int, v1 int, primary key(i1,v1));
+insert into t1 values (1,1),(2,2),(3,3);
+create table t2 (i2 int primary key, v2 int);
+insert into t2 values (1,5),(2,5),(3,10);
+select 1 as res from t1 left join t2 on i1 = i2 where v2 = 5 or v1 = 5 or v1 = 10 order by v1;
+--disable_result_log ONCE
+select sql_calc_found_rows 1 as res from t1 left join t2 on i1 = i2 where v2 = 5 or v1 = 5 or v1 = 10 order by v1 limit 1;
+select found_rows() as count;
+--disable_result_log ONCE
+select sql_calc_found_rows 1 as res from t1 left join t2 on i1 = i2 where v2 = 5 order by v1 limit 1;
+select found_rows() as count;
+drop table t1, t2;
+
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 727560dd173..5db11f3d339 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -18724,8 +18724,7 @@ end_send(JOIN *join, JOIN_TAB *join_tab __attribute__((unused)),
TABLE *table=jt->table;
join->select_options ^= OPTION_FOUND_ROWS;
- if (table->sort.record_pointers ||
- (table->sort.io_cache && my_b_inited(table->sort.io_cache)))
+ if (join->filesort_found_rows)
{
/* Using filesort */
join->send_records= table->sort.found_records;