diff --git a/Docs/manual.texi b/Docs/manual.texi index 2f0ad4f4458..2f156ca198e 100644 --- a/Docs/manual.texi +++ b/Docs/manual.texi @@ -48946,6 +48946,10 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}. @itemize @bullet @item +fixed that SQL_CALC_FOUND_ROWS works with UNIONs. It will work only if first +select has this option and if there is global LIMIT for entire select. For the +moment this requires using braces for individual select's. +@item Don't give an error for @code{CREATE TABLE ...(... VARCHAR(0))}. @item Fixed @code{SIGINT} and @code{SIGQUIT} problems in @file{mysql.cc} on Linux diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 76f09d6b330..7d914d029af 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -89,6 +89,13 @@ table type possible_keys key key_len ref rows Extra t1 ALL NULL NULL NULL NULL 4 t2 ALL NULL NULL NULL NULL 4 Using filesort t1 ALL NULL NULL NULL NULL 4 +(select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2; +a b +1 a +2 b +select found_rows(); +FOUND_ROWS() +6 explain select a,b from t1 union all select a,b from t2; table type possible_keys key key_len ref rows Extra t1 ALL NULL NULL NULL NULL 4 diff --git a/mysql-test/t/union.test b/mysql-test/t/union.test index e62ca6d2700..f5a92b05e0d 100644 --- a/mysql-test/t/union.test +++ b/mysql-test/t/union.test @@ -21,7 +21,8 @@ select 't1',b,count(*) from t1 group by b UNION select 't2',b,count(*) from t2 g (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1); (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; explain (select a,b from t1 limit 2) union all (select a,b from t2 order by a limit 1) order by b desc; - +(select sql_calc_found_rows a,b from t1 limit 2) union all (select a,b from t2 order by a) limit 2; +select found_rows(); # Test some error conditions with UNION explain select a,b from t1 union all select a,b from t2; diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 541b2383e8d..7294d287bb5 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -33,6 +33,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result) TABLE *table; int describe=(lex->select_lex.options & SELECT_DESCRIBE) ? 1 : 0; int res; + bool fr=false; TABLE_LIST result_table_list; TABLE_LIST *first_table=(TABLE_LIST *)lex->select_lex.table_list.first; TMP_TABLE_PARAM tmp_table_param; @@ -60,6 +61,7 @@ int mysql_union(THD *thd, LEX *lex,select_result *result) */ lex_sl= sl; order= (ORDER *) lex_sl->order_list.first; + fr = lex->select_lex.options & OPTION_FOUND_ROWS && !describe && sl->select_limit && sl->select_limit != HA_POS_ERROR; if (!order || !describe) last_sl->next=0; // Remove this extra element } @@ -198,6 +200,8 @@ int mysql_union(THD *thd, LEX *lex,select_result *result) item_list, NULL, (describe) ? 0 : order, (ORDER*) NULL, NULL, (ORDER*) NULL, thd->options, result); + if (fr && !res) + thd->limit_found_rows = (ulonglong)table->file->records; } }