diff options
author | unknown <Sinisa@sinisa.nasamreza.org> | 2003-08-27 14:36:38 +0300 |
---|---|---|
committer | unknown <Sinisa@sinisa.nasamreza.org> | 2003-08-27 14:36:38 +0300 |
commit | 8a6f8201bec9b8b5c338cd7f5a9d3e42ab8b1457 (patch) | |
tree | 580538f16974ea7d0c8ebf343e76e523efdb91cf /sql/sql_union.cc | |
parent | 8e8e4fe059a8cebc4f8446f2b6cdcc810bdff9e0 (diff) | |
parent | 76438bd1bb07979badbd05048b7bb4a1b9fb333a (diff) | |
download | mariadb-git-8a6f8201bec9b8b5c338cd7f5a9d3e42ab8b1457.tar.gz |
merge fixes
sql/sql_lex.h:
Auto merged
sql/sql_select.cc:
Auto merged
Diffstat (limited to 'sql/sql_union.cc')
-rw-r--r-- | sql/sql_union.cc | 88 |
1 files changed, 49 insertions, 39 deletions
diff --git a/sql/sql_union.cc b/sql/sql_union.cc index ae91b0b3ace..57fc026f4f4 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -187,31 +187,34 @@ int st_select_lex_unit::prepare(THD *thd, select_result *sel_result, for (SELECT_LEX *sl= select_cursor; sl; sl= sl->next_select()) { - JOIN *join= new JOIN(thd, sl->item_list, - sl->options | thd->options | SELECT_NO_UNLOCK, - union_result); - thd->lex.current_select= sl; - offset_limit_cnt= sl->offset_limit; - select_limit_cnt= sl->select_limit+sl->offset_limit; - if (select_limit_cnt < sl->select_limit) - select_limit_cnt= HA_POS_ERROR; // no limit - if (select_limit_cnt == HA_POS_ERROR && !sl->braces) - sl->options&= ~OPTION_FOUND_ROWS; - - res= join->prepare(&sl->ref_pointer_array, - (TABLE_LIST*) sl->table_list.first, sl->with_wild, - sl->where, - ((sl->braces) ? sl->order_list.elements : 0) + - sl->group_list.elements, - (sl->braces) ? - (ORDER *)sl->order_list.first : (ORDER *) 0, - (ORDER*) sl->group_list.first, - sl->having, - (ORDER*) NULL, - sl, this, t_and_f); - t_and_f= 0; - if (res || thd->is_fatal_error) - goto err; + for (SELECT_LEX *sl= select_cursor; sl; sl= sl->next_select()) + { + JOIN *join= new JOIN(thd, sl->item_list, + sl->options | thd->options | SELECT_NO_UNLOCK, + union_result); + thd->lex.current_select= sl; + offset_limit_cnt= sl->offset_limit; + select_limit_cnt= sl->select_limit+sl->offset_limit; + if (select_limit_cnt < sl->select_limit) + select_limit_cnt= HA_POS_ERROR; // no limit + if (select_limit_cnt == HA_POS_ERROR || sl->braces) + sl->options&= ~OPTION_FOUND_ROWS; + + res= join->prepare(&sl->ref_pointer_array, + (TABLE_LIST*) sl->table_list.first, sl->with_wild, + sl->where, + ((sl->braces) ? sl->order_list.elements : 0) + + sl->group_list.elements, + (sl->braces) ? + (ORDER *)sl->order_list.first : (ORDER *) 0, + (ORDER*) sl->group_list.first, + sl->having, + (ORDER*) NULL, + sl, this, t_and_f); + t_and_f= 0; + if (res || thd->is_fatal_error) + goto err; + } } item_list.empty(); @@ -267,12 +270,15 @@ int st_select_lex_unit::exec() select_limit_cnt= sl->select_limit+sl->offset_limit; if (select_limit_cnt < sl->select_limit) select_limit_cnt= HA_POS_ERROR; // no limit - if (select_limit_cnt == HA_POS_ERROR) + if (select_limit_cnt == HA_POS_ERROR || sl->braces) sl->options&= ~OPTION_FOUND_ROWS; - else if (found_rows_for_union) + else { - rows= sl->select_limit; - sl->options|= OPTION_FOUND_ROWS; + /* + We are doing an union without braces. In this case + SQL_CALC_FOUND_ROWS should be done on all sub parts + */ + sl->options|= found_rows_for_union; } /* @@ -301,6 +307,7 @@ int st_select_lex_unit::exec() } if (!res) { + records_at_start= table->file->records; sl->join->exec(); res= sl->join->error; if (!res && union_result->flush()) @@ -314,10 +321,17 @@ int st_select_lex_unit::exec() thd->lex.current_select= lex_select_save; DBUG_RETURN(res); } - if (found_rows_for_union && !sl->braces && - (sl->options & OPTION_FOUND_ROWS)) - add_rows+= (sl->join->send_records > rows) ? - sl->join->send_records - rows : 0; + if (found_rows_for_union & sl->options) + { + /* + This is a union without braces. Remember the number of rows that could + also have been part of the result set. + We get this from the difference of between total number of possible + rows and actual rows added to the temporary table. + */ + add_rows+= (ulonglong) (thd->limit_found_rows - (table->file->records - + records_at_start)); + } } } optimized= 1; @@ -382,12 +396,8 @@ int st_select_lex_unit::exec() (ORDER*) NULL, NULL, (ORDER*) NULL, options | SELECT_NO_UNLOCK, result, this, fake_select_lex, 0); - if (found_rows_for_union && !res) - { - thd->limit_found_rows= table->file->records; - if (!select_cursor->braces) - thd->limit_found_rows+= add_rows; - } + if (!res) + thd->limit_found_rows = (ulonglong)table->file->records + add_rows; /* Mark for slow query log if any of the union parts didn't use indexes efficiently |