diff --git a/mysql-test/r/explain_slowquerylog.result b/mysql-test/r/explain_slowquerylog.result index 86e1ca391d6..8ba631545c3 100644 --- a/mysql-test/r/explain_slowquerylog.result +++ b/mysql-test/r/explain_slowquerylog.result @@ -9,3 +9,14 @@ id select_type table type possible_keys key key_len ref rows Extra # set autocommit=1; drop table t0; +# +# MDEV-5047 virtual THD::~THD(): Assertion `status_var.memory_used == 0' fails on disconnect +# +ALTER TABLE nonexisting ENABLE KEYS; +ERROR 42S02: Table 'test.nonexisting' doesn't exist +SHOW WARNINGS; +Level Code Message +Error 1146 Table 'test.nonexisting' doesn't exist +SELECT 1; +1 +1 diff --git a/mysql-test/t/explain_slowquerylog.test b/mysql-test/t/explain_slowquerylog.test index 64005d98d05..09565d90931 100644 --- a/mysql-test/t/explain_slowquerylog.test +++ b/mysql-test/t/explain_slowquerylog.test @@ -16,5 +16,15 @@ explain select * from t0 where a < 3; --echo # MDEV-5045: Server crashes in QPF_query::print_explain with log_slow_verbosity='query_plan,explain' --echo # set autocommit=1; - drop table t0; + +--echo # +--echo # MDEV-5047 virtual THD::~THD(): Assertion `status_var.memory_used == 0' fails on disconnect +--echo # +--connect (con1,localhost,root,,) +--error ER_NO_SUCH_TABLE +ALTER TABLE nonexisting ENABLE KEYS; +SHOW WARNINGS; +--disconnect con1 +--connection default +SELECT 1; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b8ab4cef1be..bc3d53dc32e 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1525,6 +1525,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd, } +/* + @note + This function must call delete_qpf_query(). +*/ void log_slow_statement(THD *thd) { DBUG_ENTER("log_slow_statement"); @@ -1543,7 +1547,10 @@ void log_slow_statement(THD *thd) if (!thd->enable_slow_log || (thd->variables.log_slow_filter && !(thd->variables.log_slow_filter & thd->query_plan_flags))) + { + delete_qpf_query(thd->lex); DBUG_VOID_RETURN; + } if (((thd->server_status & SERVER_QUERY_WAS_SLOW) || ((thd->server_status & @@ -4799,13 +4806,7 @@ finish: #endif } lex->unit.cleanup(); - //psergey-todo: print EXPLAIN here? After the above JOIN::cleanup calls? - // how do we print EXPLAIN extended, then? - if (lex->describe) - { - DBUG_ASSERT(lex->query_plan_footprint); - ///.. - } + /* Free tables */ thd_proc_info(thd, "closing tables"); close_thread_tables(thd);