Skip to content

Commit 65a3e5d

Browse files
authored
Merge pull request mysql#17 from planetscale/piki/unmetered-vt-db
Add `innodb-extra-system-table-prefixes` option
2 parents 4c44738 + 1def892 commit 65a3e5d

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
@@ -269,6 +269,10 @@ static ulong innodb_flush_method;
269269
stopword table to be used */
270270
static char *innobase_server_stopword_table = nullptr;
271271

272+
/* A comma-separated list of prefixes that designate system (not user) tables
273+
for metrics accounting. See also dict_mem_table_is_system. */
274+
static char *extra_system_table_prefixes = nullptr;
275+
272276
/* Below we have boolean-valued start-up parameters, and their default
273277
values */
274278

@@ -5177,6 +5181,15 @@ static int innobase_init_files(dict_init_mode_t dict_init_mode,
51775181
/* Turn on monitor counters that are default on */
51785182
srv_mon_default_on();
51795183

5184+
if (extra_system_table_prefixes) {
5185+
char *copy = strdup(extra_system_table_prefixes);
5186+
char *saveptr, *tok;
5187+
for (tok=my_strtok_r(copy, ",", &saveptr); tok; tok=my_strtok_r(NULL, ",", &saveptr)) {
5188+
dict_add_system_prefix(tok);
5189+
}
5190+
free(copy);
5191+
}
5192+
51805193
/* Unit Tests */
51815194
#ifdef UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR
51825195
unit_test_os_file_get_parent_dir();
@@ -21362,6 +21375,12 @@ static MYSQL_SYSVAR_STR(ft_server_stopword_table,
2136221375
"The user supplied stopword table name.",
2136321376
innodb_stopword_table_validate, nullptr, nullptr);
2136421377

21378+
static MYSQL_SYSVAR_STR(extra_system_table_prefixes,
21379+
extra_system_table_prefixes,
21380+
PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_RQCMDARG,
21381+
"Additional prefixes that designate system (not user) tables for metrics accounting.",
21382+
nullptr, nullptr, nullptr);
21383+
2136521384
static MYSQL_SYSVAR_UINT(flush_log_at_timeout, srv_flush_log_at_timeout,
2136621385
PLUGIN_VAR_OPCMDARG,
2136721386
"Write and flush logs every (n) second.", nullptr,
@@ -22546,6 +22565,7 @@ static SYS_VAR *innobase_system_variables[] = {
2254622565
MYSQL_SYSVAR(ft_aux_table),
2254722566
MYSQL_SYSVAR(ft_enable_diag_print),
2254822567
MYSQL_SYSVAR(ft_server_stopword_table),
22568+
MYSQL_SYSVAR(extra_system_table_prefixes),
2254922569
MYSQL_SYSVAR(ft_user_stopword_table),
2255022570
MYSQL_SYSVAR(disable_sort_file_cache),
2255122571
MYSQL_SYSVAR(stats_on_metadata),

0 commit comments

Comments
 (0)