Skip to content

Commit aae89bc

Browse files
committed
Add innodb-extra-system-table-prefixes option
Now you can add to the list of prefixes that designates a table as a "system" table for accounting purposes, rather than a user table. A prefix is a database name. For example, "use foo ; select * from bar" queries the table "foo/bar". If "foo/" is in the prefix list, then queries against "foo/bar" will be treated as system queries. System queries get counted against system {read,inserted,updated,deleted} metrics rather than the equivalent user metrics. At PlanetScale, this is important because the user rows_read metric is a major input to the billing system and Insights. The `innodb-extra-system-table-prefixes` option works on the command line: ``` --innodb-extra-system-table-prefixes=foo,bar ``` or in my.cnf: ``` [mysqld] rows-read-exclude-users = vt_repl,orc_client_user innodb-extra-system-table-prefixes = foo,bar ``` It cannot be shown using `SHOW VARIABLE like ...` syntax or set using `SET variable = ...` syntax. Specified prefix match a table spec iff they match up to a comma. Specifying a prefix `foo/` is the same as specifying a prefix `foo`. `foo` will only match `foo/something`, not `football/something`.
1 parent d9d8727 commit aae89bc

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

storage/innobase/dict/mem.cc

Lines changed: 21 additions & 0 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"
@@ -157,19 +158,39 @@ static std::vector<std::string> innobase_system_databases({
157158
static bool dict_mem_table_is_system(const std::string &name) {
158159
/* Table has the following format: database/table and some system table are
159160
of the form SYS_* */
161+
printf("PIKI: is_system?(\"%s\")\n", name.c_str());
160162
if (name.find('/') == std::string::npos) {
163+
printf("PIKI: true, no slash\n");
161164
return true;
162165
}
163166

164167
for (auto p : innobase_system_databases) {
168+
printf("PIKI: compare to \"%s\"\n", p.c_str());
165169
if (name.length() > p.length() && name.compare(0, p.length(), p) == 0) {
170+
printf("PIKI: true\n");
166171
return true;
167172
}
168173
}
169174

175+
printf("PIKI: false\n");
170176
return false;
171177
}
172178

179+
void dict_add_system_prefix(const char *pfx) {
180+
printf("PIKI: add \"%s\"\n", pfx);
181+
if (!pfx || !pfx[0])
182+
return;
183+
std::string pfx_s = pfx;
184+
if (pfx_s[pfx_s.size()-1] != '/')
185+
pfx_s += '/';
186+
if (std::find(innobase_system_databases.begin(), innobase_system_databases.end(), pfx_s) == innobase_system_databases.end()) {
187+
innobase_system_databases.push_back(pfx_s);
188+
}
189+
else {
190+
printf("PIKI: already present\n");
191+
}
192+
}
193+
173194
/** Creates a table memory object.
174195
@return own: table object */
175196
dict_table_t *dict_mem_table_create(

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)