- Home
- MySQL & MariaDB
- Relational Databases
- How to Find Values of Session Variables With gdb
How to Find Values of Session Variables With gdb
Feed: Planet MySQL
;
Author: Valeriy Kravchuk
;
Usually I make notes while working on customer issues, reading the Slack channels or even scrolling across my Facebook news feed. Some of them are of “ToDo” kind, and this week while watching how my colleagues work on a very complicated crash/bug I noted that one of the problems they were discussing was how to find out from the core dump if the session behind the crashing thread had mrr=ON in the optimizer_switch.
I had already written more than once how to check MySQL threads one by one in gdb, depending on version and your real goal. For this post I decided to concentrate on checking the values of session variables and, specifically, individual switchable optimizations. This is actually easy, comparing to checking MySQL plugin variables…
I’ve used Percona 5.7.x and executed set session optimizer_switch=’mrr=off’; in one of sessions. I checked threads one by one in gdb until I find the one I need, where thd variable is defined in some frame:
…
(gdb) thread 3
[Switching to thread 3 (Thread 0x7f7171fbc700 (LWP 2186))]#0 0x00007f71a4be3383 in poll () from /lib64/libc.so.6
(gdb) p do_command::thd->m_thread_id
$1 = 7
Local session variables are kept in the filed call variables in the THD structure:
(gdb) p do_command::thd->variables
$2 = {dynamic_variables_version = 61,
dynamic_variables_ptr = 0x7f717359c820 “