From 8d210fc2aa7ca08450055e2db3249b0f18e61bdb Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Wed, 9 Aug 2023 15:47:06 +0300 Subject: [PATCH] MDEV-31877: ASAN errors in Exec_time_tracker::get_cycles with innodb slow log verbosity Remove redundant delete_explain_query() calls in sp_instr_set::exec_core(), sp_instr_set_row_field::exec_core(), sp_instr_set_row_field_by_name::exec_core(). These calls are made before the SP instruction's tables are "closed" by close_thread_tables() call. When we call close_thread_tables() after that, we no longer can collect engine's counter variables, as they use the data structures that are located in the Explain Data Structures. Also, these delete_explain_query() calls are redundant, as sp_lex_keeper::reset_lex_and_exec_core() has another delete_explain_query() call, which is located in the right location after the close_thread_tables() call. --- mysql-test/main/sp.result | 12 ++++++++++++ mysql-test/main/sp.test | 16 ++++++++++++++++ sql/sp_head.cc | 3 --- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/mysql-test/main/sp.result b/mysql-test/main/sp.result index 88df800b0e0..74734a9b7ed 100644 --- a/mysql-test/main/sp.result +++ b/mysql-test/main/sp.result @@ -8972,3 +8972,15 @@ select @counter; 5 drop function f1; drop table t1,t2; +# +# MDEV-31877: ASAN errors in Exec_time_tracker::get_cycles with innodb slow log verbosity +# +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,2); +SET @tmp=@@log_slow_verbosity; +SET SESSION log_slow_verbosity= 'innodb'; +BEGIN NOT ATOMIC DECLARE r ROW TYPE OF t1 DEFAULT (SELECT * FROM t1); SELECT r.a; END $ +r.a +1 +SET SESSION log_slow_verbosity= @tmp; +DROP TABLE t1; diff --git a/mysql-test/main/sp.test b/mysql-test/main/sp.test index e8da0bd2209..6950fbddd65 100644 --- a/mysql-test/main/sp.test +++ b/mysql-test/main/sp.test @@ -10573,3 +10573,19 @@ select f1(col1) from t2 order by col2 desc limit 5; select @counter; drop function f1; drop table t1,t2; + +--echo # +--echo # MDEV-31877: ASAN errors in Exec_time_tracker::get_cycles with innodb slow log verbosity +--echo # +CREATE TABLE t1 (a INT, b INT); +INSERT INTO t1 VALUES (1,2); +SET @tmp=@@log_slow_verbosity; +SET SESSION log_slow_verbosity= 'innodb'; +--delimiter $ +BEGIN NOT ATOMIC DECLARE r ROW TYPE OF t1 DEFAULT (SELECT * FROM t1); SELECT r.a; END $ +--delimiter ; + +SET SESSION log_slow_verbosity= @tmp; +# Cleanup +DROP TABLE t1; + diff --git a/sql/sp_head.cc b/sql/sp_head.cc index ecb3fa2d6cd..f727356b5f6 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -3807,7 +3807,6 @@ int sp_instr_set::exec_core(THD *thd, uint *nextp) { int res= get_rcontext(thd)->set_variable(thd, m_offset, &m_value); - delete_explain_query(thd->lex); *nextp = m_ip+1; return res; } @@ -3849,7 +3848,6 @@ sp_instr_set_row_field::exec_core(THD *thd, uint *nextp) int res= get_rcontext(thd)->set_variable_row_field(thd, m_offset, m_field_offset, &m_value); - delete_explain_query(thd->lex); *nextp= m_ip + 1; return res; } @@ -3897,7 +3895,6 @@ sp_instr_set_row_field_by_name::exec_core(THD *thd, uint *nextp) int res= get_rcontext(thd)->set_variable_row_field_by_name(thd, m_offset, m_field_name, &m_value); - delete_explain_query(thd->lex); *nextp= m_ip + 1; return res; }