List:Commits« Previous MessageNext Message »
From:Konstantin Osipov Date:July 14 2010 3:52pm
Subject:bzr commit into mysql-trunk-runtime branch (kostja:3079)
View as plain text  
#At file:///opt/local/work/trunk-runtime/ based on revid:jon.hauglid@stripped

 3079 Konstantin Osipov	2010-07-14
      Intermediate commit.

    modified:
      sql/event_data_objects.cc
      sql/sp.cc
      sql/sp_head.cc
      sql/sp_head.h
      sql/sql_lex.cc
      sql/sql_parse.cc
      sql/sql_parse.h
      sql/sql_prepare.cc
      sql/sql_trigger.cc
=== modified file 'sql/event_data_objects.cc'
--- a/sql/event_data_objects.cc	2010-07-08 21:20:08 +0000
+++ b/sql/event_data_objects.cc	2010-07-14 15:52:44 +0000
@@ -1402,6 +1402,8 @@ Event_job_data::execute(THD *thd, bool d
   */
   thd->set_db(dbname.str, dbname.length);
 
+  lex_start(thd);
+
 #ifndef NO_EMBEDDED_ACCESS_CHECKS
   if (event_sctx.change_security_context(thd,
                                          &definer_user, &definer_host,
@@ -1411,7 +1413,7 @@ Event_job_data::execute(THD *thd, bool d
                     "[%s].[%s.%s] execution failed, "
                     "failed to authenticate the user.",
                     definer.str, dbname.str, name.str);
-    goto end_no_lex_start;
+    goto end;
   }
 #endif
 
@@ -1427,11 +1429,11 @@ Event_job_data::execute(THD *thd, bool d
                     "[%s].[%s.%s] execution failed, "
                     "user no longer has EVENT privilege.",
                     definer.str, dbname.str, name.str);
-    goto end_no_lex_start;
+    goto end;
   }
 
   if (construct_sp_sql(thd, &sp_sql))
-    goto end_no_lex_start;
+    goto end;
 
   /*
     Set up global thread attributes to reflect the properties of
@@ -1451,8 +1453,6 @@ Event_job_data::execute(THD *thd, bool d
     if (parser_state.init(thd, thd->query(), thd->query_length()))
       goto end;
 
-    lex_start(thd);
-
     if (parse_sql(thd, & parser_state, creation_ctx))
     {
       sql_print_error("Event Scheduler: "
@@ -1484,13 +1484,6 @@ Event_job_data::execute(THD *thd, bool d
   }
 
 end:
-  if (thd->lex->sphead)                        /* NULL only if a parse error */
-  {
-    delete thd->lex->sphead;
-    thd->lex->sphead= NULL;
-  }
-
-end_no_lex_start:
   if (drop && !thd->is_fatal_error)
   {
     /*
@@ -1529,8 +1522,8 @@ end_no_lex_start:
   if (save_sctx)
     event_sctx.restore_security_context(thd, save_sctx);
 #endif
-  lex_end(thd->lex);
   thd->lex->unit.cleanup();
+  lex_end(thd->lex);
   thd->end_statement();
   thd->cleanup_after_query();
   /* Avoid races with SHOW PROCESSLIST */

=== modified file 'sql/sp.cc'
--- a/sql/sp.cc	2010-06-11 13:54:39 +0000
+++ b/sql/sp.cc	2010-07-14 15:52:44 +0000
@@ -856,6 +856,7 @@ db_load_routine(THD *thd, int type, sp_n
   }
 
 end:
+  thd->lex->sphead= NULL;
   lex_end(thd->lex);
   thd->lex= old_lex;
   return ret;
@@ -2142,6 +2143,7 @@ sp_load_for_information_schema(THD *thd,
   newlex.current_select= NULL; 
   sp= sp_compile(thd, &defstr, sql_mode, creation_ctx);
   *free_sp_head= 1;
+  thd->lex->sphead= NULL;
   lex_end(thd->lex);
   thd->lex= old_lex;
   return sp;

=== modified file 'sql/sp_head.cc'
--- a/sql/sp_head.cc	2010-06-17 13:31:51 +0000
+++ b/sql/sp_head.cc	2010-07-14 15:52:44 +0000
@@ -795,6 +795,7 @@ sp_head::~sp_head()
   while ((lex= (LEX *)m_lex.pop()))
   {
     THD *thd= lex->thd;
+    thd->lex->sphead= NULL;
     lex_end(thd->lex);
     delete thd->lex;
     thd->lex= lex;
@@ -2197,6 +2198,7 @@ sp_head::restore_lex(THD *thd)
   merge_table_list(thd, sublex->query_tables, sublex);
   if (! sublex->sp_lex_in_use)
   {
+    sublex->sphead= NULL;
     lex_end(sublex);
     delete sublex;
   }
@@ -2806,13 +2808,20 @@ sp_lex_keeper::reset_lex_and_exec_core(T
     DBUG_PRINT("info",("exec_core returned: %d", res));
   }
 
-  m_lex->unit.cleanup();
-
-  thd_proc_info(thd, "closing tables");
-  /* Here we also commit or rollback the current statement. */
-  close_thread_tables(thd);
-  thd_proc_info(thd, 0);
-
+  /*
+    Sic: call close_thread_tables() even if
+    exec_open_and_lock_tables() failed.
+    Call after unit->cleanup() to close open table
+    key read.
+  */
+  if (open_tables)
+  {
+    m_lex->unit.cleanup();
+    thd_proc_info(thd, "closing tables");
+    /* Here we also commit or rollback the current statement. */
+    close_thread_tables(thd);
+    thd_proc_info(thd, 0);
+  }
   if (m_lex->query_tables_own_last)
   {
     /*

=== modified file 'sql/sp_head.h'
--- a/sql/sp_head.h	2010-06-06 11:19:29 +0000
+++ b/sql/sp_head.h	2010-07-14 15:52:44 +0000
@@ -682,6 +682,8 @@ public:
   {
     if (m_lex_resp)
     {
+      /* Prevent endless recursion. */
+      m_lex->sphead= NULL;
       lex_end(m_lex);
       delete m_lex;
     }

=== modified file 'sql/sql_lex.cc'
--- a/sql/sql_lex.cc	2010-07-08 21:20:08 +0000
+++ b/sql/sql_lex.cc	2010-07-14 15:52:44 +0000
@@ -450,6 +450,9 @@ void lex_end(LEX *lex)
   }
   reset_dynamic(&lex->plugins);
 
+  delete lex->sphead;
+  lex->sphead= NULL;
+
   DBUG_VOID_RETURN;
 }
 

=== modified file 'sql/sql_parse.cc'
--- a/sql/sql_parse.cc	2010-07-13 08:39:24 +0000
+++ b/sql/sql_parse.cc	2010-07-14 15:52:44 +0000
@@ -115,6 +115,7 @@
    "FUNCTION" : "PROCEDURE")
 
 static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
+static void sql_kill(THD *thd, ulong id, bool only_kill_query);
 
 const char *any_db="*any*";	// Special symbol for check_access
 
@@ -568,7 +569,6 @@ static void handle_bootstrap_impl(THD *t
     }
 
     mysql_parse(thd, thd->query(), length, &parser_state);
-    close_thread_tables(thd);			// Free tables
 
     bootstrap_error= thd->is_error();
     thd->protocol->end_statement();
@@ -1139,13 +1139,11 @@ bool dispatch_command(enum enum_server_c
     {
       char *beginning_of_next_stmt= (char*)
         parser_state.m_lip.found_semicolon;
-
-      thd->protocol->end_statement();
-      query_cache_end_of_result(thd);
       /*
         Multiple queries exits, execute them individually
       */
-      close_thread_tables(thd);
+      thd->protocol->end_statement();
+      query_cache_end_of_result(thd);
       ulong length= (ulong)(packet_end - beginning_of_next_stmt);
 
       log_slow_statement(thd);
@@ -1255,7 +1253,6 @@ bool dispatch_command(enum enum_server_c
     /* init structures for VIEW processing */
     table_list.select_lex= &(thd->lex->select_lex);
 
-    lex_start(thd);
     mysql_reset_thd_for_next_command(thd);
 
     thd->lex->
@@ -1268,6 +1265,7 @@ bool dispatch_command(enum enum_server_c
     thd->lex->sql_command= SQLCOM_SHOW_FIELDS;
     mysqld_list_fields(thd,&table_list,fields);
     thd->lex->unit.cleanup();
+    close_thread_tables(thd);
     thd->cleanup_after_query();
     break;
   }
@@ -1315,7 +1313,6 @@ bool dispatch_command(enum enum_server_c
     ulong options= (ulong) (uchar) packet[0];
     if (trans_commit_implicit(thd))
       break;
-    close_thread_tables(thd);
     thd->mdl_context.release_transactional_locks();
     if (check_global_access(thd,RELOAD_ACL))
       break;
@@ -1480,29 +1477,9 @@ bool dispatch_command(enum enum_server_c
     my_message(ER_UNKNOWN_COM_ERROR, ER(ER_UNKNOWN_COM_ERROR), MYF(0));
     break;
   }
-
-  /* report error issued during command execution */
-  if (thd->killed_errno())
-  {
-    if (! thd->stmt_da->is_set())
-      thd->send_kill_message();
-  }
-  if (thd->killed == THD::KILL_QUERY || thd->killed == THD::KILL_BAD_DATA)
-  {
-    thd->killed= THD::NOT_KILLED;
-    thd->mysys_var->abort= 0;
-  }
-
-  /* If commit fails, we should be able to reset the OK status. */
-  thd->stmt_da->can_overwrite_status= TRUE;
-  thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd);
-  thd->stmt_da->can_overwrite_status= FALSE;
-
-  thd->transaction.stmt.reset();
-
-  thd->proc_info= "closing tables";
-  /* Free tables */
-  close_thread_tables(thd);
+  DBUG_ASSERT(thd->derived_tables == NULL &&
+              (thd->open_tables == NULL ||
+               (thd->locked_tables_mode == LTM_LOCK_TABLES)));
 
   thd->protocol->end_statement();
   query_cache_end_of_result(thd);
@@ -2223,7 +2200,6 @@ mysql_execute_command(THD *thd)
     if (trans_commit_implicit(thd))
       goto error;
     /* Close tables and release metadata locks. */
-    close_thread_tables(thd);
     thd->mdl_context.release_transactional_locks();
   }
 
@@ -4778,17 +4754,38 @@ finish:
   DBUG_ASSERT(!thd->in_active_multi_stmt_transaction() ||
                thd->in_multi_stmt_transaction_mode());
 
+  /* report error issued during command execution */
+  if (thd->killed_errno())
+  {
+    if (! thd->stmt_da->is_set())
+      thd->send_kill_message();
+  }
+  if (thd->killed == THD::KILL_QUERY || thd->killed == THD::KILL_BAD_DATA)
+  {
+    thd->killed= THD::NOT_KILLED;
+    thd->mysys_var->abort= 0;
+  }
+
+  /* If commit fails, we should be able to reset the OK status. */
+  thd->stmt_da->can_overwrite_status= TRUE;
+  thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd);
+  thd->stmt_da->can_overwrite_status= FALSE;
+
+  thd->transaction.stmt.reset();
+
+  lex->unit.cleanup();
+  thd_proc_info(thd, "closing tables");
+  /* Free tables */
+  close_thread_tables(thd);
+  thd_proc_info(thd, 0);
+
   if (stmt_causes_implicit_commit(thd, CF_IMPLICIT_COMMIT_END))
   {
     /* If commit fails, we should be able to reset the OK status. */
     thd->stmt_da->can_overwrite_status= TRUE;
-    /* Commit or rollback the statement transaction. */
-    thd->is_error() ? trans_rollback_stmt(thd) : trans_commit_stmt(thd);
     /* Commit the normal transaction if one is active. */
     trans_commit_implicit(thd);
     thd->stmt_da->can_overwrite_status= FALSE;
-    /* Close tables and release metadata locks. */
-    close_thread_tables(thd);
     thd->mdl_context.release_transactional_locks();
   }
 
@@ -5886,12 +5883,6 @@ void mysql_parse(THD *thd, const char *i
 
       query_cache_abort(&thd->query_cache_tls);
     }
-    if (thd->lex->sphead)
-    {
-      delete thd->lex->sphead;
-      thd->lex->sphead= 0;
-    }
-    lex->unit.cleanup();
     thd_proc_info(thd, "freeing items");
     thd->end_statement();
     thd->cleanup_after_query();
@@ -6997,11 +6988,15 @@ uint kill_one_thread(THD *thd, ulong id,
     only_kill_query     Should it kill the query or the connection
 */
 
+static
 void sql_kill(THD *thd, ulong id, bool only_kill_query)
 {
   uint error;
   if (!(error= kill_one_thread(thd, id, only_kill_query)))
-    my_ok(thd);
+  {
+    if (! thd->killed)
+      my_ok(thd);
+  }
   else
     my_error(error, MYF(0), id);
 }

=== modified file 'sql/sql_parse.h'
--- a/sql/sql_parse.h	2010-06-17 13:31:51 +0000
+++ b/sql/sql_parse.h	2010-07-14 15:52:44 +0000
@@ -51,7 +51,6 @@ bool parse_sql(THD *thd,
                Object_creation_ctx *creation_ctx);
 
 uint kill_one_thread(THD *thd, ulong id, bool only_kill_query);
-void sql_kill(THD *thd, ulong id, bool only_kill_query);
 
 void free_items(Item *item);
 void cleanup_items(Item *item);

=== modified file 'sql/sql_prepare.cc'
--- a/sql/sql_prepare.cc	2010-06-17 13:31:51 +0000
+++ b/sql/sql_prepare.cc	2010-07-14 15:52:44 +0000
@@ -90,7 +90,7 @@ When one supplies long data for a placeh
 #include "set_var.h"
 #include "sql_prepare.h"
 #include "sql_parse.h" // insert_precheck, update_precheck, delete_precheck
-#include "sql_base.h"  // close_thread_tables
+#include "sql_base.h"  // open_normal_and_derived_tables
 #include "sql_cache.h"                          // query_cache_*
 #include "sql_view.h"                          // create_view_precheck
 #include "sql_delete.h"                        // mysql_prepare_delete
@@ -2960,12 +2960,6 @@ Execute_sql_statement::execute_server_co
 
   error= mysql_execute_command(thd);
 
-  if (thd->killed_errno())
-  {
-    if (! thd->stmt_da->is_set())
-      thd->send_kill_message();
-  }
-
   /* report error issued during command execution */
   if (error == 0 && thd->spcont == NULL)
     general_log_write(thd, COM_STMT_EXECUTE,
@@ -3073,13 +3067,8 @@ void Prepared_statement::cleanup_stmt()
   DBUG_ENTER("Prepared_statement::cleanup_stmt");
   DBUG_PRINT("enter",("stmt: 0x%lx", (long) this));
 
-  delete lex->sphead;
-  lex->sphead= 0;
-  /* The order is important */
-  lex->unit.cleanup();
   cleanup_items(free_list);
   thd->cleanup_after_query();
-  close_thread_tables(thd);
   thd->rollback_item_tree_changes();
 
   DBUG_VOID_RETURN;
@@ -3243,12 +3232,9 @@ bool Prepared_statement::prepare(const c
     to PREPARE stmt FROM "CREATE PROCEDURE ..."
   */
   DBUG_ASSERT(lex->sphead == NULL || error != 0);
-  if (lex->sphead)
-  {
-    delete lex->sphead;
-    lex->sphead= NULL;
-  }
-
+  /* The order is important */
+  lex->unit.cleanup();
+  close_thread_tables(thd);
   lex_end(lex);
   cleanup_stmt();
   /*
@@ -3364,11 +3350,6 @@ Prepared_statement::set_parameters(Strin
   and execute of a new statement. If this happens repeatedly
   more than MAX_REPREPARE_ATTEMPTS times, we give up.
 
-  In future we need to be able to keep the metadata locks between
-  prepare and execute, but right now open_and_lock_tables(), as
-  well as close_thread_tables() are buried deep inside
-  execution code (mysql_execute_command()).
-
   @return TRUE if an error, FALSE if success
   @retval  TRUE    either MAX_REPREPARE_ATTEMPTS has been reached,
                    or some general error
@@ -3455,11 +3436,6 @@ Prepared_statement::execute_server_runna
 
   error= server_runnable->execute_server_code(thd);
 
-  delete lex->sphead;
-  lex->sphead= 0;
-  /* The order is important */
-  lex->unit.cleanup();
-  close_thread_tables(thd);
   thd->cleanup_after_query();
 
   thd->restore_active_arena(this, &stmt_backup);

=== modified file 'sql/sql_trigger.cc'
--- a/sql/sql_trigger.cc	2010-06-17 13:31:51 +0000
+++ b/sql/sql_trigger.cc	2010-07-14 15:52:44 +0000
@@ -1321,6 +1321,7 @@ bool Table_triggers_list::check_n_load(T
       thd->reset_db((char*) db, strlen(db));
       while ((trg_create_str= it++))
       {
+        sp_head *sp;
         trg_sql_mode= itm++;
         LEX_STRING *trg_definer= it_definer++;
 
@@ -1357,13 +1358,14 @@ bool Table_triggers_list::check_n_load(T
         */
         lex.set_trg_event_type_for_tables();
 
-        lex.sphead->set_info(0, 0, &lex.sp_chistics, (ulong) *trg_sql_mode);
-
         int event= lex.trg_chistics.event;
         int action_time= lex.trg_chistics.action_time;
 
-        lex.sphead->set_creation_ctx(creation_ctx);
-        triggers->bodies[event][action_time]= lex.sphead;
+        sp= triggers->bodies[event][action_time]= lex.sphead;
+        lex.sphead= NULL; /* Prevent double cleanup. */
+
+        sp->set_info(0, 0, &lex.sp_chistics, (ulong) *trg_sql_mode);
+        sp->set_creation_ctx(creation_ctx);
 
         if (!trg_definer->length)
         {
@@ -1376,27 +1378,26 @@ bool Table_triggers_list::check_n_load(T
             push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
                                 ER_TRG_NO_DEFINER, ER(ER_TRG_NO_DEFINER),
                                 (const char*) db,
-                                (const char*) lex.sphead->m_name.str);
+                                (const char*) sp->m_name.str);
           
           /*
             Set definer to the '' to correct displaying in the information
             schema.
           */
 
-          lex.sphead->set_definer((char*) "", 0);
+          sp->set_definer((char*) "", 0);
 
           /*
             Triggers without definer information are executed under the
             authorization of the invoker.
           */
 
-          lex.sphead->m_chistics->suid= SP_IS_NOT_SUID;
+          sp->m_chistics->suid= SP_IS_NOT_SUID;
         }
         else
-          lex.sphead->set_definer(trg_definer->str, trg_definer->length);
+          sp->set_definer(trg_definer->str, trg_definer->length);
 
-        if (triggers->names_list.push_back(&lex.sphead->m_name,
-                                           &table->mem_root))
+        if (triggers->names_list.push_back(&sp->m_name, &table->mem_root))
             goto err_with_lex_cleanup;
 
         if (!(on_table_name= alloc_lex_string(&table->mem_root)))


Attachment: [text/bzr-bundle] bzr/kostja@sun.com-20100714155244-d43jrxvyafy4pik3.bundle
Thread
bzr commit into mysql-trunk-runtime branch (kostja:3079)Konstantin Osipov14 Jul