List:Internals« Previous MessageNext Message »
From:konstantin Date:June 22 2005 9:12pm
Subject:bk commit into 5.0 tree (konstantin:1.1995)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of kostja. When kostja does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1995 05/06/22 23:12:25 konstantin@stripped +4 -0
  Remove THD::stmt_backup

  sql/sql_select.cc
    1.347 05/06/22 23:12:19 konstantin@stripped +3 -2
    Use an object on stack instead of THD::stmt_backup

  sql/sql_prepare.cc
    1.127 05/06/22 23:12:19 konstantin@stripped +20 -16
    Use an object on stack instead of THD::stmt_backup

  sql/sql_class.h
    1.243 05/06/22 23:12:19 konstantin@stripped +4 -11
    Remove THD::stmt_backup and simplify Statement constructors.

  sql/sql_class.cc
    1.189 05/06/22 23:12:19 konstantin@stripped +12 -31
    Statement constructor for the case when it's used for backup only
    was removed.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	konstantin
# Host:	dragonfly.local
# Root:	/opt/local/work/mysql-5.0-stmt_backup

--- 1.188/sql/sql_class.cc	2005-06-22 14:40:28 +04:00
+++ 1.189/sql/sql_class.cc	2005-06-22 23:12:19 +04:00
@@ -156,9 +156,15 @@
 /****************************************************************************
 ** Thread specific functions
 ****************************************************************************/
+/*
+  Pass nominal parameters to Statement constructor only to ensure that
+  the destructor works OK in case of error. The main_mem_root will be
+  re-initialized in init().
+*/
 
 THD::THD()
-  :user_time(0), global_read_lock(0), is_fatal_error(0),
+  :Statement(CONVENTIONAL_EXECUTION, 0, ALLOC_ROOT_MIN_BLOCK_SIZE, 0),
+   user_time(0), global_read_lock(0), is_fatal_error(0),
    rand_used(0), time_zone_used(0),
    last_insert_id_used(0), insert_id_used(0), clear_next_insert_id(0),
    in_lock_tables(0), bootstrap(0), derived_tables_processing(FALSE),
@@ -1483,9 +1489,10 @@
   Statement functions 
 */
 
-Statement::Statement(THD *thd)
-  :Query_arena(&main_mem_root, INITIALIZED),
-  id(++thd->statement_id_counter),
+Statement::Statement(enum enum_state state_arg, ulong id_arg,
+                     ulong alloc_block_size, ulong prealloc_size)
+  :Query_arena(&main_mem_root, state_arg),
+  id(id_arg),
   set_query_id(1),
   allow_sum_func(0),
   lex(&main_lex),
@@ -1494,33 +1501,7 @@
   cursor(0)
 {
   name.str= NULL;
-  init_sql_alloc(&main_mem_root,
-                 thd->variables.query_alloc_block_size,
-                 thd->variables.query_prealloc_size);
-}
-
-/*
-  This constructor is called when Statement is a parent of THD and
-  for the backup statement. Some variables are initialized in
-  THD::init due to locking problems.
-*/
-
-Statement::Statement()
-  :Query_arena(&main_mem_root, CONVENTIONAL_EXECUTION),
-  id(0),
-  set_query_id(1),
-  allow_sum_func(0),                            /* initialized later */
-  lex(&main_lex),
-  query(0),                                     /* these two are set */ 
-  query_length(0),                              /* in alloc_query() */
-  cursor(0)
-{
-  /*
-    This is just to ensure that the destructor works correctly in
-    case of an error and the backup statement. The memory root will
-    be re-initialized in THD::init.
-  */
-  init_sql_alloc(&main_mem_root, ALLOC_ROOT_MIN_BLOCK_SIZE, 0);
+  init_sql_alloc(&main_mem_root, alloc_block_size, prealloc_size);
 }
 
 

--- 1.242/sql/sql_class.h	2005-06-22 11:59:06 +04:00
+++ 1.243/sql/sql_class.h	2005-06-22 23:12:19 +04:00
@@ -809,13 +809,11 @@
 
 public:
 
-  /*
-    This constructor is called when statement is a subobject of THD:
-    some variables are initialized in THD::init due to locking problems
-  */
-  Statement();
+  /* This constructor is called for backup statements */
+  Statement() { clear_alloc_root(&main_mem_root); }
 
