diff options
author | Sergey Petrunya <psergey@askmonty.org> | 2013-09-25 17:23:22 +0400 |
---|---|---|
committer | Sergey Petrunya <psergey@askmonty.org> | 2013-09-25 17:23:22 +0400 |
commit | ac54df04d80781ea243cfbc8865bfe080b44f4e2 (patch) | |
tree | 57e7bb79f5bf6788097c4776dd9e45b03fdb5822 | |
parent | 28734220e7bbd85fa74a821300afdd4cad75ce13 (diff) | |
download | mariadb-git-ac54df04d80781ea243cfbc8865bfe080b44f4e2.tar.gz |
MDEV-5070 - EXPLAIN INSERT ... SELECT crashes on 10.0-base-explain-slowquerylog
- Add EXPLAIN output print out for INSERT/REPLACE ... SELECT
-rw-r--r-- | mysql-test/r/explain_non_select.result | 13 | ||||
-rw-r--r-- | mysql-test/t/explain_non_select.test | 12 | ||||
-rw-r--r-- | sql/sql_class.cc | 1 | ||||
-rw-r--r-- | sql/sql_parse.cc | 23 |
4 files changed, 46 insertions, 3 deletions
diff --git a/mysql-test/r/explain_non_select.result b/mysql-test/r/explain_non_select.result index 021c5d92daa..267b5f27c35 100644 --- a/mysql-test/r/explain_non_select.result +++ b/mysql-test/r/explain_non_select.result @@ -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; diff --git a/mysql-test/t/explain_non_select.test b/mysql-test/t/explain_non_select.test index 7385ef5d420..316720b17f3 100644 --- a/mysql-test/t/explain_non_select.test +++ b/mysql-test/t/explain_non_select.test @@ -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; + diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 08e8fbe7361..b080951dd01 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -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)); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 28d96feadbb..133485c3a68 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -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); |