From 7f345153f91c5395e5ab4ce5906fcabbb6d06f51 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 9 Jun 2011 00:13:00 -0700 Subject: Fixed LP bug #794038. INSERT/UPDATE/DELETE statement that used a temptable view v1 could lead to a crash if v1 was defined as a select from a mergeable view v2 that selected rows from a temptable view v3. When INSERT/UPDATE/DELETE uses a view that is not updatable then field translation for the view should be created before the prepare phase. --- sql/sql_derived.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'sql/sql_derived.cc') diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index ca56f0fa0a6..9bfa49c5f2d 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -467,6 +467,12 @@ bool mysql_derived_merge_for_insert(THD *thd, LEX *lex, TABLE_LIST *derived) if (derived->merged_for_insert) return FALSE; + /* It's a target view for an INSERT, create field translation only. */ + if (!derived->updatable || derived->is_materialized_derived()) + { + bool res= derived->create_field_translation(thd); + return res; + } if (!derived->is_multitable()) { TABLE_LIST *tl=((TABLE_LIST*)dt_select->table_list.first); @@ -603,16 +609,9 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) bool res= FALSE; // Skip already prepared views/DT - if (!unit || unit->prepared) + if (!unit || unit->prepared || derived->merged_for_insert) DBUG_RETURN(FALSE); - /* It's a target view for an INSERT, create field translation only. */ - if (derived->merged_for_insert) - { - res= derived->create_field_translation(thd); - DBUG_RETURN(res); - } - Query_arena *arena= thd->stmt_arena, backup; if (arena->is_conventional()) arena= 0; // For easier test -- cgit v1.2.1