diff options
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r-- | sql/sql_lex.cc | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 460b840ef8a..61df2f153db 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -1323,6 +1323,8 @@ void LEX::start(THD *thd_arg) frame_bottom_bound= NULL; win_spec= NULL; + upd_del_where= NULL; + vers_conditions.empty(); period_conditions.empty(); @@ -3056,6 +3058,7 @@ void st_select_lex::init_select() in_funcs.empty(); curr_tvc_name= 0; versioned_tables= 0; + is_tvc_wrapper= false; nest_flags= 0; } @@ -3980,57 +3983,54 @@ LEX::LEX() } +bool LEX::can_be_merged() +{ + return unit.can_be_merged(); +} + + /* - Check whether the merging algorithm can be used on this VIEW + Check whether the merging algorithm can be used for this unit SYNOPSIS - LEX::can_be_merged() + st_select_lex_unit::can_be_merged() DESCRIPTION - We can apply merge algorithm if it is single SELECT view with - subqueries only in WHERE clause (we do not count SELECTs of underlying - views, and second level subqueries) and we have not grpouping, ordering, - HAVING clause, aggregate functions, DISTINCT clause, LIMIT clause and - several underlying tables. + We can apply merge algorithm for a unit if it is single SELECT with + subqueries only in WHERE clauses or in ON conditions or in select list + (we do not count SELECTs of underlying views/derived tables/CTEs and + second level subqueries) and we have no grouping, ordering, HAVING + clause, aggregate functions, DISTINCT clause, LIMIT clause. RETURN FALSE - only temporary table algorithm can be used TRUE - merge algorithm can be used */ -bool LEX::can_be_merged() +bool st_select_lex_unit::can_be_merged() { // TODO: do not forget implement case when select_lex.table_list.elements==0 /* find non VIEW subqueries/unions */ - bool selects_allow_merge= (first_select_lex()->next_select() == 0 && - !(first_select_lex()->uncacheable & - UNCACHEABLE_RAND)); - if (selects_allow_merge) - { - for (SELECT_LEX_UNIT *tmp_unit= first_select_lex()->first_inner_unit(); - tmp_unit; - tmp_unit= tmp_unit->next_unit()) - { - if (tmp_unit->first_select()->parent_lex == this && - (tmp_unit->item != 0 && - (tmp_unit->item->place() != IN_WHERE && - tmp_unit->item->place() != IN_ON && - tmp_unit->item->place() != SELECT_LIST))) - { - selects_allow_merge= 0; - break; - } - } - } - - return (selects_allow_merge && - first_select_lex()->group_list.elements == 0 && - first_select_lex()->having == 0 && - first_select_lex()->with_sum_func == 0 && - first_select_lex()->table_list.elements >= 1 && - !(first_select_lex()->options & SELECT_DISTINCT) && - first_select_lex()->limit_params.select_limit == 0); + st_select_lex *fs= first_select(); + + if (fs->next_select() || + (fs->uncacheable & UNCACHEABLE_RAND) || + (fs->options & SELECT_DISTINCT) || + fs->group_list.elements || fs->having || + fs->with_sum_func || + fs->table_list.elements < 1 || + fs->limit_params.select_limit) + return false; + for (SELECT_LEX_UNIT *tmp_unit= fs->first_inner_unit(); + tmp_unit; + tmp_unit= tmp_unit->next_unit()) + if ((tmp_unit->item != 0 && + (tmp_unit->item->place() != IN_WHERE && + tmp_unit->item->place() != IN_ON && + tmp_unit->item->place() != SELECT_LIST))) + return false; + return true; } @@ -4105,9 +4105,7 @@ bool LEX::can_not_use_merged(bool no_update_or_delete) case SQLCOM_UPDATE_MULTI: case SQLCOM_DELETE_MULTI: - if (no_update_or_delete) - return TRUE; - /* Fall through */ + return no_update_or_delete; default: return FALSE; |