summaryrefslogtreecommitdiff
path: root/sql/sql_class.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r--sql/sql_class.cc97
1 files changed, 49 insertions, 48 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 9922eacdec1..41def4aa1b5 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -51,8 +51,6 @@ template class List<Alter_drop>;
template class List_iterator<Alter_drop>;
template class List<Alter_column>;
template class List_iterator<Alter_column>;
-template class List<Set_option>;
-template class List_iterator<Set_option>;
#endif
/****************************************************************************
@@ -87,6 +85,9 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
host_or_ip="unknown ip";
locked=killed=count_cuted_fields=some_tables_deleted=no_errors=password=
query_start_used=safe_to_cache_query=0;
+ pthread_mutex_lock(&LOCK_global_system_variables);
+ variables= global_system_variables;
+ pthread_mutex_unlock(&LOCK_global_system_variables);
db_length=query_length=col_access=0;
query_error=0;
next_insert_id=last_insert_id=0;
@@ -102,7 +103,6 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
slave_proxy_id = 0;
file_id = 0;
cond_count=0;
- convert_set=0;
db_charset=default_charset_info;
mysys_var=0;
#ifndef DBUG_OFF
@@ -117,8 +117,8 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
#endif
#ifdef SIGNAL_WITH_VIO_CLOSE
active_vio = 0;
- pthread_mutex_init(&active_vio_lock, MY_MUTEX_INIT_FAST);
#endif
+ pthread_mutex_init(&LOCK_delete, MY_MUTEX_INIT_FAST);
/* Variables with default values */
proc_info="login";
@@ -127,23 +127,15 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
slave_net = 0;
log_pos = 0;
server_status= SERVER_STATUS_AUTOCOMMIT;
- update_lock_default= low_priority_updates ? TL_WRITE_LOW_PRIORITY : TL_WRITE;
+ update_lock_default= (variables.low_priority_updates ?
+ TL_WRITE_LOW_PRIORITY :
+ TL_WRITE);
options= thd_startup_options;
-#ifdef HAVE_QUERY_CACHE
- query_cache_type= (byte) query_cache_startup_type;
-#else
- query_cache_type= 0; //Safety
-#endif
sql_mode=(uint) opt_sql_mode;
- inactive_timeout=net_wait_timeout;
open_options=ha_open_options;
- tx_isolation=session_tx_isolation=default_tx_isolation;
+ session_tx_isolation= (enum_tx_isolation) variables.tx_isolation;
command=COM_CONNECT;
set_query_id=1;
- default_select_limit= HA_POS_ERROR;
- max_error_count=max_warning_count=MYSQL_DEFAULT_ERROR_COUNT;
- max_join_size= ((::max_join_size != ~ (ulong) 0L) ? ::max_join_size :
- HA_POS_ERROR);
db_access=NO_ACCESS;
/* Initialize sub structures */
@@ -199,6 +191,10 @@ THD::~THD()
{
THD_CHECK_SENTRY(this);
DBUG_ENTER("~THD()");
+ /* Ensure that no one is using THD */
+ pthread_mutex_lock(&LOCK_delete);
+ pthread_mutex_unlock(&LOCK_delete);
+
/* Close connection */
if (net.vio)
{
@@ -218,7 +214,6 @@ THD::~THD()
hash_free(&user_vars);
DBUG_PRINT("info", ("freeing host"));
-
if (host != localhost) // If not pointer to constant
safeFree(host);
if (user != delayed_user)
@@ -229,18 +224,19 @@ THD::~THD()
free_root(&con_root,MYF(0));
free_root(&transaction.mem_root,MYF(0));
mysys_var=0; // Safety (shouldn't be needed)
-#ifdef SIGNAL_WITH_VIO_CLOSE
- pthread_mutex_destroy(&active_vio_lock);
-#endif
+ pthread_mutex_destroy(&LOCK_delete);
#ifndef DBUG_OFF
dbug_sentry = THD_SENTRY_GONE;
#endif
DBUG_VOID_RETURN;
}
+
void THD::awake(bool prepare_to_die)
{
THD_CHECK_SENTRY(this);
+ safe_mutex_assert_owner(&LOCK_delete);
+
if (prepare_to_die)
killed = 1;
thr_alarm_kill(real_id);
@@ -248,26 +244,30 @@ void THD::awake(bool prepare_to_die)
close_active_vio();
#endif
if (mysys_var)
+ {
+ pthread_mutex_lock(&mysys_var->mutex);
+ if (!system_thread) // Don't abort locks
+ mysys_var->abort=1;
+ /*
+ This broadcast could be up in the air if the victim thread
+ exits the cond in the time between read and broadcast, but that is
+ ok since all we want to do is to make the victim thread get out
+ of waiting on current_cond.
+ */
+ if (mysys_var->current_cond)
{
- pthread_mutex_lock(&mysys_var->mutex);
- if (!system_thread) // Don't abort locks
- mysys_var->abort=1;
- // this broadcast could be up in the air if the victim thread
- // exits the cond in the time between read and broadcast, but that is
- // ok since all we want to do is to make the victim thread get out
- // of waiting on current_cond
- if (mysys_var->current_cond)
- {
- pthread_mutex_lock(mysys_var->current_mutex);
- pthread_cond_broadcast(mysys_var->current_cond);
- pthread_mutex_unlock(mysys_var->current_mutex);
- }
- pthread_mutex_unlock(&mysys_var->mutex);
+ pthread_mutex_lock(mysys_var->current_mutex);
+ pthread_cond_broadcast(mysys_var->current_cond);
+ pthread_mutex_unlock(mysys_var->current_mutex);
}
+ pthread_mutex_unlock(&mysys_var->mutex);
+ }
}
-// remember the location of thread info, the structure needed for
-// sql_alloc() and the structure for the net buffer
+/*
+ Remember the location of thread info, the structure needed for
+ sql_alloc() and the structure for the net buffer
+*/
bool THD::store_globals()
{
@@ -276,6 +276,7 @@ bool THD::store_globals()
my_pthread_setspecific_ptr(THR_NET, &net));
}
+
/* routings to adding tables to list of changed in transaction tables */
inline static void list_include(CHANGED_TABLE_LIST** prev,
@@ -290,17 +291,18 @@ inline static void list_include(CHANGED_TABLE_LIST** prev,
}
/* add table to list of changed in transaction tables */
+
void THD::add_changed_table(TABLE *table)
{
- DBUG_ENTER("THD::add_changed_table (table)");
+ DBUG_ENTER("THD::add_changed_table(table)");
- DBUG_ASSERT((options & (OPTION_NOT_AUTO_COMMIT | OPTION_BEGIN)) &&
- table->file->has_transactions());
+ DBUG_ASSERT((options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) &&
+ table->file->has_transactions());
CHANGED_TABLE_LIST** prev = &transaction.changed_tables;
CHANGED_TABLE_LIST* curr = transaction.changed_tables;
- for(; curr; prev = &(curr->next), curr = curr->next)
+ for (; curr; prev = &(curr->next), curr = curr->next)
{
int cmp = (long)curr->key_length - (long)table->key_length;
if (cmp < 0)
@@ -317,7 +319,8 @@ void THD::add_changed_table(TABLE *table)
{
list_include(prev, curr, changed_table_dup(table));
DBUG_PRINT("info",
- ("key_length %u %u", table->key_length, (*prev)->key_length));
+ ("key_length %u %u", table->key_length,
+ (*prev)->key_length));
DBUG_VOID_RETURN;
}
else if (cmp == 0)
@@ -328,10 +331,12 @@ void THD::add_changed_table(TABLE *table)
}
}
*prev = changed_table_dup(table);
- DBUG_PRINT("info", ("key_length %u %u", table->key_length, (*prev)->key_length));
+ DBUG_PRINT("info", ("key_length %u %u", table->key_length,
+ (*prev)->key_length));
DBUG_VOID_RETURN;
}
+
CHANGED_TABLE_LIST* THD::changed_table_dup(TABLE *table)
{
CHANGED_TABLE_LIST* new_table =
@@ -349,11 +354,7 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(TABLE *table)
ALIGN_SIZE(sizeof(CHANGED_TABLE_LIST)));
new_table->next = 0;
new_table->key_length = table->key_length;
- uint32 db_len = ((new_table->table_name =
- ::strmake(new_table->key, table->table_cache_key,
- table->key_length) + 1) - new_table->key);
- ::memcpy(new_table->key + db_len, table->table_cache_key + db_len,
- table->key_length - db_len);
+ ::memcpy(new_table->key, table->table_cache_key, table->key_length);
return new_table;
}
@@ -614,7 +615,7 @@ bool select_export::send_data(List<Item> &items)
bfill(space,sizeof(space),' ');
}
uint length=item->max_length-used_length;
- for ( ; length > sizeof(space) ; length-=sizeof(space))
+ for (; length > sizeof(space) ; length-=sizeof(space))
{
if (my_b_write(&cache,(byte*) space,sizeof(space)))
goto err;