Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
10.6, 10.11, 11.4
Description
In MDEV-31558 we wrongly thought that there would be minimal overhead for accessing a thread-local variable:
extern thread_local ha_handler_stats *mariadb_stats; |
It turns out that in C++11, each access to an extern thread_local variable requires conditionally invoking an initialization function. In fact, we do have a custom initializer of this very variable, so that call is actually unavoidable:
thread_local ha_handler_stats mariadb_dummy_stats;
|
thread_local ha_handler_stats *mariadb_stats= &mariadb_dummy_stats;
|
It turns out that already had a better declared thread local variable that the mariadb_stats would point to when it is not pointing to the dummy object:
static thread_local THD *THR_THD; |
|
MYSQL_THD _current_thd() { return THR_THD; } |
We can access THD::handler_stats directly (well, via an accessor function, because the definition of THD is hidden from the InnoDB storage engine).
Attachments
Issue Links
- is caused by
-
MDEV-31558 Add InnoDB engine information to the slow query log
-
- Closed
-
- relates to
-
MDEV-34297 get_rnd_value() of ib_counter_t is unnecessarily complex
-
- Closed
-
I see that there also is handler::handler_stats that would be a null pointer or apparently point to THD::handler_stats. If there is no alternative to retaining mariadb_stats, then we could try the following to simulate the C11 _Thread_local:
There are a few failing tests (missing r_engine_stats sections in ANALYZE FORMAT=JSON output) for the current implementation:
10.6-MDEV-34296 5039dee49b7da592a71227e91411254013c3d5b4
Failing test(s): main.analyze_engine_stats2 main.analyze_engine_stats main.rowid_filter_innodb