diff options
Diffstat (limited to 'sql')
| -rw-r--r-- | sql/sql_explain.cc | 9 | ||||
| -rw-r--r-- | sql/sql_explain.h | 7 | ||||
| -rw-r--r-- | sql/sql_select.cc | 4 | ||||
| -rw-r--r-- | sql/sql_select.h | 6 |
4 files changed, 25 insertions, 1 deletions
diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index b4adfe8546c..fd5f675add5 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -1033,6 +1033,9 @@ void Explain_select::print_explain_json(Explain_query *query, writer->add_member("select_id").add_ll(select_id); add_linkage(writer); + if (cost != 0.0) + writer->add_member("cost").add_double(cost); + if (is_analyze && time_tracker.get_loops()) { writer->add_member("r_loops").add_ll(time_tracker.get_loops()); @@ -1942,7 +1945,13 @@ void Explain_table_access::print_explain_json(Explain_query *query, else writer->add_null(); } + } + + if (cost != 0.0) + writer->add_member("cost").add_double(cost); + if (is_analyze) + { if (op_tracker.get_loops()) { double total_time= op_tracker.get_time_ms(); diff --git a/sql/sql_explain.h b/sql/sql_explain.h index 42a1c360e5b..9e560c0be23 100644 --- a/sql/sql_explain.h +++ b/sql/sql_explain.h @@ -216,6 +216,7 @@ public: message(NULL), having(NULL), having_value(Item::COND_UNDEF), using_temporary(false), using_filesort(false), + cost(0.0), time_tracker(is_analyze), aggr_tree(NULL) {} @@ -249,9 +250,10 @@ public: bool using_temporary; bool using_filesort; + double cost; /* ANALYZE members */ Time_and_counter_tracker time_tracker; - + /* Part of query plan describing sorting, temp.table usage, and duplicate removal @@ -824,6 +826,9 @@ public: ha_rows rows; double filtered; + /* Total cost incurred during one execution of this select */ + double cost; + /* Contents of the 'Extra' column. Some are converted into strings, some have parameters, values for which are stored below. diff --git a/sql/sql_select.cc b/sql/sql_select.cc index c7ed2ebd810..17ae0cf079e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12021,6 +12021,7 @@ bool JOIN::get_best_combination() j->records_init= j->records_out= j->records_read; j->records= (ha_rows) j->records_read; j->cond_selectivity= 1.0; + j->join_read_time= 0.0; /* Not saved currently */ JOIN_TAB *jt; JOIN_TAB_RANGE *jt_range; if (!(jt= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB)*sjm->tables)) || @@ -12081,6 +12082,7 @@ bool JOIN::get_best_combination() j->records_init= cur_pos->records_init; j->records_read= cur_pos->records_read; j->records_out= cur_pos->records_out; + j->join_read_time= cur_pos->read_time; loop_end: j->cond_selectivity= cur_pos->cond_selectivity; @@ -28585,6 +28587,7 @@ bool JOIN_TAB::save_explain_data(Explain_table_access *eta, explain_plan= eta; eta->key.clear(); eta->quick_info= NULL; + eta->cost= join_read_time; SQL_SELECT *tab_select; /* @@ -29198,6 +29201,7 @@ int JOIN::save_explain_data_intern(Explain_query *output, table_map used_tables=0; join->select_lex->set_explain_type(true); + xpl_sel->cost= best_read; xpl_sel->select_id= join->select_lex->select_number; xpl_sel->select_type= join->select_lex->type; xpl_sel->linkage= select_lex->get_linkage(); diff --git a/sql/sql_select.h b/sql/sql_select.h index ce2ed623406..3956651c57b 100644 --- a/sql/sql_select.h +++ b/sql/sql_select.h @@ -350,6 +350,12 @@ typedef struct st_join_table { /* Copy of POSITION::records_out, set by get_best_combination() */ double records_out; + /* + Copy of POSITION::read_time, set by get_best_combination(). The cost of + accessing the table in course of the join execution. + */ + double join_read_time; + /* The selectivity of the conditions that can be pushed to the table */ double cond_selectivity; |
