diff --git a/mysql-test/main/memory_used.result b/mysql-test/main/memory_used.result new file mode 100644 index 00000000000..974be5a6e1e --- /dev/null +++ b/mysql-test/main/memory_used.result @@ -0,0 +1,8 @@ +select * from information_schema.processlist where id=0; +should be true +1 +should be true +1 +show global status like "max_memory_used"; +Variable_name Value +Max_memory_used NULL diff --git a/mysql-test/main/memory_used.test b/mysql-test/main/memory_used.test new file mode 100644 index 00000000000..0416f5114a5 --- /dev/null +++ b/mysql-test/main/memory_used.test @@ -0,0 +1,20 @@ +# +# Added status variable "Max_memory_used" to SHOW STATUS +# + +let $l1=`show status like "max_memory_used"`; +--disable_result_log +select * from information_schema.processlist where id=0; +--enable_result_log +let $l2=`show status like "max_memory_used"`; + +--disable_query_log +eval SET @l1= SUBSTRING_INDEX('$l1', ' ', -1); +eval SET @l2= SUBSTRING_INDEX('$l2', ' ', -1); +eval select @l1 > 10000 as "should be true"; +eval select @l2+0 > @l1+0 as "should be true"; + +--enable_query_log +# global max_memory should be NULL as we cannot calculate this +show global status like "max_memory_used"; + diff --git a/sql/mysqld.cc b/sql/mysqld.cc index d204a8482f0..43c6c2f86ef 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -7222,6 +7222,22 @@ static int show_memory_used(THD *thd, SHOW_VAR *var, void *buff, return 0; } +static int show_max_memory_used(THD *thd, SHOW_VAR *var, void *buff, + struct system_status_var *status_var, + enum enum_var_type scope) +{ + var->type= SHOW_LONGLONG; + var->value= buff; + if (scope == OPT_GLOBAL) + { + var->type= SHOW_CHAR; + var->value= (char*) "NULL"; // Emulate null value + } + else + *(longlong*) buff= (longlong) status_var->max_local_memory_used; + return 0; +} + static int show_stack_usage(THD *thd, SHOW_VAR *var, void *buff, system_status_var *, enum_var_type scope) @@ -7404,6 +7420,7 @@ SHOW_VAR status_vars[]= { {"Master_gtid_wait_timeouts", (char*) offsetof(STATUS_VAR, master_gtid_wait_timeouts), SHOW_LONG_STATUS}, {"Master_gtid_wait_time", (char*) offsetof(STATUS_VAR, master_gtid_wait_time), SHOW_LONG_STATUS}, {"Max_used_connections", (char*) &max_used_connections, SHOW_LONG}, + {"Max_memory_used", (char*) &show_max_memory_used, SHOW_SIMPLE_FUNC}, {"Memory_used", (char*) &show_memory_used, SHOW_SIMPLE_FUNC}, {"Memory_used_initial", (char*) &start_memory_used, SHOW_LONGLONG}, {"Resultset_metadata_skipped", (char *) offsetof(STATUS_VAR, skip_metadata_count),SHOW_LONG_STATUS},