MySQL 8.4.0
Source Code Documentation
pfs_variable.h File Reference

Performance schema system and status variables (declarations). More...

#include "my_inttypes.h"
#include "sql/mysqld_thd_manager.h"
#include <assert.h>
#include <stddef.h>
#include <sys/types.h>
#include <string>
#include "sql/set_var.h"
#include "storage/perfschema/pfs_account.h"
#include "storage/perfschema/pfs_host.h"
#include "storage/perfschema/pfs_instr.h"
#include "storage/perfschema/pfs_user.h"

Go to the source code of this file.


class  System_variable
 System variable derived from sys_var object. More...
class  Status_variable
 Status variable derived from SHOW_VAR. More...
class  Find_THD_variable
 Get and lock a validated THD from the thread manager. More...
class  PFS_variable_cache< Var_type >
 Base class for a system or status variable cache. More...
class  PFS_system_variable_cache
 System variable cache. More...
class  PFS_system_variable_info_cache
 System variable info cache. More...
class  PFS_system_persisted_variables_cache
 Persisted variables cache. More...
class  PFS_status_variable_cache
 Status variable cache. More...


#define PFS_VAR


typedef std::vector< SHOW_VARStatus_var_array
typedef Prealloced_array< SHOW_VAR, SYSTEM_VARIABLE_PREALLOCShow_var_array
typedef PFS_connection_slice PFS_client


void sum_user_status (PFS_client *pfs_user, System_status_var *status_totals)
void sum_host_status (PFS_client *pfs_host, System_status_var *status_totals)
void sum_account_status (PFS_client *pfs_account, System_status_var *status_totals)
void system_variable_warning ()
 Warning issued if the version of the system variable hash table changes during a query. More...
void status_variable_warning ()
 Warning issued if the global status variable array changes during a query. More...


Status_var_array all_status_vars
bool status_vars_inited
static const uint SYSVAR_MEMROOT_BLOCK_SIZE = 4096
mysql_mutex_t LOCK_plugin_delete

Detailed Description

Performance schema system and status variables (declarations).

Macro Definition Documentation


#define PFS_VAR


Status and system variables are implemented differently in the server, but the steps to process them in the Performance Schema are essentially the same:

  1. INITIALIZE - Build or acquire a sorted list of variables to use for input. Use the SHOW_VAR struct as an intermediate format common to system, status and user vars:

    SHOW_VAR Name - Text string Value - Pointer to memory location, function, sub array structure Type - Scalar, function, or sub array Scope - SESSION, GLOBAL, BOTH


    • Register the server's internal buffer with the class. Acquire locks if necessary, then scan the contents of the input buffer.
    • For system variables, convert each element to SHOW_VAR format, store in a temporary array.
    • For status variables, copy existing global status array into a local array that can be used without locks. Expand nested sub arrays, indicated by a type of SHOW_ARRAY.
  2. MATERIALIZE - Convert the list of SHOW_VAR variables to string format, store in a local cache:
    • Resolve each variable according to the type.
    • Recursively process unexpanded nested arrays and callback functions.
    • Aggregate values across threads for global status.
    • Convert numeric values to a string.
    • Prefix variable name with the plugin name.
  3. OUTPUT - Iterate the cache for the SHOW command or table query.


  1. System_variable - A materialized system variable
  2. Status_variable - A materialized status variable
  3. PFS_variable_cache - Base class that defines the interface for the operations above. public init_show_var_array() - Build SHOW_VAR list of variables for processing materialize_global() - Materialize global variables, aggregate across sessions materialize_session() - Materialize variables for a given PFS_thread or THD materialize_user() - Materialize variables for a user, aggregate across related threads. materialize_host() - Materialize variables for a host, aggregate across related threads. materialize_account() - Materialize variables for a account, aggregate across related threads. private m_show_var_array - Prealloc_array of SHOW_VARs for input to Materialize m_cache - Prealloc_array of materialized variables for output do_materialize_global() - Implementation of materialize_global() do_materialize_session() - Implementation of materialize_session() do_materialize_client() - Implementation of materialize_user/host/account()
  4. PFS_system_variable_cache - System variable implementation of PFS_variable_cache
  5. PFS_status_variable_cache - Status variable implementation of PFS_variable_cache
  6. Find_THD_variable - Used by the thread manager to find and lock a THD.


Status variable - Server or plugin status counter. Not dynamic. System variable - Server or plugin configuration variable. Usually dynamic. GLOBAL scope - Associated with the server, no context at thread level. SESSION scope - Associated with a connection or thread, but no global context. BOTH scope - Globally defined but applies at the session level. Initialize - Build list of variables in SHOW_VAR format. Materialize - Convert variables in SHOW_VAR list to string, cache for output. Manifest - Substep of Materialize. Resolve variable values according to type. This includes SHOW_FUNC types which are resolved by executing a callback function (possibly recursively), and SHOW_ARRAY types that expand into nested sub arrays.


System Variables LOCK_plugin_delete (block plugin delete) LOCK_system_variables_hash LOCK_thd_data (block THD delete) LOCK_thd_sysvar (block system variable updates, alloc_and_copy_thd_dynamic_variables) LOCK_global_system_variables (very briefly held)

Status Variables LOCK_status LOCK_thd_data (block THD delete)



Typedef Documentation

◆ PFS_client

◆ Show_var_array

◆ Status_var_array

typedef std::vector<SHOW_VAR> Status_var_array

Function Documentation

◆ status_variable_warning()

void status_variable_warning ( )

Warning issued if the global status variable array changes during a query.

This can happen when a plugin is loaded or unloaded.

◆ sum_account_status()

void sum_account_status ( PFS_client pfs_account,
System_status_var status_totals 

◆ sum_host_status()

void sum_host_status ( PFS_client pfs_host,
System_status_var status_totals 

◆ sum_user_status()

void sum_user_status ( PFS_client pfs_user,
System_status_var status_totals 

◆ system_variable_warning()

void system_variable_warning ( )

Warning issued if the version of the system variable hash table changes during a query.

This can happen when a plugin is loaded or unloaded.

Variable Documentation

◆ all_status_vars

Status_var_array all_status_vars

◆ LOCK_plugin_delete

mysql_mutex_t LOCK_plugin_delete

◆ status_vars_inited

bool status_vars_inited