-  Statement(THD *thd);
+  Statement(enum enum_state state_arg, ulong id_arg,
+            ulong alloc_block_size, ulong prealloc_size);
   virtual ~Statement();
 
   /* Assign execution context (note: not all members) of given stmt to self */
@@ -957,11 +955,6 @@
   pthread_mutex_t LOCK_delete;		// Locked before thd is deleted
   /* all prepared statements and cursors of this connection */
   Statement_map stmt_map; 
-  /*
-    keeps THD state while it is used for active statement
-    Note: we perform special cleanup for it in THD destructor.
-  */
-  Statement stmt_backup;
   /*
     A pointer to the stack frame of handle_one_connection(),
     which is called first in the thread for handling a client

--- 1.346/sql/sql_select.cc	2005-06-22 14:40:28 +04:00
+++ 1.347/sql/sql_select.cc	2005-06-22 23:12:19 +04:00
@@ -1824,6 +1824,7 @@
   THD *thd= join->thd;
   JOIN_TAB *join_tab= join->join_tab + join->const_tables;
   enum_nested_loop_state error= NESTED_LOOP_OK;
+  Query_arena backup_arena;
   DBUG_ENTER("Cursor::fetch");
   DBUG_PRINT("enter",("rows: %lu", num_rows));
 
@@ -1835,7 +1836,7 @@
   thd->lock= lock;
   thd->query_id= query_id;
   /* save references to memory, allocated during fetch */
-  thd->set_n_backup_item_arena(this, &thd->stmt_backup);
+  thd->set_n_backup_item_arena(this, &backup_arena);
 
   join->fetch_limit+= num_rows;
 
@@ -1851,7 +1852,7 @@
     ha_release_temporary_latches(thd);
 #endif
 
-  thd->restore_backup_item_arena(this, &thd->stmt_backup);
+  thd->restore_backup_item_arena(this, &backup_arena);
   DBUG_ASSERT(thd->free_list == 0);
   reset_thd(thd);
 

--- 1.126/sql/sql_prepare.cc	2005-06-22 11:59:07 +04:00
+++ 1.127/sql/sql_prepare.cc	2005-06-22 23:12:19 +04:00
@@ -1706,6 +1706,7 @@
                         LEX_STRING *name)
 {
   LEX *lex;
+  Statement stmt_backup;
   Prepared_statement *stmt= new Prepared_statement(thd);
   bool error;
   DBUG_ENTER("mysql_stmt_prepare");
@@ -1739,13 +1740,13 @@
     DBUG_RETURN(TRUE);
   }
 
