diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 54937116383..131ba4a86c5 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2179,6 +2179,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, break; general_log_print(thd, command, NullS); status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]); + *current_global_status_var= global_status_var; calc_sum_of_all_status(current_global_status_var); if (!(uptime= (ulong) (thd->start_time - server_start_time))) queries_per_second1000= 0; diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h index 64194b5a1b5..13f7296e0cd 100644 --- a/sql/sql_plugin.h +++ b/sql/sql_plugin.h @@ -22,9 +22,10 @@ that is defined in plugin.h */ #define SHOW_always_last SHOW_KEY_CACHE_LONG, \ - SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, \ SHOW_HAVE, SHOW_MY_BOOL, SHOW_HA_ROWS, SHOW_SYS, \ - SHOW_LONG_NOFLUSH, SHOW_LONGLONG_STATUS, SHOW_LEX_STRING + SHOW_LONG_NOFLUSH, SHOW_LEX_STRING, \ + /* SHOW_*_STATUS must be at the end, SHOW_LONG_STATUS being first */ \ + SHOW_LONG_STATUS, SHOW_DOUBLE_STATUS, SHOW_LONGLONG_STATUS #include #undef SHOW_always_last diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 79897429a4f..4294157cce3 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -3580,6 +3580,16 @@ static bool show_status_array(THD *thd, const char *wild, if (show_type == SHOW_SYS) mysql_mutex_lock(&LOCK_global_system_variables); + else if (show_type >= SHOW_LONG_STATUS && scope == OPT_GLOBAL && + !status_var->local_memory_used) + { + mysql_mutex_lock(&LOCK_status); + *status_var= global_status_var; + mysql_mutex_unlock(&LOCK_status); + calc_sum_of_all_status(status_var); + DBUG_ASSERT(status_var->local_memory_used); + } + pos= get_one_variable(thd, var, scope, show_type, status_var, &charset, buff, &length); @@ -3620,8 +3630,6 @@ uint calc_sum_of_all_status(STATUS_VAR *to) I_List_iterator it(threads); THD *tmp; - /* Get global values as base */ - *to= global_status_var; to->local_memory_used= 0; /* Add to this status from existing threads */ @@ -7586,13 +7594,7 @@ int fill_status(THD *thd, TABLE_LIST *tables, COND *cond) if (partial_cond) partial_cond->val_int(); - if (scope == OPT_GLOBAL) - { - /* We only hold LOCK_status for summary status vars */ - mysql_mutex_lock(&LOCK_status); - calc_sum_of_all_status(&tmp); - mysql_mutex_unlock(&LOCK_status); - } + tmp.local_memory_used= 0; // meaning tmp was not populated yet mysql_mutex_lock(&LOCK_show_status); res= show_status_array(thd, wild, diff --git a/sql/sql_test.cc b/sql/sql_test.cc index 4e68ec2ec2e..c0e62227665 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -564,6 +564,7 @@ void mysql_print_status() STATUS_VAR tmp; uint count; + tmp= global_status_var; count= calc_sum_of_all_status(&tmp); printf("\nStatus information:\n\n"); (void) my_getwd(current_dir, sizeof(current_dir),MYF(0));