From b1102eb4cae1c9b22a95dba14c18ef40a04b24ce Mon Sep 17 00:00:00 2001 From: Hunter Kang Date: Mon, 17 Aug 2026 23:28:54 +0000 Subject: [PATCH] Bug#121045 Server telemetry metrics backed by aggregated_stats_buffer always report 0 Problem: ======== 25 server telemetry (OTEL) metrics under the mysql.stats and mysql.stats.handler meters always export 0, while the matching SHOW GLOBAL STATUS counter reports real activity. These metrics are read by the async metric callback (get_metric_aggregated_integer in sql/mysqld.cc) from the sharded aggregated_stats_buffer, aggregated across shards by aggregated_stats::get_single_total. The read side, the metric registration, the shard field, its reset, and its cross-shard aggregation all exist, and the producer-side shard write is present for the counters that work (e.g. questions, com_*, ha_commit). For these 25 it is missing: the producers write only the per-THD status_var and never the shard the reader sums, so the exported value is a constant 0. Affected producers: - THD::inc_status_*() for the Select_*, Sort_*, and Created_tmp_* family (sql/sql_class.cc) plus long_query_count (sql/log.cc) and max_execution_time_exceeded (sql/sql_class.cc). - handler::ha_statistic_increment() (sql/handler.cc) for the Handler_* read/write family, reached from every storage engine. The defect is not observable through SQL (performance_schema.setup_metrics lists metric names but has no value column), which is why it went unnoticed. Solution: ========= Populate the shard next to every existing per-THD store, matching the established idiom already used by the counters that work. For the by-name producers, add the matching global_aggregated_stats.get_shard(thread_id()). increment next to the status_var store. handler::ha_statistic_increment() takes a ulonglong System_status_var::* member pointer, which cannot be reused for aggregated_stats_buffer (the two structs order their fields differently and the shard uses std::atomic_uint64_t). Extend the helper to also take the corresponding aggregated_stats_buffer member pointer and update the call sites to pass both. The shard store uses fetch_add with std::memory_order_relaxed: the value is only summed later by the reader and nothing synchronizes on it, and these counters sit on the per-row read path. Add an MTR regression test (perfschema.telemetry_metrics_shard_bug) that drives activity across the Select, Sort, Created_tmp, and Handler (read and write) families and asserts each covered metric is populated. It covers 19 of the 25 fixed counters; the other 6 (max_execution_time_ exceeded, mrr_init, select_range_check, select_full_range_join, sort_range, sort_merge_passes) are omitted because they cannot be driven nonzero deterministically and would make the test flaky. All 25 flow through the same two producer mechanisms (THD::inc_status_* and handler::ha_statistic_increment), both of which the 19 exercise. A -master.opt sets the component plugin-dir so the test component loads reliably. The test fails on the unfixed server (0) and passes once the shards are written. Note on later versions: this change is against 8.4 and fixes the 25 affected metrics present there. One further metric, count_hit_tmp_table_size, exists only in 9.x (added after 8.4) and is affected the same way; it is not touched by this change and will need a separate fix on the branch that introduces it. This contribution is under the OCA signed by Amazon and covering submissions to the MySQL project. --- .../r/telemetry_metrics_shard_bug.result | 43 +++++++ .../t/telemetry_metrics_shard_bug-master.opt | 1 + .../t/telemetry_metrics_shard_bug.test | 116 ++++++++++++++++++ sql/handler.cc | 18 ++- sql/handler.h | 6 +- sql/log.cc | 5 +- sql/sql_class.cc | 13 ++ storage/archive/ha_archive.cc | 10 +- storage/csv/ha_tina.cc | 16 ++- storage/federated/ha_federated.cc | 13 +- storage/heap/ha_heap.cc | 37 ++++-- storage/innobase/handler/ha_innodb.cc | 34 +++-- storage/innobase/handler/ha_innopart.cc | 7 +- storage/myisam/ha_myisam.cc | 43 ++++--- storage/myisammrg/ha_myisammrg.cc | 40 ++++-- storage/ndb/plugin/ha_ndbcluster.cc | 35 ++++-- storage/perfschema/ha_perfschema.cc | 25 ++-- storage/temptable/src/handler.cc | 29 +++-- 18 files changed, 393 insertions(+), 98 deletions(-) create mode 100644 mysql-test/suite/perfschema/r/telemetry_metrics_shard_bug.result create mode 100644 mysql-test/suite/perfschema/t/telemetry_metrics_shard_bug-master.opt create mode 100644 mysql-test/suite/perfschema/t/telemetry_metrics_shard_bug.test diff --git a/mysql-test/suite/perfschema/r/telemetry_metrics_shard_bug.result b/mysql-test/suite/perfschema/r/telemetry_metrics_shard_bug.result new file mode 100644 index 000000000000..77cbedb9f0a3 --- /dev/null +++ b/mysql-test/suite/perfschema/r/telemetry_metrics_shard_bug.result @@ -0,0 +1,43 @@ +INSTALL COMPONENT 'file://component_test_server_telemetry_metrics'; +UPDATE performance_schema.setup_meters SET enabled = 'YES'; +SET SESSION tmp_table_size = 1024; +SET SESSION max_heap_table_size = 16384; +SET SESSION long_query_time = 0; +CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c VARCHAR(60), KEY kb (b)); +CREATE TABLE t2 (x INT, y INT); +FLUSH STATUS; +# Drive each affected metric family: +SELECT * FROM t1 WHERE c > ''; +SELECT COUNT(*) FROM t1 a1 JOIN t1 a2 ON a1.c = a2.c; +SELECT * FROM t1 WHERE a BETWEEN 5 AND 400; +SELECT * FROM t1 ORDER BY c; +SELECT * FROM t1 ORDER BY a DESC LIMIT 5; +SELECT MIN(a), MAX(a) FROM t1; +SELECT a FROM t1 ORDER BY b LIMIT 400; +SELECT b, COUNT(*) FROM t1 GROUP BY b; +SELECT c, COUNT(*) FROM t1 GROUP BY c; +SELECT * FROM t1 WHERE a = 42; +INSERT INTO t1 VALUES (9001,1,'x'),(9002,2,'y'); +UPDATE t1 SET c = 'u' WHERE a = 9001; +DELETE FROM t1 WHERE a = 9002; +PASS: mysql.stats.select_scan populated +PASS: mysql.stats.select_full_join populated +PASS: mysql.stats.select_range populated +PASS: mysql.stats.sort_scan populated +PASS: mysql.stats.sort_rows populated +PASS: mysql.stats.created.tmp_tables populated +PASS: mysql.stats.created.tmp_disk_tables populated +PASS: mysql.stats.slow_queries populated +PASS: mysql.stats.handler.write populated +PASS: mysql.stats.handler.update populated +PASS: mysql.stats.handler.delete populated +PASS: mysql.stats.handler.read_key populated +PASS: mysql.stats.handler.read_next populated +PASS: mysql.stats.handler.read_prev populated +PASS: mysql.stats.handler.read_first populated +PASS: mysql.stats.handler.read_last populated +PASS: mysql.stats.handler.read_rnd populated +PASS: mysql.stats.handler.read_rnd_next populated +PASS: mysql.stats.handler.external_lock populated +DROP TABLE t1, t2; +UNINSTALL COMPONENT 'file://component_test_server_telemetry_metrics'; diff --git a/mysql-test/suite/perfschema/t/telemetry_metrics_shard_bug-master.opt b/mysql-test/suite/perfschema/t/telemetry_metrics_shard_bug-master.opt new file mode 100644 index 000000000000..7f11f7a01cdf --- /dev/null +++ b/mysql-test/suite/perfschema/t/telemetry_metrics_shard_bug-master.opt @@ -0,0 +1 @@ +$TEST_SERVER_TELEMETRY_METRICS_COMPONENT_OPT diff --git a/mysql-test/suite/perfschema/t/telemetry_metrics_shard_bug.test b/mysql-test/suite/perfschema/t/telemetry_metrics_shard_bug.test new file mode 100644 index 000000000000..db3ba82292d8 --- /dev/null +++ b/mysql-test/suite/perfschema/t/telemetry_metrics_shard_bug.test @@ -0,0 +1,116 @@ +# Regression test for the server telemetry metrics backed by +# aggregated_stats_buffer (mysql.stats, mysql.stats.handler). +# +# These metrics are read by the OTEL metric callback from the sharded +# aggregated_stats_buffer. The producers must write that shard next to the +# per-THD status_var store; if they do not, the metric exports a constant 0 +# while SHOW GLOBAL STATUS shows real activity. +# +# This test drives activity exercising the Select, Sort, Created_tmp and +# Handler (read and write) families, then asserts each covered metric is +# populated (nonzero). It FAILS on the unfixed server (metrics stuck at 0) and +# PASSES once the shard writes are in place. +# +# Coverage: 19 of the 25 fixed counters are asserted. The remaining 6 are +# intentionally NOT asserted because they cannot be driven nonzero +# deterministically and would make the test flaky: +# - max_execution_time_exceeded : timing dependent (query must exceed a wall +# clock limit) +# - mrr_init : depends on the optimizer choosing MRR +# - select_range_check : depends on "range checked for each record" +# - select_full_range_join : could not be driven nonzero reliably +# - sort_range : could not be driven nonzero reliably +# - sort_merge_passes : depends on sort-buffer spill thresholds +# All 25 flow through the same two mechanisms (THD::inc_status_* and +# handler::ha_statistic_increment); the 19 asserted here exercise both in both +# directions, so a broken shard write in either mechanism is caught. +# +# Values are not asserted to equal SHOW GLOBAL STATUS exactly: the metric +# aggregates 64 shards lock-free and is an approximate, non-snapshot sum by +# design. The regression property is "populated and tracking", i.e. nonzero. + +--source include/have_server_telemetry_metrics.inc + +INSTALL COMPONENT 'file://component_test_server_telemetry_metrics'; + +# All meters on so the metrics are exported/readable. +UPDATE performance_schema.setup_meters SET enabled = 'YES'; + +# Force internal tmp tables to spill to disk so created.tmp_disk_tables fires, +# and make every query "slow" so slow_queries (long_query_count) fires. +SET SESSION tmp_table_size = 1024; +SET SESSION max_heap_table_size = 16384; +SET SESSION long_query_time = 0; + +CREATE TABLE t1 (a INT PRIMARY KEY, b INT, c VARCHAR(60), KEY kb (b)); +CREATE TABLE t2 (x INT, y INT); +--disable_query_log +let $i = 1; +while ($i <= 500) +{ + eval INSERT INTO t1 VALUES ($i, $i % 17, CONCAT('padding_padding_padding_row_', $i)); + eval INSERT INTO t2 VALUES ($i % 13, $i); + inc $i; +} +--enable_query_log +FLUSH STATUS; + +--echo # Drive each affected metric family: +--disable_result_log +# Full scan on an unindexed column: select_scan + per-row read_rnd_next. +SELECT * FROM t1 WHERE c > ''; +# Self join without a usable index: select_full_join. +SELECT COUNT(*) FROM t1 a1 JOIN t1 a2 ON a1.c = a2.c; +# Primary key range scan: select_range + read_next. +SELECT * FROM t1 WHERE a BETWEEN 5 AND 400; +# ORDER BY on an unindexed column: filesort -> sort_scan / sort_rows. +SELECT * FROM t1 ORDER BY c; +# Index descending / min-max: read_prev / read_last / read_first. +SELECT * FROM t1 ORDER BY a DESC LIMIT 5; +SELECT MIN(a), MAX(a) FROM t1; +# Filesort that fetches rows by position: read_rnd. +SELECT a FROM t1 ORDER BY b LIMIT 400; +# GROUP BY on unindexed columns: created.tmp_tables (+ disk spill on the wide +# VARCHAR grouping). +SELECT b, COUNT(*) FROM t1 GROUP BY b; +SELECT c, COUNT(*) FROM t1 GROUP BY c; +# Keyed lookup: read_key. +SELECT * FROM t1 WHERE a = 42; +# Write path: write / update / delete (and external_lock on every open). +INSERT INTO t1 VALUES (9001,1,'x'),(9002,2,'y'); +UPDATE t1 SET c = 'u' WHERE a = 9001; +DELETE FROM t1 WHERE a = 9002; +--enable_result_log + +# Assert each covered metric is populated (> 0). Each was a constant 0 on the +# unfixed server. The UDF returns -1 for an unknown meter/metric, so assert +# strictly > 0 (a bare truthiness check would let both 0 and -1 through). +# +# The 19 covered metrics are checked by looping over a "meter:metric" list: +# - mysql.stats (inc_status_* producers): the Select/Sort/Created_tmp/slow +# families. +# - mysql.stats.handler (ha_statistic_increment): the read and write handler +# families. +--let $metrics = mysql.stats:select_scan mysql.stats:select_full_join mysql.stats:select_range mysql.stats:sort_scan mysql.stats:sort_rows mysql.stats:created.tmp_tables mysql.stats:created.tmp_disk_tables mysql.stats:slow_queries mysql.stats.handler:write mysql.stats.handler:update mysql.stats.handler:delete mysql.stats.handler:read_key mysql.stats.handler:read_next mysql.stats.handler:read_prev mysql.stats.handler:read_first mysql.stats.handler:read_last mysql.stats.handler:read_rnd mysql.stats.handler:read_rnd_next mysql.stats.handler:external_lock + +while ($metrics != '') +{ + # Pop the first "meter:metric" token off the front of the list. + --let $pair = `SELECT SUBSTRING_INDEX('$metrics', ' ', 1)` + --let $metrics = `SELECT LTRIM(SUBSTRING('$metrics', LENGTH('$pair') + 1))` + --let $meter = `SELECT SUBSTRING_INDEX('$pair', ':', 1)` + --let $metric = `SELECT SUBSTRING_INDEX('$pair', ':', -1)` + + --let $val = `SELECT test_report_single_metric('$meter','$metric')` + if (`SELECT $val <= 0`) + { + --die FAIL: $meter.$metric not populated (got $val) + } + --echo PASS: $meter.$metric populated +} + +# Cleanup +DROP TABLE t1, t2; +UNINSTALL COMPONENT 'file://component_test_server_telemetry_metrics'; +--let $MYSQLD_DATADIR= `select @@datadir` +--remove_file $MYSQLD_DATADIR/test_server_telemetry_metrics_component.log diff --git a/sql/handler.cc b/sql/handler.cc index 75135882a1ea..018c6636ac2e 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2720,8 +2720,14 @@ handler *handler::clone(const char *name, MEM_ROOT *mem_root) { } void handler::ha_statistic_increment( - ulonglong System_status_var::*offset) const { - if (table && table->in_use) (table->in_use->status_var.*offset)++; + ulonglong System_status_var::*offset, + std::atomic_uint64_t aggregated_stats_buffer::*shard_offset) const { + if (table && table->in_use) { + (table->in_use->status_var.*offset)++; + (global_aggregated_stats.get_shard(table->in_use->thread_id()).* + shard_offset) + .fetch_add(1, std::memory_order_relaxed); + } } THD *handler::ha_thd() const { @@ -3572,7 +3578,8 @@ int handler::ha_read_first_row(uchar *buf, uint primary_key) { int error; DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_first_count); + ha_statistic_increment(&System_status_var::ha_read_first_count, + &aggregated_stats_buffer::ha_read_first_count); /* If there is very few deleted rows in the table, find the first row by @@ -6654,6 +6661,8 @@ int DsMrr_impl::dsmrr_init(RANGE_SEQ_IF *seq_funcs, void *seq_init_param, if (is_mrr_assoc) { assert(!thd->status_var_aggregated); table->in_use->status_var.ha_multi_range_read_init_count++; + global_aggregated_stats.get_shard(table->in_use->thread_id()) + .ha_multi_range_read_init_count++; } rowids_buf_end = buf->buffer_end; @@ -8023,7 +8032,8 @@ int handler::ha_external_lock(THD *thd, int lock_type) { /* SQL HANDLER call locks/unlock while scanning (RND/INDEX). */ assert(inited == NONE || table->open_by_handler); - ha_statistic_increment(&System_status_var::ha_external_lock_count); + ha_statistic_increment(&System_status_var::ha_external_lock_count, + &aggregated_stats_buffer::ha_external_lock_count); MYSQL_TABLE_LOCK_WAIT(PSI_TABLE_EXTERNAL_LOCK, lock_type, { error = external_lock(thd, lock_type); }) diff --git a/sql/handler.h b/sql/handler.h index 841d223fb3a6..3685a7277b0b 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -91,6 +92,7 @@ class THD; class handler; class partition_info; struct System_status_var; +struct aggregated_stats_buffer; namespace dd { class Properties; @@ -6597,7 +6599,9 @@ class handler { protected: /* Service methods for use by storage engines. */ - void ha_statistic_increment(ulonglong System_status_var::*offset) const; + void ha_statistic_increment( + ulonglong System_status_var::*offset, + std::atomic_uint64_t aggregated_stats_buffer::*shard_offset) const; THD *ha_thd() const; /** diff --git a/sql/log.cc b/sql/log.cc index 0ad951f9d645..d859d06d9c2f 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1803,7 +1803,10 @@ bool log_slow_applicable(THD *thd) { (thd->get_examined_row_count() >= thd->variables.min_examined_row_limit); // The docs say slow queries must be counted even when the log is off. - if (log_this_query) thd->status_var.long_query_count++; + if (log_this_query) { + thd->status_var.long_query_count++; + global_aggregated_stats.get_shard(thd->thread_id()).long_query_count++; + } /* Do not log administrative statements unless the appropriate option is diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 0668bc7fdb3f..4da4e588cf3a 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -1609,6 +1609,8 @@ void THD::awake(THD::killed_state state_to_set) { if (state_to_set == THD::KILL_TIMEOUT) { assert(!status_var_aggregated); status_var.max_execution_time_exceeded++; + global_aggregated_stats.get_shard(thread_id()) + .max_execution_time_exceeded++; } /* Broadcast a condition to kick the target if it is waiting on it. */ @@ -2428,6 +2430,7 @@ void THD::inc_examined_row_count(ha_rows count) { void THD::inc_status_created_tmp_disk_tables() { assert(!status_var_aggregated); status_var.created_tmp_disk_tables++; + global_aggregated_stats.get_shard(thread_id()).created_tmp_disk_tables++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_created_tmp_disk_tables)(m_statement_psi, 1); #endif @@ -2436,6 +2439,7 @@ void THD::inc_status_created_tmp_disk_tables() { void THD::inc_status_created_tmp_tables() { assert(!status_var_aggregated); status_var.created_tmp_tables++; + global_aggregated_stats.get_shard(thread_id()).created_tmp_tables++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_created_tmp_tables)(m_statement_psi, 1); #endif @@ -2444,6 +2448,7 @@ void THD::inc_status_created_tmp_tables() { void THD::inc_status_select_full_join() { assert(!status_var_aggregated); status_var.select_full_join_count++; + global_aggregated_stats.get_shard(thread_id()).select_full_join_count++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_select_full_join)(m_statement_psi, 1); #endif @@ -2452,6 +2457,7 @@ void THD::inc_status_select_full_join() { void THD::inc_status_select_full_range_join() { assert(!status_var_aggregated); status_var.select_full_range_join_count++; + global_aggregated_stats.get_shard(thread_id()).select_full_range_join_count++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_select_full_range_join)(m_statement_psi, 1); #endif @@ -2460,6 +2466,7 @@ void THD::inc_status_select_full_range_join() { void THD::inc_status_select_range() { assert(!status_var_aggregated); status_var.select_range_count++; + global_aggregated_stats.get_shard(thread_id()).select_range_count++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_select_range)(m_statement_psi, 1); #endif @@ -2468,6 +2475,7 @@ void THD::inc_status_select_range() { void THD::inc_status_select_range_check() { assert(!status_var_aggregated); status_var.select_range_check_count++; + global_aggregated_stats.get_shard(thread_id()).select_range_check_count++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_select_range_check)(m_statement_psi, 1); #endif @@ -2476,6 +2484,7 @@ void THD::inc_status_select_range_check() { void THD::inc_status_select_scan() { assert(!status_var_aggregated); status_var.select_scan_count++; + global_aggregated_stats.get_shard(thread_id()).select_scan_count++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_select_scan)(m_statement_psi, 1); #endif @@ -2484,6 +2493,7 @@ void THD::inc_status_select_scan() { void THD::inc_status_sort_merge_passes() { assert(!status_var_aggregated); status_var.filesort_merge_passes++; + global_aggregated_stats.get_shard(thread_id()).filesort_merge_passes++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_sort_merge_passes)(m_statement_psi, 1); #endif @@ -2492,6 +2502,7 @@ void THD::inc_status_sort_merge_passes() { void THD::inc_status_sort_range() { assert(!status_var_aggregated); status_var.filesort_range_count++; + global_aggregated_stats.get_shard(thread_id()).filesort_range_count++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_sort_range)(m_statement_psi, 1); #endif @@ -2500,6 +2511,7 @@ void THD::inc_status_sort_range() { void THD::inc_status_sort_rows(ha_rows count) { assert(!status_var_aggregated); status_var.filesort_rows += count; + global_aggregated_stats.get_shard(thread_id()).filesort_rows += count; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_sort_rows) (m_statement_psi, static_cast(count)); @@ -2509,6 +2521,7 @@ void THD::inc_status_sort_rows(ha_rows count) { void THD::inc_status_sort_scan() { assert(!status_var_aggregated); status_var.filesort_scan_count++; + global_aggregated_stats.get_shard(thread_id()).filesort_scan_count++; #ifdef HAVE_PSI_STATEMENT_INTERFACE PSI_STATEMENT_CALL(inc_statement_sort_scan)(m_statement_psi, 1); #endif diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index b71606eac8b1..8562976330fe 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -42,6 +42,7 @@ #include "mysql/psi/mysql_file.h" #include "mysql/psi/mysql_memory.h" #include "nulls.h" +#include "sql/aggregated_stats_buffer.h" #include "sql/derror.h" #include "sql/field.h" #include "sql/sql_class.h" @@ -792,7 +793,8 @@ int ha_archive::write_row(uchar *buf) { if (share->crashed) return HA_ERR_CRASHED_ON_USAGE; - ha_statistic_increment(&System_status_var::ha_write_count); + ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); mysql_mutex_lock(&share->mutex); if (!share->archive_write_open && share->init_archive_writer()) { @@ -1117,7 +1119,8 @@ int ha_archive::rnd_next(uchar *buf) { } scan_rows--; - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); current_position = aztell(&archive); rc = get_row(&archive, buf); @@ -1145,7 +1148,8 @@ void ha_archive::position(const uchar *) { int ha_archive::rnd_pos(uchar *buf, uchar *pos) { int rc; DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); current_position = (my_off_t)my_get_ptr(pos, ref_length); if (azseek(&archive, current_position, SEEK_SET) == (my_off_t)(-1L)) { rc = HA_ERR_CRASHED_ON_USAGE; diff --git a/storage/csv/ha_tina.cc b/storage/csv/ha_tina.cc index 62c8fc257ce4..7b067a77fc43 100644 --- a/storage/csv/ha_tina.cc +++ b/storage/csv/ha_tina.cc @@ -64,6 +64,7 @@ #include "mysql/plugin.h" #include "mysql/psi/mysql_memory.h" #include "nulls.h" +#include "sql/aggregated_stats_buffer.h" #include "sql/derror.h" #include "sql/field.h" #include "sql/sql_class.h" @@ -940,7 +941,8 @@ int ha_tina::write_row(uchar *buf) { if (share->crashed) return HA_ERR_CRASHED_ON_USAGE; - ha_statistic_increment(&System_status_var::ha_write_count); + ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); size = encode_quote(buf); @@ -996,7 +998,8 @@ int ha_tina::update_row(const uchar *, uchar *new_data) { int rc = -1; DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_update_count); + ha_statistic_increment(&System_status_var::ha_update_count, + &aggregated_stats_buffer::ha_update_count); size = encode_quote(new_data); @@ -1037,7 +1040,8 @@ int ha_tina::update_row(const uchar *, uchar *new_data) { */ int ha_tina::delete_row(const uchar *) { DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_delete_count); + ha_statistic_increment(&System_status_var::ha_delete_count, + &aggregated_stats_buffer::ha_delete_count); if (chain_append()) return -1; @@ -1145,7 +1149,8 @@ int ha_tina::rnd_next(uchar *buf) { goto end; } - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); current_position = next_position; @@ -1185,7 +1190,8 @@ void ha_tina::position(const uchar *) { int ha_tina::rnd_pos(uchar *buf, uchar *pos) { int rc; DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_rnd_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); current_position = my_get_ptr(pos, ref_length); rc = find_current_row(buf); return rc; diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc index d55a8420a2d8..febb3b0c58c7 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -398,6 +398,7 @@ #include "mysql/psi/mysql_mutex.h" #include "mysql/strings/m_ctype.h" #include "mysql/strings/my_strtoll10.h" +#include "sql/aggregated_stats_buffer.h" #include "sql/current_thd.h" #include "sql/key.h" // key_copy #include "sql/mysqld.h" // my_localhost @@ -1730,7 +1731,8 @@ int ha_federated::write_row(uchar *) { values_string.length(0); insert_field_value_string.length(0); - ha_statistic_increment(&System_status_var::ha_write_count); + ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); /* start both our field and field values strings @@ -2274,7 +2276,8 @@ int ha_federated::index_read_idx_with_result_set(uchar *buf, uint index, *result = nullptr; // In case of errors index_string.length(0); sql_query.length(0); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); sql_query.append(share->select_query); @@ -2378,7 +2381,8 @@ int ha_federated::read_range_next() { int ha_federated::index_next(uchar *buf) { int retval; DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); retval = read_next(buf, stored_result); return retval; } @@ -2568,7 +2572,8 @@ int ha_federated::rnd_pos(uchar *buf, uchar *pos) { int ret_val; DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_rnd_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); /* Get stored result set. */ memcpy(&result, pos, sizeof(MYSQL_RES *)); diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc index 5f92986d01c1..d8e8d352289a 100644 --- a/storage/heap/ha_heap.cc +++ b/storage/heap/ha_heap.cc @@ -33,6 +33,7 @@ #include "my_pointer_arithmetic.h" #include "my_psi_config.h" #include "mysql/plugin.h" +#include "sql/aggregated_stats_buffer.h" #include "sql/current_thd.h" #include "sql/field.h" #include "sql/sql_base.h" // enum_tdc_remove_table_type @@ -204,7 +205,8 @@ void ha_heap::update_key_stats() { int ha_heap::write_row(uchar *buf) { int res; - ha_statistic_increment(&System_status_var::ha_write_count); + ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); if (table->next_number_field && buf == table->record[0]) { if ((res = update_auto_increment())) return res; } @@ -223,7 +225,8 @@ int ha_heap::write_row(uchar *buf) { int ha_heap::update_row(const uchar *old_data, uchar *new_data) { int res; - ha_statistic_increment(&System_status_var::ha_update_count); + ha_statistic_increment(&System_status_var::ha_update_count, + &aggregated_stats_buffer::ha_update_count); res = heap_update(file, old_data, new_data); if (!res && ++records_changed * HEAP_STATS_UPDATE_THRESHOLD > file->s->records) { @@ -238,7 +241,8 @@ int ha_heap::update_row(const uchar *old_data, uchar *new_data) { int ha_heap::delete_row(const uchar *buf) { int res; - ha_statistic_increment(&System_status_var::ha_delete_count); + ha_statistic_increment(&System_status_var::ha_delete_count, + &aggregated_stats_buffer::ha_delete_count); res = heap_delete(file, buf); if (!res && table->s->tmp_table == NO_TMP_TABLE && ++records_changed * HEAP_STATS_UPDATE_THRESHOLD > file->s->records) { @@ -255,7 +259,8 @@ int ha_heap::index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); int error = heap_rkey(file, buf, active_index, key, keypart_map, find_flag); return error; @@ -264,7 +269,8 @@ int ha_heap::index_read_map(uchar *buf, const uchar *key, int ha_heap::index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); int error = heap_rkey(file, buf, active_index, key, keypart_map, HA_READ_PREFIX_LAST); return error; @@ -273,35 +279,40 @@ int ha_heap::index_read_last_map(uchar *buf, const uchar *key, int ha_heap::index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) { - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); int error = heap_rkey(file, buf, index, key, keypart_map, find_flag); return error; } int ha_heap::index_next(uchar *buf) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); int error = heap_rnext(file, buf); return error; } int ha_heap::index_prev(uchar *buf) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_prev_count); + ha_statistic_increment(&System_status_var::ha_read_prev_count, + &aggregated_stats_buffer::ha_read_prev_count); int error = heap_rprev(file, buf); return error; } int ha_heap::index_first(uchar *buf) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_first_count); + ha_statistic_increment(&System_status_var::ha_read_first_count, + &aggregated_stats_buffer::ha_read_first_count); int error = heap_rfirst(file, buf, active_index); return error; } int ha_heap::index_last(uchar *buf) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_last_count); + ha_statistic_increment(&System_status_var::ha_read_last_count, + &aggregated_stats_buffer::ha_read_last_count); int error = heap_rlast(file, buf, active_index); return error; } @@ -309,7 +320,8 @@ int ha_heap::index_last(uchar *buf) { int ha_heap::rnd_init(bool scan) { return scan ? heap_scan_init(file) : 0; } int ha_heap::rnd_next(uchar *buf) { - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); int error = heap_scan(file, buf); return error; @@ -318,7 +330,8 @@ int ha_heap::rnd_next(uchar *buf) { int ha_heap::rnd_pos(uchar *buf, uchar *pos) { int error; HP_HEAP_POSITION heap_position; - ha_statistic_increment(&System_status_var::ha_read_rnd_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); memcpy(&heap_position, pos, sizeof(HP_HEAP_POSITION)); error = heap_rrnd(file, buf, &heap_position); return error; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 69b19ddc4457..9f942fadb9d9 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -185,6 +185,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include "dict0upgrade.h" #include "os0thread-create.h" #include "os0thread.h" +#include "sql/aggregated_stats_buffer.h" #include "sql/item.h" #include "sql_base.h" #include "srv0tmp.h" @@ -9256,7 +9257,8 @@ int ha_innobase::write_row(uchar *record) /*!< in: a row in MySQL format */ DBUG_TRACE; /* Increase the write count of handler */ - ha_statistic_increment(&System_status_var::ha_write_count); + ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); if (m_prebuilt->table->is_intrinsic()) { return intrinsic_table_write_row(record); @@ -10039,7 +10041,8 @@ int ha_innobase::update_row(const uchar *old_row, uchar *new_row) { } } - ha_statistic_increment(&System_status_var::ha_update_count); + ha_statistic_increment(&System_status_var::ha_update_count, + &aggregated_stats_buffer::ha_update_count); upd_t *uvect; @@ -10183,7 +10186,8 @@ int ha_innobase::delete_row( ++trx->will_lock; } - ha_statistic_increment(&System_status_var::ha_delete_count); + ha_statistic_increment(&System_status_var::ha_delete_count, + &aggregated_stats_buffer::ha_delete_count); if (!m_prebuilt->upd_node) { row_get_prebuilt_update_vector(m_prebuilt); @@ -10442,7 +10446,8 @@ int ha_innobase::index_read( ut_a(m_prebuilt->trx == thd_to_trx(m_user_thd)); ut_ad(key_len != 0 || find_flag != HA_READ_KEY_EXACT); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); dict_index_t *index = m_prebuilt->index; @@ -10858,7 +10863,8 @@ int ha_innobase::general_fetch( int ha_innobase::index_next(uchar *buf) /*!< in/out: buffer for next row in MySQL format */ { - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); return (general_fetch(buf, ROW_SEL_NEXT, 0)); } @@ -10870,7 +10876,8 @@ int ha_innobase::index_next_same(uchar *buf, /*!< in/out: buffer for the row */ const uchar *, /*!< in: key value */ uint) /*!< in: key value length */ { - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); return (general_fetch(buf, ROW_SEL_NEXT, m_last_match_mode)); } @@ -10882,7 +10889,8 @@ int ha_innobase::index_next_same(uchar *buf, /*!< in/out: buffer for the row */ int ha_innobase::index_prev( uchar *buf) /*!< in/out: buffer for previous row in MySQL format */ { - ha_statistic_increment(&System_status_var::ha_read_prev_count); + ha_statistic_increment(&System_status_var::ha_read_prev_count, + &aggregated_stats_buffer::ha_read_prev_count); return (general_fetch(buf, ROW_SEL_PREV, 0)); } @@ -10895,7 +10903,8 @@ int ha_innobase::index_first(uchar *buf) /*!< in/out: buffer for the row */ { DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_first_count); + ha_statistic_increment(&System_status_var::ha_read_first_count, + &aggregated_stats_buffer::ha_read_first_count); int error = index_read(buf, nullptr, 0, HA_READ_AFTER_KEY); @@ -10916,7 +10925,8 @@ int ha_innobase::index_last(uchar *buf) /*!< in/out: buffer for the row */ { DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_last_count); + ha_statistic_increment(&System_status_var::ha_read_last_count, + &aggregated_stats_buffer::ha_read_last_count); int error = index_read(buf, nullptr, 0, HA_READ_BEFORE_KEY); @@ -11083,7 +11093,8 @@ int ha_innobase::rnd_next(uchar *buf) /*!< in/out: returns the row in this if (m_user_thd->transaction_rollback_request) return HA_ERR_GENERIC; - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); if (m_start_of_scan) { error = index_first(buf); @@ -11113,7 +11124,8 @@ int ha_innobase::rnd_pos( DBUG_TRACE; DBUG_DUMP("key", pos, ref_length); - ha_statistic_increment(&System_status_var::ha_read_rnd_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); ut_a(m_prebuilt->trx == thd_to_trx(ha_thd())); diff --git a/storage/innobase/handler/ha_innopart.cc b/storage/innobase/handler/ha_innopart.cc index 37e15cd3649a..a8ecbe9616cb 100644 --- a/storage/innobase/handler/ha_innopart.cc +++ b/storage/innobase/handler/ha_innopart.cc @@ -31,6 +31,7 @@ Code for native partitioning in InnoDB. Created Nov 22, 2013 Mattias Jonsson */ /* Include necessary SQL headers */ +#include #include #include #include @@ -2146,7 +2147,8 @@ int ha_innopart::rnd_next_in_part(uint part_id, uchar *buf) { } m_start_of_scan = false; } else { - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); error = ha_innobase::general_fetch(buf, ROW_SEL_NEXT, 0); } @@ -2168,7 +2170,8 @@ int ha_innopart::rnd_pos(uchar *buf, uchar *pos) { static_assert(PARTITION_BYTES_IN_POS == 2); DBUG_DUMP("pos", pos, ref_length); - ha_statistic_increment(&System_status_var::ha_read_rnd_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); ut_ad(m_prebuilt->trx == thd_to_trx(ha_thd())); diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 2d96e849f50a..59b5609447b9 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -44,6 +44,7 @@ #include "mysql/strings/int2str.h" #include "mysql/strings/m_ctype.h" #include "nulls.h" +#include "sql/aggregated_stats_buffer.h" #include "sql/current_thd.h" #include "sql/derror.h" #include "sql/field.h" @@ -817,7 +818,8 @@ int ha_myisam::close(void) { } int ha_myisam::write_row(uchar *buf) { - ha_statistic_increment(&System_status_var::ha_write_count); + ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); /* If we have an auto_increment column and we are writing a changed row @@ -1478,12 +1480,14 @@ bool ha_myisam::is_crashed() const { } int ha_myisam::update_row(const uchar *old_data, uchar *new_data) { - ha_statistic_increment(&System_status_var::ha_update_count); + ha_statistic_increment(&System_status_var::ha_update_count, + &aggregated_stats_buffer::ha_update_count); return mi_update(file, old_data, new_data); } int ha_myisam::delete_row(const uchar *buf) { - ha_statistic_increment(&System_status_var::ha_delete_count); + ha_statistic_increment(&System_status_var::ha_delete_count, + &aggregated_stats_buffer::ha_delete_count); return mi_delete(file, buf); } @@ -1522,7 +1526,8 @@ int ha_myisam::index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); if (file->s->keyinfo[active_index].flag & HA_FULLTEXT) { set_my_errno(HA_ERR_KEY_NOT_FOUND); return HA_ERR_KEY_NOT_FOUND; @@ -1536,7 +1541,8 @@ int ha_myisam::index_read_idx_map(uchar *buf, uint index, const uchar *key, enum ha_rkey_function find_flag) { assert(pushed_idx_cond == nullptr); assert(pushed_idx_cond_keyno == MAX_KEY); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); if (file->s->keyinfo[active_index].flag & HA_FULLTEXT) { set_my_errno(HA_ERR_KEY_NOT_FOUND); return HA_ERR_KEY_NOT_FOUND; @@ -1549,7 +1555,8 @@ int ha_myisam::index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map) { DBUG_TRACE; assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); if (file->s->keyinfo[active_index].flag & HA_FULLTEXT) { set_my_errno(HA_ERR_KEY_NOT_FOUND); return HA_ERR_KEY_NOT_FOUND; @@ -1561,28 +1568,32 @@ int ha_myisam::index_read_last_map(uchar *buf, const uchar *key, int ha_myisam::index_next(uchar *buf) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); int error = mi_rnext(file, buf, active_index); return error; } int ha_myisam::index_prev(uchar *buf) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_prev_count); + ha_statistic_increment(&System_status_var::ha_read_prev_count, + &aggregated_stats_buffer::ha_read_prev_count); int error = mi_rprev(file, buf, active_index); return error; } int ha_myisam::index_first(uchar *buf) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_first_count); + ha_statistic_increment(&System_status_var::ha_read_first_count, + &aggregated_stats_buffer::ha_read_first_count); int error = mi_rfirst(file, buf, active_index); return error; } int ha_myisam::index_last(uchar *buf) { assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_last_count); + ha_statistic_increment(&System_status_var::ha_read_last_count, + &aggregated_stats_buffer::ha_read_last_count); int error = mi_rlast(file, buf, active_index); return error; } @@ -1591,7 +1602,8 @@ int ha_myisam::index_next_same(uchar *buf, const uchar *key [[maybe_unused]], uint length [[maybe_unused]]) { int error; assert(inited == INDEX); - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); do { error = mi_rnext_same(file, buf); } while (error == HA_ERR_RECORD_DELETED); @@ -1604,13 +1616,15 @@ int ha_myisam::rnd_init(bool scan) { } int ha_myisam::rnd_next(uchar *buf) { - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); int error = mi_scan(file, buf); return error; } int ha_myisam::rnd_pos(uchar *buf, uchar *pos) { - ha_statistic_increment(&System_status_var::ha_read_rnd_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); int error = mi_rrnd(file, buf, my_get_ptr(pos, ref_length)); return error; } @@ -1892,7 +1906,8 @@ int ha_myisam::ft_read(uchar *buf) { if (!ft_handler) return -1; - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); error = ft_handler->please->read_next(ft_handler, (char *)buf); diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 7cd10e1f40fe..6023cfb7dade 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -106,6 +106,7 @@ #include "my_psi_config.h" #include "mysql/strings/m_ctype.h" #include "nulls.h" +#include "sql/aggregated_stats_buffer.h" #include "sql/current_thd.h" #include "sql/debug_sync.h" #include "sql/mysqld.h" @@ -982,7 +983,8 @@ int ha_myisammrg::close(void) { int ha_myisammrg::write_row(uchar *buf) { DBUG_TRACE; assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_write_count); + ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); if (file->merge_insert_method == MERGE_INSERT_DISABLED || !file->tables) return HA_ERR_TABLE_READONLY; @@ -997,13 +999,15 @@ int ha_myisammrg::write_row(uchar *buf) { int ha_myisammrg::update_row(const uchar *old_data, uchar *new_data) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_update_count); + ha_statistic_increment(&System_status_var::ha_update_count, + &aggregated_stats_buffer::ha_update_count); return myrg_update(file, old_data, new_data); } int ha_myisammrg::delete_row(const uchar *buf) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_delete_count); + ha_statistic_increment(&System_status_var::ha_delete_count, + &aggregated_stats_buffer::ha_delete_count); return myrg_delete(file, buf); } @@ -1011,7 +1015,8 @@ int ha_myisammrg::index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); int error = myrg_rkey(file, buf, active_index, key, keypart_map, find_flag); return error; } @@ -1020,7 +1025,8 @@ int ha_myisammrg::index_read_idx_map(uchar *buf, uint index, const uchar *key, key_part_map keypart_map, enum ha_rkey_function find_flag) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); int error = myrg_rkey(file, buf, index, key, keypart_map, find_flag); return error; } @@ -1028,7 +1034,8 @@ int ha_myisammrg::index_read_idx_map(uchar *buf, uint index, const uchar *key, int ha_myisammrg::index_read_last_map(uchar *buf, const uchar *key, key_part_map keypart_map) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); int error = myrg_rkey(file, buf, active_index, key, keypart_map, HA_READ_PREFIX_LAST); return error; @@ -1036,28 +1043,32 @@ int ha_myisammrg::index_read_last_map(uchar *buf, const uchar *key, int ha_myisammrg::index_next(uchar *buf) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); int error = myrg_rnext(file, buf, active_index); return error; } int ha_myisammrg::index_prev(uchar *buf) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_prev_count); + ha_statistic_increment(&System_status_var::ha_read_prev_count, + &aggregated_stats_buffer::ha_read_prev_count); int error = myrg_rprev(file, buf, active_index); return error; } int ha_myisammrg::index_first(uchar *buf) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_first_count); + ha_statistic_increment(&System_status_var::ha_read_first_count, + &aggregated_stats_buffer::ha_read_first_count); int error = myrg_rfirst(file, buf, active_index); return error; } int ha_myisammrg::index_last(uchar *buf) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_last_count); + ha_statistic_increment(&System_status_var::ha_read_last_count, + &aggregated_stats_buffer::ha_read_last_count); int error = myrg_rlast(file, buf, active_index); return error; } @@ -1066,7 +1077,8 @@ int ha_myisammrg::index_next_same(uchar *buf, const uchar *key [[maybe_unused]], uint length [[maybe_unused]]) { int error; assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); do { error = myrg_rnext_same(file, buf); } while (error == HA_ERR_RECORD_DELETED); @@ -1080,14 +1092,16 @@ int ha_myisammrg::rnd_init(bool) { int ha_myisammrg::rnd_next(uchar *buf) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); int error = myrg_rrnd(file, buf, HA_OFFSET_ERROR); return error; } int ha_myisammrg::rnd_pos(uchar *buf, uchar *pos) { assert(this->file->children_attached); - ha_statistic_increment(&System_status_var::ha_read_rnd_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); int error = myrg_rrnd(file, buf, my_get_ptr(pos, ref_length)); return error; } diff --git a/storage/ndb/plugin/ha_ndbcluster.cc b/storage/ndb/plugin/ha_ndbcluster.cc index 95176f54f1f6..7b0762dac366 100644 --- a/storage/ndb/plugin/ha_ndbcluster.cc +++ b/storage/ndb/plugin/ha_ndbcluster.cc @@ -57,6 +57,7 @@ #ifndef NDEBUG #include "sql/sql_test.h" // print_where #endif +#include "sql/aggregated_stats_buffer.h" #include "sql/strfunc.h" #include "storage/ndb/include/ndb_global.h" #include "storage/ndb/include/ndb_version.h" @@ -4897,7 +4898,8 @@ int ha_ndbcluster::ndb_write_row(uchar *record, bool primary_key_update, } assert(trans); - ha_statistic_increment(&System_status_var::ha_write_count); + ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); /* Setup OperationOptions @@ -5545,7 +5547,8 @@ int ha_ndbcluster::ndb_update_row(const uchar *old_data, uchar *new_data, if (peek_res != HA_ERR_KEY_NOT_FOUND) return peek_res; } - ha_statistic_increment(&System_status_var::ha_update_count); + ha_statistic_increment(&System_status_var::ha_update_count, + &aggregated_stats_buffer::ha_update_count); bool skip_partition_for_unique_index = false; if (m_use_partition_pruning) { @@ -5877,7 +5880,8 @@ int ha_ndbcluster::ndb_delete_row(const uchar *record, NdbTransaction *trans = m_thd_ndb->trans; assert(trans); - ha_statistic_increment(&System_status_var::ha_delete_count); + ha_statistic_increment(&System_status_var::ha_delete_count, + &aggregated_stats_buffer::ha_delete_count); bool skip_partition_for_unique_index = false; if (m_use_partition_pruning) { @@ -6319,14 +6323,16 @@ int ha_ndbcluster::index_read(uchar *buf, const uchar *key, uint key_len, int ha_ndbcluster::index_next(uchar *buf) { DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); const int error = next_result(buf); return error; } int ha_ndbcluster::index_prev(uchar *buf) { DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_prev_count); + ha_statistic_increment(&System_status_var::ha_read_prev_count, + &aggregated_stats_buffer::ha_read_prev_count); const int error = next_result(buf); return error; } @@ -6335,7 +6341,8 @@ int ha_ndbcluster::index_first(uchar *buf) { DBUG_TRACE; if (!m_index[active_index].index) return fail_index_offline(table, active_index); - ha_statistic_increment(&System_status_var::ha_read_first_count); + ha_statistic_increment(&System_status_var::ha_read_first_count, + &aggregated_stats_buffer::ha_read_first_count); // Start the ordered index scan and fetch the first row // Only HA_READ_ORDER indexes get called by index_first @@ -6348,7 +6355,8 @@ int ha_ndbcluster::index_last(uchar *buf) { DBUG_TRACE; if (!m_index[active_index].index) return fail_index_offline(table, active_index); - ha_statistic_increment(&System_status_var::ha_read_last_count); + ha_statistic_increment(&System_status_var::ha_read_last_count, + &aggregated_stats_buffer::ha_read_last_count); const int error = ordered_index_scan(nullptr, nullptr, m_sorted, true, buf, nullptr); return error; @@ -6358,7 +6366,8 @@ int ha_ndbcluster::index_next_same(uchar *buf, const uchar *key [[maybe_unused]], uint length [[maybe_unused]]) { DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); const int error = next_result(buf); return error; } @@ -6571,7 +6580,8 @@ int ha_ndbcluster::rnd_end() { int ha_ndbcluster::rnd_next(uchar *buf) { DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); int error; if (m_active_cursor || m_active_query) @@ -6590,7 +6600,8 @@ int ha_ndbcluster::rnd_next(uchar *buf) { int ha_ndbcluster::rnd_pos(uchar *buf, uchar *pos) { DBUG_TRACE; - ha_statistic_increment(&System_status_var::ha_read_rnd_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); // The primary key for the record is stored in pos // Perform a pk_read using primary key "index" { @@ -13580,7 +13591,9 @@ int ha_ndbcluster::multi_range_read_init(RANGE_SEQ_IF *seq_funcs, m_range_res = mrr_funcs.next(mrr_iter, &mrr_cur_range); const bool mrr_need_range_assoc = !(mode & HA_MRR_NO_ASSOCIATION); if (mrr_need_range_assoc) { - ha_statistic_increment(&System_status_var::ha_multi_range_read_init_count); + ha_statistic_increment( + &System_status_var::ha_multi_range_read_init_count, + &aggregated_stats_buffer::ha_multi_range_read_init_count); } /* diff --git a/storage/perfschema/ha_perfschema.cc b/storage/perfschema/ha_perfschema.cc index a084e1acfb68..38bb5f426361 100644 --- a/storage/perfschema/ha_perfschema.cc +++ b/storage/perfschema/ha_perfschema.cc @@ -44,6 +44,7 @@ #include "mysql/strings/int2str.h" #include "mysqld_error.h" #include "nulls.h" +#include "sql/aggregated_stats_buffer.h" #include "sql/hostname_cache.h" #include "sql/mysqld.h" #include "sql/sql_class.h" @@ -1681,7 +1682,8 @@ int ha_perfschema::write_row(uchar *buf) { if (m_table == nullptr) { m_table = m_table_share->m_open_table(m_table_share); } - ha_statistic_increment(&System_status_var::ha_write_count); + ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); result = m_table_share->write_row(m_table, table, buf, table->field); return result; } @@ -1707,7 +1709,8 @@ int ha_perfschema::update_row(const uchar *old_data, uchar *new_data) { } assert(m_table); - ha_statistic_increment(&System_status_var::ha_update_count); + ha_statistic_increment(&System_status_var::ha_update_count, + &aggregated_stats_buffer::ha_update_count); const int result = m_table->update_row(table, old_data, new_data, table->field); return result; @@ -1720,7 +1723,8 @@ int ha_perfschema::delete_row(const uchar *buf) { } assert(m_table); - ha_statistic_increment(&System_status_var::ha_delete_count); + ha_statistic_increment(&System_status_var::ha_delete_count, + &aggregated_stats_buffer::ha_delete_count); const int result = m_table->delete_row(table, buf, table->field); return result; } @@ -1762,7 +1766,8 @@ int ha_perfschema::rnd_next(uchar *buf) { } assert(m_table); - ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); int result = m_table->rnd_next(); if (result == 0) { @@ -1788,7 +1793,8 @@ int ha_perfschema::rnd_pos(uchar *buf, uchar *pos) { } assert(m_table); - ha_statistic_increment(&System_status_var::ha_read_rnd_count); + ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); int result = m_table->rnd_pos(pos); if (result == 0) { result = m_table->read_row(table, buf, table->field); @@ -1990,7 +1996,8 @@ int ha_perfschema::index_read(uchar *buf, const uchar *key, uint key_len, } assert(m_table); - ha_statistic_increment(&System_status_var::ha_read_key_count); + ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); assert(table != nullptr); assert(table->s != nullptr); @@ -2016,7 +2023,8 @@ int ha_perfschema::index_next(uchar *buf) { return HA_ERR_END_OF_FILE; } - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); assert(m_table); @@ -2037,7 +2045,8 @@ int ha_perfschema::index_next_same(uchar *buf, const uchar *key, uint keylen) { return HA_ERR_END_OF_FILE; } - ha_statistic_increment(&System_status_var::ha_read_next_count); + ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); assert(m_table); diff --git a/storage/temptable/src/handler.cc b/storage/temptable/src/handler.cc index 303d0b71a75a..24afbbbf248d 100644 --- a/storage/temptable/src/handler.cc +++ b/storage/temptable/src/handler.cc @@ -32,6 +32,7 @@ TempTable public handler API implementation. */ #include "my_dbug.h" #include "mysql/components/services/log_builtins.h" #include "mysql/plugin.h" +#include "sql/aggregated_stats_buffer.h" #include "sql/mysqld.h" #include "sql/sql_class.h" #include "sql/sql_thd_internal_api.h" @@ -306,7 +307,9 @@ int Handler::rnd_next(uchar *mysql_row) { opened_table_validate(); - handler::ha_statistic_increment(&System_status_var::ha_read_rnd_next_count); + handler::ha_statistic_increment( + &System_status_var::ha_read_rnd_next_count, + &aggregated_stats_buffer::ha_read_rnd_next_count); const Storage &rows = m_opened_table->rows(); @@ -361,7 +364,8 @@ int Handler::rnd_pos(uchar *mysql_row, uchar *position) { opened_table_validate(); - handler::ha_statistic_increment(&System_status_var::ha_read_rnd_count); + handler::ha_statistic_increment(&System_status_var::ha_read_rnd_count, + &aggregated_stats_buffer::ha_read_rnd_count); Storage::Element *row; memcpy(&row, position, sizeof(row)); @@ -419,7 +423,8 @@ int Handler::index_read(uchar *mysql_row, const uchar *mysql_search_cells, opened_table_validate(); - handler::ha_statistic_increment(&System_status_var::ha_read_key_count); + handler::ha_statistic_increment(&System_status_var::ha_read_key_count, + &aggregated_stats_buffer::ha_read_key_count); assert(handler::active_index < m_opened_table->number_of_indexes()); @@ -528,7 +533,8 @@ int Handler::index_next(uchar *mysql_row) { opened_table_validate(); - handler::ha_statistic_increment(&System_status_var::ha_read_next_count); + handler::ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); const Result ret = index_next_conditional(mysql_row, NextCondition::NO); @@ -540,7 +546,8 @@ int Handler::index_next_same(uchar *mysql_row, const uchar *, uint) { opened_table_validate(); - handler::ha_statistic_increment(&System_status_var::ha_read_next_count); + handler::ha_statistic_increment(&System_status_var::ha_read_next_count, + &aggregated_stats_buffer::ha_read_next_count); const Result ret = index_next_conditional(mysql_row, NextCondition::ONLY_IF_SAME); @@ -638,7 +645,8 @@ int Handler::index_prev(uchar *mysql_row) { assert(m_index_cursor.is_positioned()); - handler::ha_statistic_increment(&System_status_var::ha_read_prev_count); + handler::ha_statistic_increment(&System_status_var::ha_read_prev_count, + &aggregated_stats_buffer::ha_read_prev_count); Result ret; @@ -704,7 +712,8 @@ int Handler::write_row(uchar *mysql_row) { opened_table_validate(); - handler::ha_statistic_increment(&System_status_var::ha_write_count); + handler::ha_statistic_increment(&System_status_var::ha_write_count, + &aggregated_stats_buffer::ha_write_count); const Result ret = m_opened_table->insert(mysql_row); @@ -716,7 +725,8 @@ int Handler::update_row(const uchar *mysql_row_old, uchar *mysql_row_new) { opened_table_validate(); - handler::ha_statistic_increment(&System_status_var::ha_update_count); + handler::ha_statistic_increment(&System_status_var::ha_update_count, + &aggregated_stats_buffer::ha_update_count); Storage::Element *target_row; @@ -741,7 +751,8 @@ int Handler::delete_row(const uchar *mysql_row) { assert(m_rnd_iterator_is_positioned); - ha_statistic_increment(&System_status_var::ha_delete_count); + ha_statistic_increment(&System_status_var::ha_delete_count, + &aggregated_stats_buffer::ha_delete_count); const Storage::Iterator victim_position = m_rnd_iterator;