Skip to content

Commit 1f8bbe8

Browse files
pikidbussink
authored andcommitted
Add innodb-extra-system-table-prefixes option
With this option it's possible to exclude certain system tables from rows read metrics.
1 parent f7ee83d commit 1f8bbe8

File tree

7 files changed

+76
-13
lines changed

7 files changed

+76
-13
lines changed

storage/innobase/api/api0api.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ static ib_err_t ib_execute_insert_query_graph(
10731073

10741074
dict_table_n_rows_inc(table);
10751075

1076-
if (table->is_system_table) {
1076+
if (table->is_system_table_metrics) {
10771077
srv_stats.n_system_rows_inserted.inc();
10781078
} else {
10791079
srv_stats.n_rows_inserted.inc();
@@ -1398,13 +1398,13 @@ static inline ib_err_t ib_execute_update_query_graph(
13981398
if (node->is_delete) {
13991399
dict_table_n_rows_dec(table);
14001400

1401-
if (table->is_system_table) {
1401+
if (table->is_system_table_metrics) {
14021402
srv_stats.n_system_rows_deleted.inc();
14031403
} else {
14041404
srv_stats.n_rows_deleted.inc();
14051405
}
14061406
} else {
1407-
if (table->is_system_table) {
1407+
if (table->is_system_table_metrics) {
14081408
srv_stats.n_system_rows_updated.inc();
14091409
} else {
14101410
srv_stats.n_rows_updated.inc();

storage/innobase/dict/mem.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,38 @@ static bool dict_mem_table_is_system(const std::string name) {
178178
}
179179
}
180180

181+
static std::vector<std::string> innobase_system_databases_metrics({
182+
"mysql/", "information_schema/", "performance_schema/"
183+
});
184+
185+
/** Determines if a table is a system table for metrics purposes
186+
@param[in] name table_name
187+
@return true if table is system table */
188+
static bool dict_mem_table_is_system_metrics(const std::string &name) {
189+
/* Table has the following format: database/table and some system table are
190+
of the form SYS_* */
191+
if (name.find('/') == std::string::npos)
192+
return true;
193+
194+
for (auto p : innobase_system_databases_metrics) {
195+
if (name.length() > p.length() && name.compare(0, p.length(), p) == 0)
196+
return true;
197+
}
198+
199+
return false;
200+
}
201+
202+
void dict_add_system_metrics_prefix(const char *pfx) {
203+
if (!pfx || !pfx[0])
204+
return;
205+
206+
std::string pfx_s = pfx;
207+
if (pfx_s[pfx_s.size()-1] != '/')
208+
pfx_s += '/';
209+
if (std::find(innobase_system_databases_metrics.begin(), innobase_system_databases_metrics.end(), pfx_s) == innobase_system_databases_metrics.end())
210+
innobase_system_databases_metrics.push_back(pfx_s);
211+
}
212+
181213
dict_table_t *dict_mem_table_create(const char *name, space_id_t space,
182214
ulint n_cols, ulint n_v_cols,
183215
ulint n_m_v_cols, uint32_t flags,
@@ -211,6 +243,7 @@ dict_table_t *dict_mem_table_create(const char *name, space_id_t space,
211243
table->flags2 = (unsigned int)flags2;
212244
table->name.m_name = mem_strdup(name);
213245
table->is_system_table = dict_mem_table_is_system(table->name.m_name);
246+
table->is_system_table_metrics = dict_mem_table_is_system_metrics(table->name.m_name);
214247
table->space = (unsigned int)space;
215248
table->dd_space_id = dd::INVALID_OBJECT_ID;
216249
table->n_t_cols = (unsigned int)(n_cols + table->get_n_sys_cols());

storage/innobase/dict/mem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,9 @@ const char *dict_add_col_name(const char *col_names, /*!< in: existing column
105105
ulint cols, /*!< in: number of existing columns */
106106
const char *name, /*!< in: new column name */
107107
mem_heap_t *heap); /*!< in: heap */
108+
109+
/** Add the prefix 'pfx' to the list of database names that count as
110+
* system tables, rather than user tables, for the purposes of rows
111+
* {read,inserted,updated,deleted} counters. */
112+
void dict_add_system_metrics_prefix(const char *pfx);
108113
#endif

storage/innobase/handler/ha_innodb.cc

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ static ulong innodb_flush_method;
327327
stopword table to be used */
328328
static char *innobase_server_stopword_table = nullptr;
329329

330+
/* A comma-separated list of prefixes that designate system (not user) tables
331+
for metrics accounting. See also dict_mem_table_is_system. */
332+
static char *extra_system_table_prefixes = nullptr;
333+
330334
/* Below we have boolean-valued start-up parameters, and their default
331335
values */
332336

@@ -5604,6 +5608,15 @@ static int innobase_init_files(dict_init_mode_t dict_init_mode,
56045608
/* Turn on monitor counters that are default on */
56055609
srv_mon_default_on();
56065610

5611+
if (extra_system_table_prefixes) {
5612+
char *copy = strdup(extra_system_table_prefixes);
5613+
char *saveptr, *tok;
5614+
for (tok=my_strtok_r(copy, ",", &saveptr); tok; tok=my_strtok_r(NULL, ",", &saveptr)) {
5615+
dict_add_system_metrics_prefix(tok);
5616+
}
5617+
free(copy);
5618+
}
5619+
56075620
/* Unit Tests */
56085621
#ifdef UNIV_ENABLE_UNIT_TEST_GET_PARENT_DIR
56095622
unit_test_os_file_get_parent_dir();
@@ -10292,7 +10305,7 @@ int ha_innobase::index_read(
1029210305
switch (ret) {
1029310306
case DB_SUCCESS:
1029410307
error = 0;
10295-
if (m_prebuilt->table->is_system_table) {
10308+
if (m_prebuilt->table->is_system_table_metrics) {
1029610309
srv_stats.n_system_rows_read.add(
1029710310
thd_get_thread_id(m_prebuilt->trx->mysql_thd), 1);
1029810311
} else if (!m_user_thd->security_context()->exclude_user_from_rows_read()) {
@@ -10540,7 +10553,7 @@ int ha_innobase::general_fetch(
1054010553
switch (ret) {
1054110554
case DB_SUCCESS:
1054210555
error = 0;
10543-
if (m_prebuilt->table->is_system_table) {
10556+
if (m_prebuilt->table->is_system_table_metrics) {
1054410557
srv_stats.n_system_rows_read.add(
1054510558
thd_get_thread_id(m_prebuilt->trx->mysql_thd), 1);
1054610559
} else if (!m_user_thd->security_context()->exclude_user_from_rows_read()) {
@@ -22034,6 +22047,12 @@ static MYSQL_SYSVAR_STR(ft_server_stopword_table,
2203422047
"The user supplied stopword table name.",
2203522048
innodb_stopword_table_validate, nullptr, nullptr);
2203622049

22050+
static MYSQL_SYSVAR_STR(extra_system_table_prefixes,
22051+
extra_system_table_prefixes,
22052+
PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR | PLUGIN_VAR_RQCMDARG,
22053+
"Additional prefixes that designate system (not user) tables for metrics accounting.",
22054+
nullptr, nullptr, nullptr);
22055+
2203722056
static MYSQL_SYSVAR_UINT(flush_log_at_timeout, srv_flush_log_at_timeout,
2203822057
PLUGIN_VAR_OPCMDARG,
2203922058
"Write and flush logs every (n) second.", nullptr,
@@ -23240,6 +23259,7 @@ static SYS_VAR *innobase_system_variables[] = {
2324023259
MYSQL_SYSVAR(ft_aux_table),
2324123260
MYSQL_SYSVAR(ft_enable_diag_print),
2324223261
MYSQL_SYSVAR(ft_server_stopword_table),
23262+
MYSQL_SYSVAR(extra_system_table_prefixes),
2324323263
MYSQL_SYSVAR(ft_user_stopword_table),
2324423264
MYSQL_SYSVAR(disable_sort_file_cache),
2324523265
MYSQL_SYSVAR(stats_on_metadata),

storage/innobase/include/dict0mem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,10 @@ struct dict_table_t {
21012101
or performance_schema) */
21022102
bool is_system_table;
21032103

2104+
/** True if the table stats should be seen as a system table (mysql, information_schema
2105+
or performance_schema) */
2106+
bool is_system_table_metrics;
2107+
21042108
/** Hash chain node. */
21052109
hash_node_t name_hash;
21062110

storage/innobase/mtr/mtr0log.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ static byte *mlog_parse_index_v1(byte *ptr, const byte *end_ptr,
13031303
}
13041304

13051305
table->is_system_table = false;
1306+
table->is_system_table_metrics = false;
13061307

13071308
if (is_instant || is_versioned) {
13081309
if (is_versioned) {

storage/innobase/row/row0mysql.cc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,7 @@ static dberr_t row_insert_for_mysql_using_cursor(const byte *mysql_rec,
14851485
, with a latch. */
14861486
dict_table_n_rows_inc(node->table);
14871487

1488-
if (node->table->is_system_table) {
1488+
if (node->table->is_system_table_metrics) {
14891489
srv_stats.n_system_rows_inserted.inc();
14901490
} else {
14911491
srv_stats.n_rows_inserted.inc();
@@ -1679,7 +1679,7 @@ static dberr_t row_insert_for_mysql_using_ins_graph(const byte *mysql_rec,
16791679

16801680
que_thr_stop_for_mysql_no_error(thr, trx);
16811681

1682-
if (table->is_system_table) {
1682+
if (table->is_system_table_metrics) {
16831683
srv_stats.n_system_rows_inserted.inc();
16841684
} else {
16851685
srv_stats.n_rows_inserted.inc();
@@ -2225,7 +2225,7 @@ static dberr_t row_del_upd_for_mysql_using_cursor(row_prebuilt_t *prebuilt) {
22252225
if (node->is_delete) {
22262226
if (err == DB_SUCCESS) {
22272227
dict_table_n_rows_dec(prebuilt->table);
2228-
if (node->table->is_system_table) {
2228+
if (node->table->is_system_table_metrics) {
22292229
srv_stats.n_system_rows_deleted.inc();
22302230
} else {
22312231
srv_stats.n_rows_deleted.inc();
@@ -2239,7 +2239,7 @@ static dberr_t row_del_upd_for_mysql_using_cursor(row_prebuilt_t *prebuilt) {
22392239
err = row_update_for_mysql_using_cursor(node, delete_entries, thr);
22402240

22412241
if (err == DB_SUCCESS) {
2242-
if (node->table->is_system_table) {
2242+
if (node->table->is_system_table_metrics) {
22432243
srv_stats.n_system_rows_updated.inc();
22442244
} else {
22452245
srv_stats.n_rows_updated.inc();
@@ -2408,13 +2408,13 @@ static dberr_t row_update_for_mysql_using_upd_graph(const byte *mysql_rec,
24082408
with a latch. */
24092409
dict_table_n_rows_dec(prebuilt->table);
24102410

2411-
if (table->is_system_table) {
2411+
if (table->is_system_table_metrics) {
24122412
srv_stats.n_system_rows_deleted.inc();
24132413
} else {
24142414
srv_stats.n_rows_deleted.inc();
24152415
}
24162416
} else {
2417-
if (table->is_system_table) {
2417+
if (table->is_system_table_metrics) {
24182418
srv_stats.n_system_rows_updated.inc();
24192419
} else {
24202420
srv_stats.n_rows_updated.inc();
@@ -2641,13 +2641,13 @@ dberr_t row_update_cascade_for_mysql(
26412641
with a latch. */
26422642
dict_table_n_rows_dec(table);
26432643

2644-
if (table->is_system_table) {
2644+
if (table->is_system_table_metrics) {
26452645
srv_stats.n_system_rows_deleted.add((size_t)trx->id, 1);
26462646
} else {
26472647
srv_stats.n_rows_deleted.add((size_t)trx->id, 1);
26482648
}
26492649
} else {
2650-
if (table->is_system_table) {
2650+
if (table->is_system_table_metrics) {
26512651
srv_stats.n_system_rows_updated.add((size_t)trx->id, 1);
26522652
} else {
26532653
srv_stats.n_rows_updated.add((size_t)trx->id, 1);

0 commit comments

Comments
 (0)