diff options
author | Igor Babaev <igor@askmonty.org> | 2011-05-27 00:03:55 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2011-05-27 00:03:55 -0700 |
commit | c9a349488b95a9a938564fe1ac06dafc70db5864 (patch) | |
tree | db5bff7867f4d077edaf2a9c9b4a737e25973dbf /sql | |
parent | 317e04ce67d97ab4a11582236f1e46ccf25c94fb (diff) | |
download | mariadb-git-c9a349488b95a9a938564fe1ac06dafc70db5864.tar.gz |
Applied Sanja's patch to fix LP bug #784297 in the tree for mwl106.
The patch imposes unconditional materialization for derived tables
used in update and multi-update statements.
Fixed a bug with a wrong order of processing derived tables/views
at the prepare stage that caused a crash for the variant of the
query from test case for bug 52157.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_lex.h | 2 | ||||
-rw-r--r-- | sql/sql_union.cc | 24 | ||||
-rw-r--r-- | sql/sql_update.cc | 4 | ||||
-rw-r--r-- | sql/table.cc | 8 |
4 files changed, 32 insertions, 6 deletions
diff --git a/sql/sql_lex.h b/sql/sql_lex.h index a587a01b3f4..014bcfdfd65 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -585,6 +585,8 @@ public: void set_thd(THD *thd_arg) { thd= thd_arg; } inline bool is_union (); + void set_unique_exlude(); + friend void lex_start(THD *thd); friend int subselect_union_engine::exec(); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 255f5311ac3..c6a6349fd4e 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -944,3 +944,27 @@ void st_select_lex::cleanup_all_joins(bool full) for (sl= unit->first_select(); sl; sl= sl->next_select()) sl->cleanup_all_joins(full); } + + +/** + Set exclude_from_table_unique_test for selects of this unit and all + underlying selects. + + @note used to exclude materialized derived tables (views) from unique + table check. +*/ + +void st_select_lex_unit::set_unique_exlude() +{ + for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select()) + { + sl->exclude_from_table_unique_test= TRUE; + for (SELECT_LEX_UNIT *unit= sl->first_inner_unit(); + unit; + unit= unit->next_unit()) + { + unit->set_unique_exlude(); + } + } +} + diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 215c5cbd4b3..4821fc2bd8f 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -1040,8 +1040,8 @@ reopen_tables: //We need to merge for insert prior to prepare. if (mysql_handle_list_of_derived(lex, table_list, DT_MERGE_FOR_INSERT)) DBUG_RETURN(1); - if (mysql_handle_list_of_derived(lex, table_list, DT_PREPARE)) - DBUG_RETURN(1); + if (mysql_handle_derived(lex, DT_PREPARE)) + DBUG_RETURN(TRUE); if (setup_tables_and_check_access(thd, &lex->select_lex.context, &lex->select_lex.top_join_list, diff --git a/sql/table.cc b/sql/table.cc index 290a82eb56a..3e6b683eafb 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -5851,7 +5851,9 @@ bool TABLE_LIST::init_derived(THD *thd, bool init_view) if (!is_view()) { /* A subquery might be forced to be materialized due to a side-effect. */ - if (!is_materialized_derived() && first_select->is_mergeable()) + if (!is_materialized_derived() && first_select->is_mergeable() && + !(thd->lex->sql_command == SQLCOM_UPDATE_MULTI || + thd->lex->sql_command == SQLCOM_UPDATE)) set_merged_derived(); else set_materialized_derived(); @@ -5862,9 +5864,7 @@ bool TABLE_LIST::init_derived(THD *thd, bool init_view) */ if (is_materialized_derived()) { - SELECT_LEX *sl; - for (sl= first_select ;sl ; sl= sl->next_select()) - sl->exclude_from_table_unique_test= TRUE; + unit->master_unit()->set_unique_exlude(); } /* Create field translation for mergeable derived tables/views. |