mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-5070 - EXPLAIN INSERT ... SELECT crashes on 10.0-base-explain-slowquerylog
- Add EXPLAIN output print out for INSERT/REPLACE ... SELECT
This commit is contained in:
@ -114,3 +114,16 @@ explain delete from t0 returning a;
|
|||||||
id select_type table type possible_keys key key_len ref rows Extra
|
id select_type table type possible_keys key key_len ref rows Extra
|
||||||
1 SIMPLE t0 ALL NULL NULL NULL NULL 4
|
1 SIMPLE t0 ALL NULL NULL NULL NULL 4
|
||||||
drop table t0;
|
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;
|
explain delete from t0 returning a;
|
||||||
drop table t0;
|
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;
|
List<Item> field_list;
|
||||||
make_explain_field_list(field_list);
|
make_explain_field_list(field_list);
|
||||||
|
result->prepare(field_list, NULL);
|
||||||
return (result->send_result_set_metadata(field_list,
|
return (result->send_result_set_metadata(field_list,
|
||||||
Protocol::SEND_NUM_ROWS |
|
Protocol::SEND_NUM_ROWS |
|
||||||
Protocol::SEND_EOF));
|
Protocol::SEND_EOF));
|
||||||
|
@ -3173,6 +3173,7 @@ end_with_restore_list:
|
|||||||
case SQLCOM_INSERT_SELECT:
|
case SQLCOM_INSERT_SELECT:
|
||||||
{
|
{
|
||||||
select_result *sel_result;
|
select_result *sel_result;
|
||||||
|
bool explain= test(lex->describe);
|
||||||
DBUG_ASSERT(first_table == all_tables && first_table != 0);
|
DBUG_ASSERT(first_table == all_tables && first_table != 0);
|
||||||
if ((res= insert_precheck(thd, all_tables)))
|
if ((res= insert_precheck(thd, all_tables)))
|
||||||
break;
|
break;
|
||||||
@ -3205,7 +3206,10 @@ end_with_restore_list:
|
|||||||
|
|
||||||
if (!(res= open_and_lock_tables(thd, all_tables, TRUE, 0)))
|
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
|
Only the INSERT table should be merged. Other will be handled by
|
||||||
select.
|
select.
|
||||||
@ -3242,8 +3246,22 @@ end_with_restore_list:
|
|||||||
}
|
}
|
||||||
delete sel_result;
|
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 */
|
/* 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;
|
select_lex->table_list.first= first_table;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -3322,7 +3340,6 @@ end_with_restore_list:
|
|||||||
delete result;
|
delete result;
|
||||||
result= NULL;
|
result= NULL;
|
||||||
}
|
}
|
||||||
//select_lex->set_explain_type(FALSE);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
result= new multi_delete(aux_tables, lex->table_count);
|
result= new multi_delete(aux_tables, lex->table_count);
|
||||||
|
Reference in New Issue
Block a user