Commit ac54df04 authored by Sergey Petrunya's avatar Sergey Petrunya

MDEV-5070 - EXPLAIN INSERT ... SELECT crashes on 10.0-base-explain-slowquerylog

- Add EXPLAIN output print out for INSERT/REPLACE ... SELECT
parent 28734220
......@@ -114,3 +114,16 @@ explain delete from t0 returning a;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 4
drop table t0;
#
# MDEV-5070 - EXPLAIN INSERT ... SELECT crashes on 10.0-base-explain-slowquerylog
#
create table t0 (a int);
insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
create table t1 (a int);
explain insert into t1 select * from t0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 8
explain replace into t1 select * from t0;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t0 ALL NULL NULL NULL NULL 8
drop table t0, t1;
......@@ -94,4 +94,16 @@ explain delete from t0 where a=1 returning a;
explain delete from t0 returning a;
drop table t0;
--echo #
--echo # MDEV-5070 - EXPLAIN INSERT ... SELECT crashes on 10.0-base-explain-slowquerylog
--echo #
create table t0 (a int);
insert into t0 values (1),(2),(3),(4),(5),(6),(7),(8);
create table t1 (a int);
explain insert into t1 select * from t0;
explain replace into t1 select * from t0;
drop table t0, t1;
......@@ -2089,6 +2089,7 @@ int THD::send_explain_fields(select_result *result)
{
List<Item> field_list;
make_explain_field_list(field_list);
result->prepare(field_list, NULL);
return (result->send_result_set_metadata(field_list,
Protocol::SEND_NUM_ROWS |
Protocol::SEND_EOF));
......
......@@ -3173,6 +3173,7 @@ end_with_restore_list:
case SQLCOM_INSERT_SELECT:
{
select_result *sel_result;
bool explain= test(lex->describe);
DBUG_ASSERT(first_table == all_tables && first_table != 0);
if ((res= insert_precheck(thd, all_tables)))
break;
......@@ -3205,7 +3206,10 @@ end_with_restore_list:
if (!(res= open_and_lock_tables(thd, all_tables, TRUE, 0)))
{
MYSQL_INSERT_SELECT_START(thd->query());
if (!explain)
{
MYSQL_INSERT_SELECT_START(thd->query());
}
/*
Only the INSERT table should be merged. Other will be handled by
select.
......@@ -3242,8 +3246,22 @@ end_with_restore_list:
}
delete sel_result;
}
if (!res && explain)
{
select_result *result= new select_send();
LEX *lex= thd->lex;
if (thd->send_explain_fields(result) ||
lex->query_plan_footprint->print_explain(result, lex->describe) ||
result->send_eof())
res= 1;
}
/* revert changes for SP */
MYSQL_INSERT_SELECT_DONE(res, (ulong) thd->get_row_count_func());
if (!explain)
{
MYSQL_INSERT_SELECT_DONE(res, (ulong) thd->get_row_count_func());
}
select_lex->table_list.first= first_table;
}
/*
......@@ -3322,7 +3340,6 @@ end_with_restore_list:
delete result;
result= NULL;
}
//select_lex->set_explain_type(FALSE);
}
else
result= new multi_delete(aux_tables, lex->table_count);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment