Skip to content

Commit b43d21f

Browse files
authored
Merge pull request mysql#18 from planetscale/piki/unmetered-vt-for-8.0.28
Cherry-pick mysql#17 for 8.0.28 (unmetered reads prefixes)
2 parents 9ae00a1 + 920ab1a commit b43d21f

File tree

3 files changed

+46
-19
lines changed

3 files changed

+46
-19
lines changed

storage/innobase/dict/mem.cc

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
3535
other files in library. The code in this file is used to make a library for
3636
external tools. */
3737

38+
#include <algorithm>
3839
#include <new>
3940

4041
#include "dict0dict.h"
@@ -147,35 +148,36 @@ void dict_mem_table_free(dict_table_t *table) /*!< in: table */
147148
}
148149

149150
/** System databases */
150-
static std::string innobase_system_databases[] = {
151-
"mysql/", "information_schema/", "performance_schema/", ""};
151+
static std::vector<std::string> innobase_system_databases({
152+
"mysql/", "information_schema/", "performance_schema/"
153+
});
152154

153155
/** Determines if a table is a system table
154156
@param[in] name table_name
155157
@return true if table is system table */
156-
static bool dict_mem_table_is_system(const std::string name) {
158+
static bool dict_mem_table_is_system(const std::string &name) {
157159
/* Table has the following format: database/table and some system table are
158160
of the form SYS_* */
159-
if (name.find('/') != std::string::npos) {
160-
size_t table_len = name.length();
161-
162-
std::string system_db = std::string(innobase_system_databases[0]);
163-
int i = 0;
161+
if (name.find('/') == std::string::npos)
162+
return true;
164163

165-
while (system_db.compare("") != 0) {
166-
size_t len = system_db.length();
164+
for (auto p : innobase_system_databases) {
165+
if (name.length() > p.length() && name.compare(0, p.length(), p) == 0)
166+
return true;
167+
}
167168

168-
if (table_len > len && name.compare(0, len, system_db) == 0) {
169-
return true;
170-
}
169+
return false;
170+
}
171171

172-
system_db = std::string(innobase_system_databases[++i]);
173-
}
172+
void dict_add_system_prefix(const char *pfx) {
173+
if (!pfx || !pfx[0])
174+
return;
174175

175-
return false;
176-
} else {
177-
return true;
178-
}
176+
std::string pfx_s = pfx;
177+
if (pfx_s[pfx_s.size()-1] != '/')
178+
pfx_s += '/';
179+
if (std::find(innobase_system_databases.begin(), innobase_system_databases.end(), pfx_s) == innobase_system_databases.end())
180+
innobase_system_databases.push_back(pfx_s);
179181
}
180182

181183
/** Creates a table memory object.

storage/innobase/dict/mem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,9 @@ const char *dict_add_col_name(const char *col_names, /*!< in: existing column
9191
ulint cols, /*!< in: number of existing columns */
9292
const char *name, /*!< in: new column name */
9393
mem_heap_t *heap); /*!< in: heap */
94+
95+
/** Add the prefix 'pfx' to the list of database names that count as
96+
* system tables, rather than user tables, for the purposes of rows
97+
* {read,inserted,updated,deleted} counters. */
98+
void dict_add_system_prefix(const char *pfx);
9499
#endif

storage/innobase/handler/ha_innodb.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ static ulong innodb_flush_method;
310310
stopword table to be used */
311311
static char *innobase_server_stopword_table = nullptr;
312312

313+
/* A comma-separated list of prefixes that designate system (not user) tables
314+
for metrics accounting. See also dict_mem_table_is_system. */
315+
static char *extra_system_table_prefixes = nullptr;
316+
313317
/* Below we have boolean-valued start-up parameters, and their default
314318
values */
315319

@@ -5446,6 +5450,15 @@ static int innobase_init_files(dict_init_mode_t dict_init_mode,
54465450
/* Turn on monitor counters that are default on */
54475451
srv_mon_default_on();
54485452

5453+
if (extra_system_table_prefixes) {
5454+
char *copy = strdup(extra_system_table_prefixes);
5455+
char *saveptr, *tok;
5456+
for (tok=my_strtok_r(copy, ",", &saveptr); tok; tok=my_strtok_r(NULL, ",", &saveptr)) {
5457+
dict_add_system_prefix(tok);
5458+
}
5459+
free(copy);
5460+
}
5461+
54495462
/* Unit Tests */
54505463
#ifdef UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR
54515464
unit_test_os_file_get_parent_dir();
@@ -21797,6 +21810,12 @@ static MYSQL_SYSVAR_STR(ft_server_stopword_table,
2179721810
"The user supplied stopword table name.",
2179821811
innodb_stopword_table_validate, nullptr, nullptr);
2179921812

21813+
static MYSQL_SYSVAR_STR(extra_system_table_prefixes,
21814+
extra_system_table_prefixes,
21815+
PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_RQCMDARG,
21816+
"Additional prefixes that designate system (not user) tables for metrics accounting.",
21817+
nullptr, nullptr, nullptr);
21818+
2180021819
extern uint srv_flush_log_at_timeout;
2180121820
static MYSQL_SYSVAR_UINT(flush_log_at_timeout, srv_flush_log_at_timeout,
2180221821
PLUGIN_VAR_OPCMDARG,
@@ -23006,6 +23025,7 @@ static SYS_VAR *innobase_system_variables[] = {
2300623025
MYSQL_SYSVAR(ft_aux_table),
2300723026
MYSQL_SYSVAR(ft_enable_diag_print),
2300823027
MYSQL_SYSVAR(ft_server_stopword_table),
23028+
MYSQL_SYSVAR(extra_system_table_prefixes),
2300923029
MYSQL_SYSVAR(ft_user_stopword_table),
2301023030
MYSQL_SYSVAR(disable_sort_file_cache),
2301123031
MYSQL_SYSVAR(stats_on_metadata),

0 commit comments

Comments
 (0)