Commit 2fe00517 authored by unknown's avatar unknown

THD::init_for_queries() pushed back:

see comments to the method why


sql/sql_class.h:
  THD::init_for_queries() pushed back:
  see comments to the method why
  Cleanup
parent b4b8d1f6
...@@ -3111,6 +3111,7 @@ extern "C" pthread_handler_decl(handle_slave_sql,arg) ...@@ -3111,6 +3111,7 @@ extern "C" pthread_handler_decl(handle_slave_sql,arg)
sql_print_error("Failed during slave thread initialization"); sql_print_error("Failed during slave thread initialization");
goto err; goto err;
} }
thd->init_for_queries();
rli->sql_thd= thd; rli->sql_thd= thd;
thd->temporary_tables = rli->save_temporary_tables; // restore temp tables thd->temporary_tables = rli->save_temporary_tables; // restore temp tables
pthread_mutex_lock(&LOCK_thread_count); pthread_mutex_lock(&LOCK_thread_count);
......
...@@ -144,9 +144,6 @@ THD::THD():user_time(0), is_fatal_error(0), ...@@ -144,9 +144,6 @@ THD::THD():user_time(0), is_fatal_error(0),
*scramble= '\0'; *scramble= '\0';
init(); init();
init_sql_alloc(&mem_root, // must be after init()
variables.query_alloc_block_size,
variables.query_prealloc_size);
/* Initialize sub structures */ /* Initialize sub structures */
bzero((char*) &transaction.mem_root,sizeof(transaction.mem_root)); bzero((char*) &transaction.mem_root,sizeof(transaction.mem_root));
bzero((char*) &warn_root,sizeof(warn_root)); bzero((char*) &warn_root,sizeof(warn_root));
...@@ -182,9 +179,6 @@ THD::THD():user_time(0), is_fatal_error(0), ...@@ -182,9 +179,6 @@ THD::THD():user_time(0), is_fatal_error(0),
transaction.trans_log.end_of_file= max_binlog_cache_size; transaction.trans_log.end_of_file= max_binlog_cache_size;
} }
#endif #endif
init_sql_alloc(&transaction.mem_root,
variables.trans_alloc_block_size,
variables.trans_prealloc_size);
/* /*
We need good random number initialization for new thread We need good random number initialization for new thread
Just coping global one will not work Just coping global one will not work
...@@ -227,6 +221,23 @@ void THD::init(void) ...@@ -227,6 +221,23 @@ void THD::init(void)
} }
/*
Init THD for query processing.
This has to be called once before we call mysql_parse.
See also comments in sql_class.h.
*/
void THD::init_for_queries()
{
init_sql_alloc(&mem_root,
variables.query_alloc_block_size,
variables.query_prealloc_size);
init_sql_alloc(&transaction.mem_root,
variables.trans_alloc_block_size,
variables.trans_prealloc_size);
}
/* /*
Do what's needed when one invokes change user Do what's needed when one invokes change user
......
...@@ -405,7 +405,6 @@ struct system_variables ...@@ -405,7 +405,6 @@ struct system_variables
void free_tmp_table(THD *thd, TABLE *entry); void free_tmp_table(THD *thd, TABLE *entry);
class Prepared_statement;
/* /*
State of a single command executed against this connection. State of a single command executed against this connection.
...@@ -760,6 +759,16 @@ class THD :public ilink, ...@@ -760,6 +759,16 @@ class THD :public ilink,
~THD(); ~THD();
void init(void); void init(void);
/*
Initialize memory roots necessary for query processing and (!)
pre-allocate memory for it. We can't do that in THD constructor because
there are use cases (acl_init, delayed inserts, watcher threads,
killing mysqld) where it's vital to not allocate excessive and not used
memory. Note, that we still don't return error from init_for_queries():
if preallocation fails, we should notice that at the first call to
alloc_root.
*/
void init_for_queries();
void change_user(void); void change_user(void);
void cleanup(void); void cleanup(void);
bool store_globals(); bool store_globals();
......
...@@ -974,6 +974,7 @@ pthread_handler_decl(handle_one_connection,arg) ...@@ -974,6 +974,7 @@ pthread_handler_decl(handle_one_connection,arg)
thd->proc_info=0; thd->proc_info=0;
thd->set_time(); thd->set_time();
thd->init_for_queries();
while (!net->error && net->vio != 0 && !thd->killed) while (!net->error && net->vio != 0 && !thd->killed)
{ {
if (do_command(thd)) if (do_command(thd))
...@@ -1054,6 +1055,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg) ...@@ -1054,6 +1055,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
thd->priv_user=thd->user=(char*) my_strdup("boot", MYF(MY_WME)); thd->priv_user=thd->user=(char*) my_strdup("boot", MYF(MY_WME));
buff= (char*) thd->net.buff; buff= (char*) thd->net.buff;
thd->init_for_queries();
while (fgets(buff, thd->net.max_packet, file)) while (fgets(buff, thd->net.max_packet, file))
{ {
uint length=(uint) strlen(buff); uint length=(uint) strlen(buff);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment