Skip to content

Commit

Permalink
[mysql-5.6][PR] FB8-206: Avoid executing status var functions during …
Browse files Browse the repository at this point in the history
…`SHOW STATUS` when not required

Summary:
Jira issue: https://jira.percona.com/browse/FB8-206

Reference Patch: bf0baf3f7af
Status var functions were always executed irrespective of matching
string in the `LIKE` clause of `SHOW STATUS`. This caused execution of
some heavy status var functions like `show_jemalloc_*` every time `SHOW
STATUS` was invoked.

In this change we execute the status var function only for vars whose
names are strict prefixes of the wildcard specified in the `LIKE`
clause. Since we're checking for strict prefix match, we might get false
positives in some cases. We cannot use normal wildcard matching (like
other function-less status vars) because some var names are constructed
recursively in `show_status_array()` (e.g.
`Rpl_semi_sync_master_trx_wait_histogram%` is composed out of
`Rpl_semi_sync_master` and `trx_wait_histogram`).

Originally Reviewed By: midom, anirbanr-fb
Pull Request resolved: #1009
GitHub Author: [email protected] <[email protected]>

Test Plan: Imported from GitHub, without a `Test Plan:` line.

Reviewers:

Subscribers: butterflybot, vinaybhat, [email protected]

Differential Revision: https://phabricator.intern.facebook.com/D14884044
  • Loading branch information
facebook-github-bot authored and Herman Lee committed Apr 18, 2019
1 parent 7f595e0 commit 7cac65b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions storage/perfschema/pfs_variable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
@file storage/perfschema/pfs_variable.cc
Performance schema system variable and status variable (implementation).
*/
#include "mf_wcomp.h"
#include "my_dbug.h"
#include "my_macros.h"
#include "my_sys.h"
Expand Down Expand Up @@ -1362,6 +1363,18 @@ void PFS_status_variable_cache::manifest(THD *thd,
System_status_var *status_vars,
const char *prefix, bool nested_array,
bool strict) {
const LEX *lex = thd->lex;
const char *const wild = lex->wild ? lex->wild->ptr() : nullptr;

// Find the length of the user's 'LIKE' parameter until the first wildcard
std::size_t before_wild_len = 0;
while (wild && wild[before_wild_len] != wild_one &&
wild[before_wild_len] != wild_many &&
wild[before_wild_len] != wild_prefix &&
wild[before_wild_len] != '\0') {
++before_wild_len;
}

for (const SHOW_VAR *show_var_iter = show_var_array;
show_var_iter && show_var_iter->name; show_var_iter++) {
// work buffer, must be aligned to handle long/longlong values
Expand All @@ -1376,6 +1389,17 @@ void PFS_status_variable_cache::manifest(THD *thd,
SHOW_FUNC resolves to another SHOW_FUNC.
*/
if (show_var_ptr->type == SHOW_FUNC) {
if (before_wild_len > 0) {
const auto len = strlen(show_var_ptr->name);
/* Perform prefix match */
if (system_charset_info->coll->strnncoll(
system_charset_info,
reinterpret_cast<const uchar *>(show_var_ptr->name), len,
reinterpret_cast<const uchar *>(wild), before_wild_len,
true) != 0)
continue;
}

show_var_tmp = *show_var_ptr;
/*
Execute the function reference in show_var_tmp->value, which returns
Expand Down

0 comments on commit 7cac65b

Please sign in to comment.