YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
staticinline SHOW_SCOPE show_scope_from_type(enum enum_mysql_show_type type)
{ switch(type) { case SHOW_BOOL: case SHOW_CHAR: case SHOW_CHAR_PTR: case SHOW_DOUBLE: case SHOW_HAVE: case SHOW_HA_ROWS: case SHOW_KEY_CACHE_LONG: case SHOW_LEX_STRING: case SHOW_LONG_NOFLUSH: case SHOW_MY_BOOL: case SHOW_SINT: case SHOW_SLONG: case SHOW_SLONGLONG: case SHOW_SYS: case SHOW_UINT: case SHOW_ULONG: case SHOW_ULONGLONG: case SHOW_LONGLONG_NOFLUSH: return SHOW_SCOPE_GLOBAL;
case SHOW_DOUBLE_STATUS: case SHOW_LONGLONG_STATUS: case SHOW_LONG_STATUS: return SHOW_SCOPE_ALL;
case SHOW_ARRAY: case SHOW_FUNC: case SHOW_SIMPLE_FUNC: case SHOW_UNDEF: default: return SHOW_SCOPE_ALL;
} return SHOW_SCOPE_UNDEF;
}
case sys_var::ONLY_SESSION: return m_query_scope == OPT_SESSION; break;
default: returnfalse; break;
} returnfalse;
}
/** BuildaGLOBALsystemvariablecache.
*/ int PFS_system_variable_cache::do_materialize_global(void)
{ /* Block system variable additions or deletions. */
mysql_mutex_lock(&LOCK_global_system_variables);
m_materialized= false;
/* BuildarrayofSHOW_VARsfromsystemvariablehash.Dothiswithin LOCK_plugin_deletetoensurethatthehashtableremainsunchanged duringmaterialization.
*/ if (!m_external_init)
init_show_var_array(OPT_GLOBAL, true);
/* Resolve the value for each SHOW_VAR in the array, add to cache. */ for (SHOW_VAR *show_var= m_show_var_array.front();
show_var->value && (show_var != m_show_var_array.end()); show_var++)
{ const Lex_ident_sys_var name= Lex_cstring_strlen(show_var->name);
sys_var *value= (sys_var *)show_var->value;
assert(value);
if ((m_query_scope == OPT_GLOBAL) &&
name.streq("sql_log_bin"_LEX_CSTRING))
{ /* PLEASEREAD: http://dev.mysql.com/doc/relnotes/mysql/5.7/en/news-5-7-6.html
/* Match the system variable scope to the target scope. */ if (match_scope(value->scope()))
{ /* Resolve value, convert to text, add to cache. */
System_variable system_var(m_current_thd, show_var, m_query_scope, false);
m_cache.push(system_var);
}
}
/* Block plugins from unloading. */
mysql_mutex_lock(&LOCK_plugin_delete);
/* The SHOW_VAR array must be initialized externally. */
assert(m_initialized);
/* Use a temporary mem_root to avoid depleting THD mem_root. */ if (m_use_mem_root)
set_mem_root();
/* Get and lock a validated THD from the thread manager. */ if ((m_safe_thd= get_THD(pfs_thread)) != NULL)
{ for (SHOW_VAR *show_var= m_show_var_array.front();
show_var->value && (show_var != m_show_var_array.end()); show_var++)
{
sys_var *value= (sys_var *)show_var->value;
/* Match the system variable scope to the target scope. */ if (match_scope(value->scope()))
{ /* Resolve value, convert to text, add to cache. */
System_variable system_var(m_safe_thd, show_var, m_query_scope, false);
m_cache.push(system_var);
}
}
/* Release lock taken in get_THD(). */ if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
m_materialized= true;
ret= 0;
}
/* Mark mem_root blocks as free. */ if (m_use_mem_root)
clear_mem_root();
/* Block plugins from unloading. */
mysql_mutex_lock(&LOCK_plugin_delete);
/* The SHOW_VAR array must be initialized externally. */
assert(m_initialized);
/* Get and lock a validated THD from the thread manager. */ if ((m_safe_thd= get_THD(pfs_thread)) != NULL)
{
SHOW_VAR *show_var= &m_show_var_array.at(index);
/* Match the system variable scope to the target scope. */ if (match_scope(value->scope()))
{ /* Resolve value, convert to text, add to cache. */
System_variable system_var(m_safe_thd, show_var, m_query_scope, false);
m_cache.push(system_var);
}
}
/* Release lock taken in get_THD(). */ if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
/* Block plugins from unloading. */
mysql_mutex_lock(&LOCK_plugin_delete);
/* BuildarrayofSHOW_VARsfromsystemvariablehash.Dothiswithin LOCK_plugin_deletetoensurethatthehashtableremainsunchanged whilethisthreadismaterialized.
*/ if (!m_external_init)
init_show_var_array(OPT_SESSION, true);
/* Get and lock a validated THD from the thread manager. */ if ((m_safe_thd= get_THD(unsafe_thd)) != NULL)
{ for (SHOW_VAR *show_var= m_show_var_array.front();
show_var->value && (show_var != m_show_var_array.end()); show_var++)
{
sys_var *value = (sys_var *)show_var->value;
/* Match the system variable scope to the target scope. */ if (match_scope(value->scope()))
{ /* Resolve value, convert to text, add to cache. */
System_variable system_var(m_safe_thd, show_var, m_query_scope, false);
m_cache.push(system_var);
}
}
/* Release lock taken in get_THD(). */ if (m_safe_thd != current_thd)
mysql_mutex_unlock(&m_safe_thd->LOCK_thd_kill);
/* Deprecated variables are ignored but must still be accounted for. */ if (m_ignore)
{
m_value_str[0]= '\0';
m_value_length= 0;
m_initialized= true; return;
}
/* Block remote target thread from updating this system variable. */ /*XXX THD*current_thread=current_thd; if(target_thd!=current_thread)
mysql_mutex_lock(&target_thd->LOCK_thd_sysvar);*/
/* Get the value of the system variable. */
String buf(m_value_str, sizeof(m_value_str) - 1, system_charset_info); if (!system_var->val_str_nolock(&buf, target_thd,
system_var->value_ptr(target_thd, query_scope, &null_clex_str)))
buf.length(0);
/* Returned value may reference a string other than m_value_str. */ if (buf.ptr() != m_value_str)
memcpy(m_value_str, buf.ptr(), m_value_length);
m_value_str[m_value_length]= 0;
PFS_status_variable_cache::
PFS_status_variable_cache(bool external_init) :
PFS_variable_cache<Status_variable>(external_init),
m_show_command(false), m_sum_client_status(NULL)
{ /* Determine if the originating query is a SHOW command. */
m_show_command= (m_current_thd->lex->sql_command == SQLCOM_SHOW_STATUS);
}
/** BuildcacheofSESSIONstatusvariablesforauser.
*/ int PFS_status_variable_cache::materialize_user(PFS_user *pfs_user)
{ if (!pfs_user) return1;
/** BuildcacheofSESSIONstatusvariablesforanaccount.
*/ int PFS_status_variable_cache::materialize_account(PFS_account *pfs_account)
{ if (!pfs_account) return1;
if (is_materialized(pfs_account)) return0;
if (!pfs_account->m_lock.is_populated()) return1;
/* Set callback function. */
m_sum_client_status= sum_account_status; return do_materialize_client((PFS_client *)pfs_account);
} /** Comparestatusvariablescopetodesiredscope. @paramvariable_scopeScopeofcurrentstatusvariable @returnTRUEifvariablematchesthequeryscope
*/ bool PFS_status_variable_cache::match_scope(SHOW_SCOPE variable_scope, bool strict)
{ switch (variable_scope)
{ case SHOW_SCOPE_GLOBAL: return (m_query_scope == OPT_GLOBAL) || (! strict && (m_query_scope == OPT_SESSION)); break; case SHOW_SCOPE_SESSION: /* Ignore session-only vars if aggregating by user, host or account. */ if (m_aggregate) returnfalse; else return (m_query_scope == OPT_SESSION); break; case SHOW_SCOPE_ALL: return (m_query_scope == OPT_GLOBAL || m_query_scope == OPT_SESSION); break; case SHOW_SCOPE_UNDEF: default: returnfalse; break;
} returnfalse;
}
if (show_var->type == SHOW_ARRAY)
{ /* The SHOW_ARRAY name is the prefix for the variables in the subarray. */ const Lex_ident_sys_var prefix= Lex_cstring_strlen(show_var->name); /* Exclude COM counters if not a SHOW STATUS command. */ if (prefix.streq("Com"_LEX_CSTRING) && !m_show_command) returntrue;
} else
{ /* SlavestatusresidesinPerformanceSchemareplicationtables.Exclude theseslavestatusvariablesfromtheSHOWSTATUScommandandfromthe statustables. Assumenullprefixtoensurethatonlyserver-definedslavestatus variablesarefiltered.
*/ const Lex_ident_sys_var name= Lex_cstring_strlen(show_var->name); if (name.streq("Slave_running"_LEX_CSTRING) ||
name.streq("Slave_retried_transactions"_LEX_CSTRING) ||
name.streq("Slave_last_heartbeat"_LEX_CSTRING) ||
name.streq("Slave_received_heartbeats"_LEX_CSTRING) ||
name.streq("Slave_heartbeat_period"_LEX_CSTRING))
{ returntrue;
}
}
returnfalse;
}
/** Checkthatthevariabletypeisaggregatable.
@paramvariable_typeStatusvariabletype @returnTRUEifvariabletypecanbeaggregated
*/ bool PFS_status_variable_cache::can_aggregate(enum_mysql_show_type variable_type)
{ switch(variable_type)
{ /* Allserverstatuscountersthataretotaledacrossthreadsaredefinedin system_status_varaseitherSHOW_LONGLONG_STATUSorSHOW_LONG_STATUS. Thesedatatypesarenotavailabletoplugins.
*/ case SHOW_LONGLONG_STATUS: case SHOW_LONG_STATUS: returntrue; break;
/* Server and plugin */ case SHOW_UNDEF: case SHOW_BOOL: case SHOW_CHAR: case SHOW_CHAR_PTR: case SHOW_ARRAY: case SHOW_FUNC: case SHOW_SIMPLE_FUNC: case SHOW_INT: case SHOW_LONG: case SHOW_LONGLONG: case SHOW_DOUBLE: /* Server only */ case SHOW_HAVE: case SHOW_MY_BOOL: case SHOW_SYS: case SHOW_LEX_STRING: case SHOW_KEY_CACHE_LONG: case SHOW_DOUBLE_STATUS: case SHOW_HA_ROWS: case SHOW_LONG_NOFLUSH: case SHOW_LONGLONG_NOFLUSH: case SHOW_SLONG: default: returnfalse; break;
}
}
/** Checkifastatusvariableshouldbeexcludedfromthequery. ReturnTRUEifthevariableshouldbeexcluded.
*/ bool PFS_status_variable_cache::filter_show_var(const SHOW_VAR *show_var, bool strict)
{ /* Match the variable scope with the query scope. */ if (!match_scope(show_scope_from_type(show_var->type), strict)) returntrue;
/* Exclude specific status variables by name or prefix. */ if (filter_by_name(show_var)) returntrue;
/* For user, host or account, ignore variables having non-aggregatable types. */ if (m_aggregate && !can_aggregate(show_var->type)) returntrue;
/* Check if this status var should be excluded from the query. */ if (filter_show_var(&show_var, strict)) continue;
if (show_var.type == SHOW_ARRAY)
{ /* Expand nested subarray. The name is used as a prefix. */
expand_show_var_array((SHOW_VAR *)show_var.value, show_var.name, strict);
} else
{
show_var.name= make_show_var_name(NULL, show_var.name);
m_show_var_array.push(show_var);
}
}
/* Last element is NULL. */
st_mysql_show_var empty= {0,0,SHOW_UNDEF};
m_show_var_array.push(empty);
/* Get the latest version of all_status_vars. */
m_version= get_status_vars_version();
/* Increase cache size if necessary. */
m_cache.reserve(m_show_var_array.elements());
if (show_var.type == SHOW_ARRAY)
{ char name_buf[SHOW_VAR_MAX_NAME_LEN];
show_var.name= make_show_var_name(prefix, show_var.name, name_buf, sizeof(name_buf)); /* Expand nested subarray. The name is used as a prefix. */
expand_show_var_array((SHOW_VAR *)show_var.value, show_var.name, strict);
} else
{ /* Add the SHOW_VAR element. Make a local copy of the name string. */
show_var.name= make_show_var_name(prefix, show_var.name);
m_show_var_array.push(show_var);
}
}
}
if (prefix && *prefix)
{ /* Drop the prefix into the front of the name buffer. */
prefix_end= my_stpnmov(name_buf, prefix, buf_len-1);
*prefix_end++= '_';
}
/* Restrict name length to remaining buffer size. */
size_t max_name_len= name_buf + buf_len - prefix_end;
/* Load the name into the buffer after the prefix. */
my_stpnmov(prefix_end, name, max_name_len);
name_buf[buf_len-1]= 0;
/* IfweareexpandingaSHOW_ARRAY,filtervariablesthatwerenotprefilteredby init_show_var_array().
*/ if (nested_array && filter_show_var(show_var_ptr, strict)) continue;
if (show_var_ptr->type == SHOW_ARRAY)
{ /* StatusvariablesoftypeSHOW_ARRAYwereexpandedandfilteredby init_show_var_array(),exceptwhereaSHOW_FUNCresolvesintoa SHOW_ARRAY,suchaswithInnoDB.Recursetoexpandthesubarray.
*/
manifest(thd, (SHOW_VAR *)show_var_ptr->value, status_vars, show_var_ptr->name, true, strict);
} else
{ /* Add the materialized status variable to the cache. */
SHOW_VAR show_var= *show_var_ptr; /* Fornestedarrayexpansions,makeacopyofthevariablename,justas doneininit_show_var_array().
*/ if (nested_array)
show_var.name= make_show_var_name(prefix, show_var_ptr->name);
/* Convert status value to string format. Add to the cache. */
Status_variable status_var(&show_var, status_vars, m_query_scope);
m_cache.push(status_var);
}
}
}
/* Get the value of the status variable. */ constchar *value;
value= get_one_variable(current_thd, show_var, query_scope, m_type,
status_vars, &m_charset, m_value_str, &m_value_length);
m_value_length= MY_MIN(m_value_length, SHOW_VAR_FUNC_BUFF_SIZE);
m_charset= system_charset_info;
/* Returned value may reference a string other than m_value_str. */ if (value != m_value_str)
memcpy(m_value_str, value, m_value_length);
m_value_str[m_value_length]= 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.