Performance schema system and status variables (declarations).
OVERVIEW
Status and system variables are implemented differently in the server, but the steps to process them in the Performance Schema are essentially the same:
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
Steps:
- 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.
- 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.
- OUTPUT - Iterate the cache for the SHOW command or table query.
CLASS OVERVIEW
- System_variable - A materialized system variable
- Status_variable - A materialized status variable
- 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()
- PFS_system_variable_cache - System variable implementation of PFS_variable_cache
- PFS_status_variable_cache - Status variable implementation of PFS_variable_cache
- Find_THD_variable - Used by the thread manager to find and lock a THD.
GLOSSARY
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.
LOCK PRIORITIES
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)