diff --git a/sql/events.cc b/sql/events.cc index 32d194e3bac..75780cd94c5 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -907,10 +907,7 @@ end: if (res) deinit(); if (!had_thd) - { delete thd; - set_current_thd(0); - } DBUG_RETURN(res); } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e52a35bcc8f..e3e331932d0 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -6334,7 +6334,6 @@ void handle_connections_sockets() (void) mysql_socket_close(new_sock); } delete thd; - set_current_thd(0); statistic_increment(connection_errors_internal, &LOCK_status); continue; } @@ -6449,7 +6448,6 @@ pthread_handler_t handle_connections_namedpipes(void *arg) { close_connection(thd, ER_OUT_OF_RESOURCES); delete thd; - set_current_thd(0); continue; } /* Host is unknown */ diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 3647520ed4b..63d7d7a0399 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -959,8 +959,6 @@ my_bool acl_init(bool dont_read_acl_tables) */ return_val= acl_reload(thd); delete thd; - /* Remember that we don't have a THD */ - set_current_thd(0); DBUG_RETURN(return_val); } @@ -6371,8 +6369,6 @@ my_bool grant_init() thd->store_globals(); return_val= grant_reload(thd); delete thd; - /* Remember that we don't have a THD */ - set_current_thd(0); DBUG_RETURN(return_val); } diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 807ec93f4cb..52d5928ea1d 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -9045,7 +9045,6 @@ my_bool mysql_rm_tmp_tables(void) my_dirend(dirp); } delete thd; - set_current_thd(0); DBUG_RETURN(0); } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 583abee360f..7a9cdad84f6 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1645,7 +1645,7 @@ THD::~THD() DBUG_ASSERT(status_var.memory_used == 0); // Ensure everything is freed } - set_current_thd(orig_thd); + set_current_thd(orig_thd == this ? 0 : orig_thd); DBUG_VOID_RETURN; } diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index dea224398ea..5977cfb8618 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -1791,9 +1791,7 @@ static void plugin_load(MEM_ROOT *tmp_root) table->m_needs_reopen= TRUE; // Force close to free memory close_mysql_tables(new_thd); end: - /* Remember that we don't have a THD */ delete new_thd; - set_current_thd(0); DBUG_VOID_RETURN; } diff --git a/sql/sql_reload.cc b/sql/sql_reload.cc index 4d22dae1c47..86d1e27a4ef 100644 --- a/sql/sql_reload.cc +++ b/sql/sql_reload.cc @@ -98,8 +98,6 @@ bool reload_acl_and_cache(THD *thd, unsigned long long options, if (tmp_thd) { delete tmp_thd; - /* Remember that we don't have a THD */ - set_current_thd(0); thd= 0; } reset_mqh((LEX_USER *)NULL, TRUE); diff --git a/sql/sql_servers.cc b/sql/sql_servers.cc index 8d5bb2b596d..78d11a6bebf 100644 --- a/sql/sql_servers.cc +++ b/sql/sql_servers.cc @@ -177,8 +177,6 @@ bool servers_init(bool dont_read_servers_table) */ return_val= servers_reload(thd); delete thd; - /* Remember that we don't have a THD */ - set_current_thd(0); end: DBUG_RETURN(return_val); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index ff5c385626a..1e7d4f5e3c6 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -1674,8 +1674,6 @@ void execute_ddl_log_recovery() mysql_mutex_unlock(&LOCK_gdl); thd->reset_query(); delete thd; - /* Remember that we don't have a THD */ - set_current_thd(0); DBUG_VOID_RETURN; } diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 0f9043a77df..74d2f6bc252 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -258,8 +258,6 @@ void udf_init() end: close_mysql_tables(new_thd); delete new_thd; - /* Remember that we don't have a THD */ - set_current_thd(0); DBUG_VOID_RETURN; } diff --git a/sql/tztime.cc b/sql/tztime.cc index 6486e9b2018..9791e218108 100644 --- a/sql/tztime.cc +++ b/sql/tztime.cc @@ -1803,11 +1803,7 @@ end: if (org_thd) org_thd->store_globals(); /* purecov: inspected */ else - { - /* Remember that we don't have a THD */ - set_current_thd(0); my_pthread_setspecific_ptr(THR_MALLOC, 0); - } default_tz= default_tz_name ? global_system_variables.time_zone : my_tz_SYSTEM; diff --git a/storage/spider/spd_conn.cc b/storage/spider/spd_conn.cc index 293a209ac68..c5c47064403 100644 --- a/storage/spider/spd_conn.cc +++ b/storage/spider/spd_conn.cc @@ -2280,9 +2280,6 @@ void *spider_bg_conn_action( if (!(trx = spider_get_trx(thd, FALSE, &error_num))) { delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif pthread_mutex_lock(&conn->bg_conn_sync_mutex); pthread_cond_signal(&conn->bg_conn_sync_cond); pthread_mutex_unlock(&conn->bg_conn_sync_mutex); @@ -2346,9 +2343,6 @@ void *spider_bg_conn_action( spider_free_trx(trx, TRUE); /* lex_end(thd->lex); */ delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif pthread_mutex_lock(&conn->bg_conn_sync_mutex); pthread_cond_signal(&conn->bg_conn_sync_cond); pthread_mutex_unlock(&conn->bg_conn_mutex); @@ -2799,9 +2793,6 @@ void *spider_bg_sts_action( if (!(trx = spider_get_trx(thd, FALSE, &error_num))) { delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif share->bg_sts_thd_wait = FALSE; share->bg_sts_kill = FALSE; share->bg_sts_init = FALSE; @@ -2867,9 +2858,6 @@ void *spider_bg_sts_action( } spider_free_trx(trx, TRUE); delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif share->bg_sts_thd_wait = FALSE; share->bg_sts_kill = FALSE; share->bg_sts_init = FALSE; @@ -2903,9 +2891,6 @@ void *spider_bg_sts_action( } spider_free_trx(trx, TRUE); delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif pthread_cond_signal(&share->bg_sts_sync_cond); pthread_mutex_unlock(&share->sts_mutex); #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) @@ -3190,9 +3175,6 @@ void *spider_bg_crd_action( if (!(trx = spider_get_trx(thd, FALSE, &error_num))) { delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif share->bg_crd_thd_wait = FALSE; share->bg_crd_kill = FALSE; share->bg_crd_init = FALSE; @@ -3262,9 +3244,6 @@ void *spider_bg_crd_action( } spider_free_trx(trx, TRUE); delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif share->bg_crd_thd_wait = FALSE; share->bg_crd_kill = FALSE; share->bg_crd_init = FALSE; @@ -3298,9 +3277,6 @@ void *spider_bg_crd_action( } spider_free_trx(trx, TRUE); delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif pthread_cond_signal(&share->bg_crd_sync_cond); pthread_mutex_unlock(&share->crd_mutex); #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) @@ -3688,9 +3664,6 @@ void *spider_bg_mon_action( if (!(trx = spider_get_trx(thd, FALSE, &error_num))) { delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif share->bg_mon_kill = FALSE; share->bg_mon_init = FALSE; pthread_cond_signal(&share->bg_mon_conds[link_idx]); @@ -3734,9 +3707,6 @@ void *spider_bg_mon_action( pthread_mutex_unlock(&share->bg_mon_mutexes[link_idx]); spider_free_trx(trx, TRUE); delete thd; -#if defined(MARIADB_BASE_VERSION) && MYSQL_VERSION_ID >= 100000 - set_current_thd(NULL); -#endif #if !defined(MYSQL_DYNAMIC_PLUGIN) || !defined(_WIN32) my_pthread_setspecific_ptr(THR_THD, NULL); #endif