summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2021-01-07 19:37:47 +0100
committerSergei Golubchik <serg@mariadb.org>2021-01-11 21:54:47 +0100
commit63f91927870b41b8965e2a2a868abcc2b3672f68 (patch)
treec1f7e0f76168834f2aa0ee461a9ce1e07bed0408
parent4c448836d489bd5a25c7509e8a69309c3b0a8e72 (diff)
downloadmariadb-git-63f91927870b41b8965e2a2a868abcc2b3672f68.tar.gz
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
-rw-r--r--sql/sql_parse.cc1
-rw-r--r--sql/sql_plugin.h5
-rw-r--r--sql/sql_show.cc20
-rw-r--r--sql/sql_test.cc1
4 files changed, 16 insertions, 11 deletions
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 <my_global.h>
#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<THD> 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));