Added status variable "Max_memory_used" to SHOW STATUS

This shows the maximum memory allocations used by the current connection.
The value for @@global.max_memory_used is 0 as we are not collecting this
value as it would cause a notable performance issue registering this for
all threads for every memory allocation

Reviewed-by: Sergei Golubchik <serg@mariadb.org>
This commit is contained in:
Monty 2024-12-04 12:03:40 +02:00
parent a0bfdef5e6
commit 47a5eed437
3 changed files with 45 additions and 0 deletions

View file

@ -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

View file

@ -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";

View file

@ -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},