From a26847c2753bc9d0d8354e33de2281737522b6ef Mon Sep 17 00:00:00 2001 From: "Sinisa@sinisa.nasamreza.org" <> Date: Sat, 13 Sep 2003 19:56:58 +0300 Subject: [PATCH] Fixes for OPTION_FOUND_ROWS in UNION's --- mysql-test/r/subselect.result | 2 ++ mysql-test/r/union.result | 4 ++-- sql/sql_parse.cc | 2 +- sql/sql_union.cc | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 2c0947346be..e846f557c7c 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -1046,6 +1046,8 @@ t1 CREATE TABLE `t1` ( ) TYPE=MyISAM CHARSET=latin1 drop table t1; CREATE TABLE t1 SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a; +Warnings: +Warning 1262 Data truncated, NULL supplied to NOT NULL column 'a' at row 1 SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( diff --git a/mysql-test/r/union.result b/mysql-test/r/union.result index 952ed566132..2e962190762 100644 --- a/mysql-test/r/union.result +++ b/mysql-test/r/union.result @@ -409,7 +409,7 @@ found_rows() SELECT SQL_CALC_FOUND_ROWS * FROM t1 UNION SELECT * FROM t2 LIMIT 2,2; a 3 -4 +5 select found_rows(); found_rows() 6 @@ -423,7 +423,7 @@ found_rows() 5 SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY a desc LIMIT 1; a -5 +3 (SELECT * FROM t1 ORDER by a) UNION ALL (SELECT * FROM t2 ORDER BY a) ORDER BY A desc LIMIT 4; a 5 diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 9e7532c447d..d987a4ba8f1 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1729,7 +1729,7 @@ mysql_execute_command(THD *thd) if (unit->select_limit_cnt < (ha_rows) unit->global_parameters->select_limit) unit->select_limit_cnt= HA_POS_ERROR; // no limit - if (unit->select_limit_cnt == HA_POS_ERROR) + if (unit->select_limit_cnt == HA_POS_ERROR && !select_lex->next_select()) select_lex->options&= ~OPTION_FOUND_ROWS; if (!(res=open_and_lock_tables(thd,tables))) diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 381311b4975..2d7bee54da8 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -281,7 +281,7 @@ int st_select_lex_unit::exec() */ sl->options|= found_rows_for_union; } - + sl->join->select_options=sl->options; /* As far as union share table space we should reassign table map, which can be spoiled by 'prepare' of JOIN of other UNION parts @@ -311,6 +311,7 @@ int st_select_lex_unit::exec() records_at_start= table->file->records; sl->join->exec(); res= sl->join->error; + offset_limit_cnt= sl->offset_limit; if (!res && union_result->flush()) { thd->lex.current_select= lex_select_save; @@ -332,7 +333,7 @@ int st_select_lex_unit::exec() We get this from the difference of between total number of possible rows and actual rows added to the temporary table. */ - add_rows+= (ha_rows) (thd->limit_found_rows - (ulonglong) + add_rows+= (ulonglong) (thd->limit_found_rows - (ulonglong) ((table->file->records - records_at_start))); } }