-  thd->set_n_backup_statement(stmt, &thd->stmt_backup);
-  thd->set_n_backup_item_arena(stmt, &thd->stmt_backup);
+  thd->set_n_backup_statement(stmt, &stmt_backup);
+  thd->set_n_backup_item_arena(stmt, &stmt_backup);
 
   if (alloc_query(thd, packet, packet_length))
   {
-    thd->restore_backup_statement(stmt, &thd->stmt_backup);
-    thd->restore_backup_item_arena(stmt, &thd->stmt_backup);
+    thd->restore_backup_statement(stmt, &stmt_backup);
+    thd->restore_backup_item_arena(stmt, &stmt_backup);
     /* Statement map deletes statement on erase */
     thd->stmt_map.erase(stmt);
     DBUG_RETURN(TRUE);
@@ -1770,7 +1771,7 @@
     transformation can be reused on execute, we set again thd->mem_root from
     stmt->mem_root (see setup_wild for one place where we do that).
   */
-  thd->restore_backup_item_arena(stmt, &thd->stmt_backup);
+  thd->restore_backup_item_arena(stmt, &stmt_backup);
 
   if (!error)
     error= check_prepared_statement(stmt, test(name));
@@ -1786,7 +1787,7 @@
   lex_end(lex);
   close_thread_tables(thd);
   cleanup_stmt_and_thd_after_use(stmt, thd);
-  thd->restore_backup_statement(stmt, &thd->stmt_backup);
+  thd->restore_backup_statement(stmt, &stmt_backup);
   thd->current_arena= thd;
 
   if (error)
@@ -1949,6 +1950,7 @@
 {
   ulong stmt_id= uint4korr(packet);
   ulong flags= (ulong) ((uchar) packet[4]);
+  Statement stmt_backup;
   Cursor *cursor;
   /*
     Query text for binary log, or empty string if the query is not put into
@@ -2026,8 +2028,7 @@
   if (stmt->param_count && stmt->set_params_data(stmt,
&expanded_query))
     goto set_params_data_err;
 #endif
-  thd->stmt_backup.set_statement(thd);
-  thd->set_statement(stmt);
+  thd->set_n_backup_statement(stmt, &stmt_backup);
   thd->current_arena= stmt;
   reinit_stmt_before_use(thd, stmt->lex);
   /* From now cursors assume that thd->mem_root is clean */
@@ -2064,7 +2065,7 @@
     reset_stmt_params(stmt);
   }
 
-  thd->set_statement(&thd->stmt_backup);
+  thd->set_statement(&stmt_backup);
   thd->current_arena= thd;
   DBUG_VOID_RETURN;
 
@@ -2089,6 +2090,7 @@
     binary log.
   */
   String expanded_query;
+  Statement stmt_backup;
   DBUG_ENTER("mysql_sql_stmt_execute");
 
   DBUG_ASSERT(thd->free_list == NULL);
@@ -2110,16 +2112,16 @@
 
   /* Must go before setting variables, as it clears thd->user_var_events */
   mysql_reset_thd_for_next_command(thd);
-  thd->set_n_backup_statement(stmt, &thd->stmt_backup);
-  thd->set_statement(stmt);
+  thd->set_n_backup_statement(stmt, &stmt_backup);
   if (stmt->set_params_from_vars(stmt,
-                                 thd->stmt_backup.lex->prepared_stmt_params,
+                                 stmt_backup.lex->prepared_stmt_params,
                                  &expanded_query))
   {
     my_error(ER_WRONG_ARGUMENTS, MYF(0), "EXECUTE");
   }
   thd->command= COM_STMT_EXECUTE; /* For nice messages in general log */
   execute_stmt(thd, stmt, &expanded_query);
+  thd->set_statement(&stmt_backup);
   DBUG_VOID_RETURN;
 }
 
@@ -2176,7 +2178,6 @@
   close_thread_tables(thd);                    // to close derived tables
   cleanup_stmt_and_thd_after_use(stmt, thd);
   reset_stmt_params(stmt);
-  thd->set_statement(&thd->stmt_backup);
   thd->current_arena= thd;
 
   if (stmt->state == Query_arena::PREPARED)
@@ -2201,6 +2202,7 @@
   ulong stmt_id= uint4korr(packet);
   ulong num_rows= uint4korr(packet+4);
   Prepared_statement *stmt;
+  Statement stmt_backup;
   DBUG_ENTER("mysql_stmt_fetch");
 
   statistic_increment(thd->status_var.com_stmt_fetch, &LOCK_status);
@@ -2214,7 +2216,7 @@
   }
 
   thd->current_arena= stmt;
-  thd->set_n_backup_statement(stmt, &thd->stmt_backup);
+  thd->set_n_backup_statement(stmt, &stmt_backup);
 
   if (!(specialflag & SPECIAL_NO_PRIOR))
     my_pthread_setprio(pthread_self(), QUERY_PRIOR);
@@ -2226,7 +2228,7 @@
   if (!(specialflag & SPECIAL_NO_PRIOR))
     my_pthread_setprio(pthread_self(), WAIT_PRIOR);
 
-  thd->restore_backup_statement(stmt, &thd->stmt_backup);
+  thd->restore_backup_statement(stmt, &stmt_backup);
   thd->current_arena= thd;
 
   if (!stmt->cursor->is_open())
@@ -2386,7 +2388,9 @@
 
 
 Prepared_statement::Prepared_statement(THD *thd_arg)
-  :Statement(thd_arg),
+  :Statement(INITIALIZED, ++thd_arg->statement_id_counter,
+             thd_arg->variables.query_alloc_block_size,
+             thd_arg->variables.query_prealloc_size),
   thd(thd_arg),
   param_array(0),
   param_count(0),
Thread
bk commit into 5.0 tree (konstantin:1.1995)konstantin22 Jun