mirror of
https://github.com/MariaDB/server.git
synced 2025-01-16 03:52:35 +01:00
MDEV-5045: Server crashes in QPF_query::print_explain with log_slow_verbosity='explain'
- Don't print a plan when the statement didn't produce it - Also, add first testcase. We can't check the EXPLAIN from the slow log itself, though.
This commit is contained in:
parent
2add402891
commit
d998a1635f
6 changed files with 41 additions and 6 deletions
11
mysql-test/r/explain_slowquerylog.result
Normal file
11
mysql-test/r/explain_slowquerylog.result
Normal file
|
@ -0,0 +1,11 @@
|
|||
drop table if exists t0,t1;
|
||||
create table t0 (a int);
|
||||
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
||||
explain select * from t0 where a < 3;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t0 ALL NULL NULL NULL NULL 10 Using where
|
||||
#
|
||||
# MDEV-5045: Server crashes in QPF_query::print_explain with log_slow_verbosity='query_plan,explain'
|
||||
#
|
||||
set autocommit=1;
|
||||
drop table t0;
|
1
mysql-test/t/explain_slowquerylog-master.opt
Normal file
1
mysql-test/t/explain_slowquerylog-master.opt
Normal file
|
@ -0,0 +1 @@
|
|||
--slow-query-log --long-query-time=0.00000 --log-slow-verbosity=query_plan,explain
|
20
mysql-test/t/explain_slowquerylog.test
Normal file
20
mysql-test/t/explain_slowquerylog.test
Normal file
|
@ -0,0 +1,20 @@
|
|||
#
|
||||
# This is a test for EXPLAINs being written into slow query log.
|
||||
# For now, we just run the queries and hope not to crash.
|
||||
#
|
||||
#
|
||||
--disable_warnings
|
||||
drop table if exists t0,t1;
|
||||
--enable_warnings
|
||||
|
||||
create table t0 (a int);
|
||||
insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
||||
|
||||
explain select * from t0 where a < 3;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-5045: Server crashes in QPF_query::print_explain with log_slow_verbosity='query_plan,explain'
|
||||
--echo #
|
||||
set autocommit=1;
|
||||
|
||||
drop table t0;
|
|
@ -2830,8 +2830,8 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time,
|
|||
{
|
||||
StringBuffer<128> buf;
|
||||
DBUG_ASSERT(!thd->free_list);
|
||||
print_qpf_query(thd->lex, thd, &buf);
|
||||
my_b_printf(&log_file, "%s", buf.c_ptr_safe());
|
||||
if (!print_qpf_query(thd->lex, thd, &buf))
|
||||
my_b_printf(&log_file, "%s", buf.c_ptr_safe());
|
||||
thd->free_items();
|
||||
}
|
||||
if (thd->db && strcmp(thd->db, db))
|
||||
|
|
|
@ -116,13 +116,15 @@ int QPF_query::print_explain(select_result_sink *output,
|
|||
{
|
||||
/* Start printing from node with id=1 */
|
||||
QPF_node *node= get_node(1);
|
||||
if (!node)
|
||||
return 1; /* No query plan */
|
||||
return node->print_explain(this, output, explain_flags);
|
||||
}
|
||||
}
|
||||
|
||||
void print_qpf_query(LEX *lex, THD *thd, String *str)
|
||||
bool print_qpf_query(LEX *lex, THD *thd, String *str)
|
||||
{
|
||||
lex->query_plan_footprint->print_explain_str(thd, str);
|
||||
return lex->query_plan_footprint->print_explain_str(thd, str);
|
||||
}
|
||||
|
||||
bool QPF_query::print_explain_str(THD *thd, String *out_str)
|
||||
|
@ -132,7 +134,8 @@ bool QPF_query::print_explain_str(THD *thd, String *out_str)
|
|||
|
||||
select_result_text_buffer output_buf(thd);
|
||||
output_buf.send_result_set_metadata(fields, thd->lex->describe);
|
||||
print_explain(&output_buf, 0);
|
||||
if (print_explain(&output_buf, 0))
|
||||
return true;
|
||||
output_buf.save_to(out_str);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -622,7 +622,7 @@ class QPF_query;
|
|||
|
||||
void delete_qpf_query(LEX *lex);
|
||||
void create_qpf_query(LEX *lex, MEM_ROOT *mem_root);
|
||||
void print_qpf_query(LEX *lex, THD *thd, String *str);
|
||||
bool print_qpf_query(LEX *lex, THD *thd, String *str);
|
||||
|
||||
class st_select_lex_unit: public st_select_lex_node {
|
||||
protected:
|
||||
|
|
Loading…
Reference in a new issue