Commit 63f91927 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-17251 SHOW STATUS unnecessary calls calc_sum_of_all_status

1. only call calc_sum_of_all_status() if a global
   SHOW_xxx_STATUS variable is to be returned
2. only lock LOCK_status when copying global_status_var,
   but not when iterating all threads
parent 4c448836
...@@ -2179,6 +2179,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, ...@@ -2179,6 +2179,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
break; break;
general_log_print(thd, command, NullS); general_log_print(thd, command, NullS);
status_var_increment(thd->status_var.com_stat[SQLCOM_SHOW_STATUS]); 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); calc_sum_of_all_status(current_global_status_var);
if (!(uptime= (ulong) (thd->start_time - server_start_time))) if (!(uptime= (ulong) (thd->start_time - server_start_time)))
queries_per_second1000= 0; queries_per_second1000= 0;
......
...@@ -22,9 +22,10 @@ ...@@ -22,9 +22,10 @@
that is defined in plugin.h that is defined in plugin.h
*/ */
#define SHOW_always_last SHOW_KEY_CACHE_LONG, \ #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_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 <my_global.h> #include <my_global.h>
#undef SHOW_always_last #undef SHOW_always_last
......
...@@ -3580,6 +3580,16 @@ static bool show_status_array(THD *thd, const char *wild, ...@@ -3580,6 +3580,16 @@ static bool show_status_array(THD *thd, const char *wild,
if (show_type == SHOW_SYS) if (show_type == SHOW_SYS)
mysql_mutex_lock(&LOCK_global_system_variables); 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, pos= get_one_variable(thd, var, scope, show_type, status_var,
&charset, buff, &length); &charset, buff, &length);
...@@ -3620,8 +3630,6 @@ uint calc_sum_of_all_status(STATUS_VAR *to) ...@@ -3620,8 +3630,6 @@ uint calc_sum_of_all_status(STATUS_VAR *to)
I_List_iterator<THD> it(threads); I_List_iterator<THD> it(threads);
THD *tmp; THD *tmp;
/* Get global values as base */
*to= global_status_var;
to->local_memory_used= 0; to->local_memory_used= 0;
/* Add to this status from existing threads */ /* Add to this status from existing threads */
...@@ -7586,13 +7594,7 @@ int fill_status(THD *thd, TABLE_LIST *tables, COND *cond) ...@@ -7586,13 +7594,7 @@ int fill_status(THD *thd, TABLE_LIST *tables, COND *cond)
if (partial_cond) if (partial_cond)
partial_cond->val_int(); partial_cond->val_int();
if (scope == OPT_GLOBAL) tmp.local_memory_used= 0; // meaning tmp was not populated yet
{
/* 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);
}
mysql_mutex_lock(&LOCK_show_status); mysql_mutex_lock(&LOCK_show_status);
res= show_status_array(thd, wild, res= show_status_array(thd, wild,
......
...@@ -564,6 +564,7 @@ void mysql_print_status() ...@@ -564,6 +564,7 @@ void mysql_print_status()
STATUS_VAR tmp; STATUS_VAR tmp;
uint count; uint count;
tmp= global_status_var;
count= calc_sum_of_all_status(&tmp); count= calc_sum_of_all_status(&tmp);
printf("\nStatus information:\n\n"); printf("\nStatus information:\n\n");
(void) my_getwd(current_dir, sizeof(current_dir),MYF(0)); (void) my_getwd(current_dir, sizeof(current_dir),MYF(0));
......
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