From ae6e95c498db4800e95fdd70fadaa608f6aa9f3f Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Tue, 17 Sep 2013 16:03:40 +0400 Subject: [PATCH] Code cleanup. --- sql/opt_qpf.cc | 10 +++------- sql/opt_qpf.h | 5 +++-- sql/sql_delete.cc | 21 ++++++++------------- sql/sql_lex.h | 6 +++--- sql/sql_select.cc | 21 ++------------------- sql/sql_update.cc | 5 ++--- 6 files changed, 21 insertions(+), 47 deletions(-) diff --git a/sql/opt_qpf.cc b/sql/opt_qpf.cc index d3fd88ce9bd..f594d2b1b22 100644 --- a/sql/opt_qpf.cc +++ b/sql/opt_qpf.cc @@ -81,14 +81,13 @@ void QPF_query::add_node(QPF_node *node) QPF_select *sel= (QPF_select*)node; if (sel->select_id == (int)UINT_MAX) { - //TODO this is a "fake select" from a UNION. - DBUG_ASSERT(0); + DBUG_ASSERT(0); // this is a "fake select" from a UNION. } else { uint select_id= sel->select_id; QPF_select *old_node; - //DBUG_ASSERT(!get_select(select_id)); + if (selects.elements() <= select_id) selects.resize(max(select_id+1, selects.elements()*2), NULL); @@ -115,7 +114,7 @@ int QPF_query::print_explain(select_result_sink *output, } else { - // Start printing from id=1 + /* Start printing from node with id=1 */ QPF_node *node= get_node(1); return node->print_explain(this, output, explain_flags); } @@ -264,8 +263,6 @@ QPF_select::~QPF_select() int QPF_select::print_explain(QPF_query *query, select_result_sink *output, uint8 explain_flags) { - //output->unit.offset_limit_cnt= 0; - if (message) { List item_list; @@ -328,7 +325,6 @@ int QPF_table_access::print_explain(select_result_sink *output, uint8 explain_fl List item_list; Item *item_null= new Item_null(); - //const CHARSET_INFO *cs= system_charset_info; if (sjm_nest_select_id) select_id= sjm_nest_select_id; diff --git a/sql/opt_qpf.h b/sql/opt_qpf.h index 2ab32967c8b..b3996fcb58d 100644 --- a/sql/opt_qpf.h +++ b/sql/opt_qpf.h @@ -361,7 +361,7 @@ public: StringBuffer<32> used_partitions; bool used_partitions_set; - /* Empty strings means "NULL" will be printed */ + /* Empty string means "NULL" will be printed */ StringBuffer<32> possible_keys_str; /* @@ -375,7 +375,8 @@ public: QPF_index_use key; /* - when type==JT_HASH_NEXT, this stores the real index. + when type==JT_HASH_NEXT, 'key' stores the hash join pseudo-key. + hash_next_key stores the table's key. */ QPF_index_use hash_next_key; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 5655bb12886..93de4fccf5e 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -51,7 +51,7 @@ invoked on a running DELETE statement. */ -void Delete_plan::save_query_plan_footprint(QPF_query *query) +void Delete_plan::save_qpf(QPF_query *query) { QPF_delete* qpf= new QPF_delete; @@ -63,22 +63,22 @@ void Delete_plan::save_query_plan_footprint(QPF_query *query) else { qpf->deleting_all_rows= false; - Update_plan::save_query_plan_footprint_intern(query, qpf); + Update_plan::save_qpf_intern(query, qpf); } query->upd_del_plan= qpf; } -void Update_plan::save_query_plan_footprint(QPF_query *query) +void Update_plan::save_qpf(QPF_query *query) { QPF_update* qpf= new QPF_update; - save_query_plan_footprint_intern(query, qpf); + save_qpf_intern(query, qpf); query->upd_del_plan= qpf; } -void Update_plan::save_query_plan_footprint_intern(QPF_query *query, QPF_update *qpf) +void Update_plan::save_qpf_intern(QPF_query *query, QPF_update *qpf) { qpf->select_type= "SIMPLE"; qpf->table_name.append(table->pos_in_table_list->alias); @@ -116,7 +116,6 @@ void Update_plan::save_query_plan_footprint_intern(QPF_query *query, QPF_update qpf->using_where= test(select && select->cond); qpf->using_filesort= using_filesort; - //using_filesort is already set make_possible_keys_line(table, possible_keys, &qpf->possible_keys_line); /* Calculate key_len */ @@ -141,6 +140,7 @@ void Update_plan::save_query_plan_footprint_intern(QPF_query *query, QPF_update } bool skip= updating_a_view; + /* Save subquery children */ for (SELECT_LEX_UNIT *unit= select_lex->first_inner_unit(); unit; @@ -157,11 +157,6 @@ void Update_plan::save_query_plan_footprint_intern(QPF_query *query, QPF_update */ if (!(unit->item && unit->item->eliminated)) qpf->add_child(unit->first_select()->select_number); - - //TODO: temporary?: - // A: yes. optimizing children subqueries has caused them to save QPFs, - // automatically. - //unit->save_qpf(query); } } @@ -423,7 +418,7 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, if (thd->lex->describe) goto exit_without_my_ok; - query_plan.save_query_plan_footprint(thd->lex->query_plan_footprint); + query_plan.save_qpf(thd->lex->query_plan_footprint); thd->apc_target.enable(); DBUG_EXECUTE_IF("show_explain_probe_delete_exec_start", @@ -656,7 +651,7 @@ cleanup: /* Special exits */ exit_without_my_ok: - query_plan.save_query_plan_footprint(thd->lex->query_plan_footprint); + query_plan.save_qpf(thd->lex->query_plan_footprint); select_send *result2; if (!(result2= new select_send())) diff --git a/sql/sql_lex.h b/sql/sql_lex.h index a84a452ef68..d06f31bd53f 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -2397,8 +2397,8 @@ public: /* Set this plan to be a plan to do nothing because of impossible WHRE*/ void set_impossible_where() { impossible_where= true; } - void save_query_plan_footprint(QPF_query *query); - void save_query_plan_footprint_intern(QPF_query *query, QPF_update *qpf); + void save_qpf(QPF_query *query); + void save_qpf_intern(QPF_query *query, QPF_update *qpf); virtual ~Update_plan() {} Update_plan() : impossible_where(false), using_filesort(false) {} @@ -2422,7 +2422,7 @@ public: table_rows= rows_arg; } - void save_query_plan_footprint(QPF_query *query); + void save_qpf(QPF_query *query); }; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 236ddbe8ed3..2c510a39f8e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -22517,8 +22517,6 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, bool distinct, const char *message) { QPF_node *qp_node; - const bool on_the_fly= true; - JOIN *join= this; /* Legacy: this code used to be a non-member function */ THD *thd=join->thd; const CHARSET_INFO *cs= system_charset_info; @@ -22535,7 +22533,7 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, { QPF_select *qp_sel; qp_node= qp_sel= new (output->mem_root) QPF_select; - join->select_lex->set_explain_type(on_the_fly); + join->select_lex->set_explain_type(true); qp_sel->select_id= join->select_lex->select_number; qp_sel->select_type= join->select_lex->type; @@ -22554,10 +22552,7 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, qp_node= qp_sel= new (output->mem_root) QPF_select; table_map used_tables=0; - if (on_the_fly) - join->select_lex->set_explain_type(on_the_fly); - - //bool printing_materialize_nest= FALSE; + join->select_lex->set_explain_type(true); uint select_id= join->select_lex->select_number; qp_sel->select_id= join->select_lex->select_number; @@ -22568,13 +22563,6 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, for (JOIN_TAB *tab= first_breadth_first_tab(join, WALK_OPTIMIZATION_TABS); tab; tab= next_breadth_first_tab(join, WALK_OPTIMIZATION_TABS, tab)) { - if (tab->bush_root_tab) - { - JOIN_TAB *first_sibling= tab->bush_root_tab->bush_children->start; - select_id= first_sibling->emb_sj_nest->sj_subq_pred->get_identifier(); - //printing_materialize_nest= TRUE; - } - TABLE *table=tab->table; TABLE_LIST *table_list= tab->table->pos_in_table_list; char buff4[512]; @@ -22615,9 +22603,6 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, qpt->sjm_nest_select_id= 0; /* select_type */ - //const char* stype= printing_materialize_nest? "MATERIALIZED" : - // join->select_lex->type; - //item_list.push_back(new Item_string(stype, strlen(stype), cs)); qp_sel->select_type= join->select_lex->type; /* table */ @@ -22684,8 +22669,6 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order, append_possible_keys(&qpt->possible_keys_str, table, tab->keys); /* Build "key", "key_len", and "ref" */ - - // tmp4 holds ref if (tab_type == JT_NEXT) { key_info= table->key_info+tab->index; diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 74f1a279411..15b3b9ad7e7 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -500,7 +500,7 @@ int mysql_update(THD *thd, if (thd->lex->describe) goto exit_without_my_ok; - query_plan.save_query_plan_footprint(thd->lex->query_plan_footprint); + query_plan.save_qpf(thd->lex->query_plan_footprint); thd->apc_target.enable(); apc_target_enabled= true; DBUG_EXECUTE_IF("show_explain_probe_update_exec_start", @@ -1031,10 +1031,9 @@ err: exit_without_my_ok: DBUG_ASSERT(!apc_target_enabled); - query_plan.save_query_plan_footprint(thd->lex->query_plan_footprint); + query_plan.save_qpf(thd->lex->query_plan_footprint); select_send *result; - //bool printed_anything; if (!(result= new select_send())) return 1; /* purecov: inspected */ List dummy; /* note: looked in 5.6 and they too use a dummy list like this */