Commit 72bc6d73 authored by Sergey Petrunya's avatar Sergey Petrunya

MDEV-3798: EXPLAIN UPDATE/DELETE

- Address review feedback: more renames
parent 6a7f8af3
......@@ -11940,25 +11940,26 @@ void QUICK_SELECT_I::add_key_name(String *str, bool *first)
}
void QUICK_RANGE_SELECT::save_info(MEM_ROOT *alloc, Explain_quick_select *qpf)
void QUICK_RANGE_SELECT::save_info(MEM_ROOT *alloc,
Explain_quick_select *explain)
{
qpf->quick_type= QS_TYPE_RANGE;
qpf->range.set(alloc, head->key_info[index].name, max_used_key_length);
explain->quick_type= QS_TYPE_RANGE;
explain->range.set(alloc, head->key_info[index].name, max_used_key_length);
}
void QUICK_GROUP_MIN_MAX_SELECT::save_info(MEM_ROOT *alloc,
Explain_quick_select *qpf)
Explain_quick_select *explain)
{
qpf->quick_type= QS_TYPE_GROUP_MIN_MAX;
qpf->range.set(alloc, head->key_info[index].name, max_used_key_length);
explain->quick_type= QS_TYPE_GROUP_MIN_MAX;
explain->range.set(alloc, head->key_info[index].name, max_used_key_length);
}
void QUICK_INDEX_SORT_SELECT::save_info(MEM_ROOT *alloc,
Explain_quick_select *qpf)
Explain_quick_select *explain)
{
qpf->quick_type= get_type();
explain->quick_type= get_type();
QUICK_RANGE_SELECT *quick;
Explain_quick_select *child_qpf;
......@@ -11966,14 +11967,14 @@ void QUICK_INDEX_SORT_SELECT::save_info(MEM_ROOT *alloc,
while ((quick= it++))
{
child_qpf= new Explain_quick_select;
qpf->children.push_back(child_qpf);
explain->children.push_back(child_qpf);
quick->save_info(alloc, child_qpf);
}
if (pk_quick_select)
{
child_qpf= new Explain_quick_select;
qpf->children.push_back(child_qpf);
explain->children.push_back(child_qpf);
pk_quick_select->save_info(alloc, child_qpf);
}
}
......@@ -11983,15 +11984,15 @@ void QUICK_INDEX_SORT_SELECT::save_info(MEM_ROOT *alloc,
first
*/
void QUICK_INDEX_INTERSECT_SELECT::save_info(MEM_ROOT *alloc,
Explain_quick_select *qpf)
Explain_quick_select *explain)
{
qpf->quick_type= get_type();
explain->quick_type= get_type();
Explain_quick_select *child_qpf;
if (pk_quick_select)
{
child_qpf= new Explain_quick_select;
qpf->children.push_back(child_qpf);
explain->children.push_back(child_qpf);
pk_quick_select->save_info(alloc, child_qpf);
}
......@@ -12000,7 +12001,7 @@ void QUICK_INDEX_INTERSECT_SELECT::save_info(MEM_ROOT *alloc,
while ((quick= it++))
{
child_qpf= new Explain_quick_select;
qpf->children.push_back(child_qpf);
explain->children.push_back(child_qpf);
quick->save_info(alloc, child_qpf);
}
......@@ -12008,39 +12009,39 @@ void QUICK_INDEX_INTERSECT_SELECT::save_info(MEM_ROOT *alloc,
void QUICK_ROR_INTERSECT_SELECT::save_info(MEM_ROOT *alloc,
Explain_quick_select *qpf)
Explain_quick_select *explain)
{
qpf->quick_type= get_type();
explain->quick_type= get_type();
QUICK_SELECT_WITH_RECORD *qr;
List_iterator_fast<QUICK_SELECT_WITH_RECORD> it(quick_selects);
while ((qr= it++))
{
Explain_quick_select *child_qpf= new Explain_quick_select;
qpf->children.push_back(child_qpf);
explain->children.push_back(child_qpf);
qr->quick->save_info(alloc, child_qpf);
}
if (cpk_quick)
{
Explain_quick_select *child_qpf= new Explain_quick_select;
qpf->children.push_back(child_qpf);
explain->children.push_back(child_qpf);
cpk_quick->save_info(alloc, child_qpf);
}
}
void QUICK_ROR_UNION_SELECT::save_info(MEM_ROOT *alloc,
Explain_quick_select *qpf)
Explain_quick_select *explain)
{
qpf->quick_type= get_type();
explain->quick_type= get_type();
QUICK_SELECT_I *quick;
List_iterator_fast<QUICK_SELECT_I> it(quick_selects);
while ((quick= it++))
{
Explain_quick_select *child_qpf= new Explain_quick_select;
qpf->children.push_back(child_qpf);
explain->children.push_back(child_qpf);
quick->save_info(alloc, child_qpf);
}
}
......
......@@ -346,7 +346,7 @@ public:
void add_key_name(String *str, bool *first);
/* Save information about quick select's query plan */
virtual void save_info(MEM_ROOT *alloc, Explain_quick_select *qpf)= 0;
virtual void save_info(MEM_ROOT *alloc, Explain_quick_select *explain)= 0;
/*
Return 1 if any index used by this quick select
......@@ -473,7 +473,7 @@ public:
{ file->position(record); }
int get_type() { return QS_TYPE_RANGE; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void save_info(MEM_ROOT *alloc, Explain_quick_select *qpf);
void save_info(MEM_ROOT *alloc, Explain_quick_select *explain);
#ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose);
#endif
......@@ -610,7 +610,7 @@ public:
#ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose);
#endif
void save_info(MEM_ROOT *alloc, Explain_quick_select *qpf);
void save_info(MEM_ROOT *alloc, Explain_quick_select *explain);
bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range);
......@@ -674,7 +674,7 @@ public:
int get_next();
int get_type() { return QS_TYPE_INDEX_INTERSECT; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void save_info(MEM_ROOT *alloc, Explain_quick_select *qpf);
void save_info(MEM_ROOT *alloc, Explain_quick_select *explain);
};
......@@ -712,7 +712,7 @@ public:
bool unique_key_range() { return false; }
int get_type() { return QS_TYPE_ROR_INTERSECT; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void save_info(MEM_ROOT *alloc, Explain_quick_select *qpf);
void save_info(MEM_ROOT *alloc, Explain_quick_select *explain);
bool is_keys_used(const MY_BITMAP *fields);
#ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose);
......@@ -791,7 +791,7 @@ public:
bool unique_key_range() { return false; }
int get_type() { return QS_TYPE_ROR_UNION; }
void add_keys_and_lengths(String *key_names, String *used_lengths);
void save_info(MEM_ROOT *alloc, Explain_quick_select *qpf);
void save_info(MEM_ROOT *alloc, Explain_quick_select *explain);
bool is_keys_used(const MY_BITMAP *fields);
#ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose);
......@@ -940,7 +940,7 @@ public:
#endif
bool is_agg_distinct() { return have_agg_distinct; }
bool loose_scan_is_scanning() { return is_index_scan; }
void save_info(MEM_ROOT *alloc, Explain_quick_select *qpf);
void save_info(MEM_ROOT *alloc, Explain_quick_select *explain);
};
......
......@@ -53,59 +53,60 @@
void Delete_plan::save_explain_data(Explain_query *query)
{
QPF_delete* qpf= new QPF_delete;
Explain_delete* explain= new Explain_delete;
if (deleting_all_rows)
{
qpf->deleting_all_rows= true;
qpf->select_type= "SIMPLE";
explain->deleting_all_rows= true;
explain->select_type= "SIMPLE";
}
else
{
qpf->deleting_all_rows= false;
Update_plan::save_explain_data_intern(query, qpf);
explain->deleting_all_rows= false;
Update_plan::save_explain_data_intern(query, explain);
}
query->upd_del_plan= qpf;
query->upd_del_plan= explain;
}
void Update_plan::save_explain_data(Explain_query *query)
{
QPF_update* qpf= new QPF_update;
save_explain_data_intern(query, qpf);
query->upd_del_plan= qpf;
Explain_update* explain= new Explain_update;
save_explain_data_intern(query, explain);
query->upd_del_plan= explain;
}
void Update_plan::save_explain_data_intern(Explain_query *query, QPF_update *qpf)
void Update_plan::save_explain_data_intern(Explain_query *query,
Explain_update *explain)
{
qpf->select_type= "SIMPLE";
qpf->table_name.append(table->pos_in_table_list->alias);
explain->select_type= "SIMPLE";
explain->table_name.append(table->pos_in_table_list->alias);
if (impossible_where)
{
qpf->impossible_where= true;
explain->impossible_where= true;
return;
}
qpf->impossible_where= false;
explain->impossible_where= false;
select_lex->set_explain_type(TRUE);
qpf->select_type= select_lex->type;
explain->select_type= select_lex->type;
/* Partitions */
{
#ifdef WITH_PARTITION_STORAGE_ENGINE
partition_info *part_info;
if ((part_info= table->part_info))
{
make_used_partitions_str(part_info, &qpf->used_partitions);
qpf->used_partitions_set= true;
make_used_partitions_str(part_info, &explain->used_partitions);
explain->used_partitions_set= true;
}
else
qpf->used_partitions_set= false;
explain->used_partitions_set= false;
#else
/* just produce empty column if partitioning is not compiled in */
qpf->used_partitions_set= false;
explain->used_partitions_set= false;
#endif
}
......@@ -118,42 +119,43 @@ void Update_plan::save_explain_data_intern(Explain_query *query, QPF_update *qpf
(quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_INTERSECT) ||
(quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT) ||
(quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION))
qpf->jtype= JT_INDEX_MERGE;
explain->jtype= JT_INDEX_MERGE;
else
qpf->jtype= JT_RANGE;
explain->jtype= JT_RANGE;
}
else
{
if (index == MAX_KEY)
qpf->jtype= JT_ALL;
explain->jtype= JT_ALL;
else
qpf->jtype= JT_NEXT;
explain->jtype= JT_NEXT;
}
qpf->using_where= test(select && select->cond);
qpf->using_filesort= using_filesort;
explain->using_where= test(select && select->cond);
explain->using_filesort= using_filesort;
make_possible_keys_line(table, possible_keys, &qpf->possible_keys_line);
make_possible_keys_line(table, possible_keys, &explain->possible_keys_line);
/* Calculate key_len */
if (select && select->quick)
{
select->quick->add_keys_and_lengths(&qpf->key_str, &qpf->key_len_str);
select->quick->add_keys_and_lengths(&explain->key_str, &explain->key_len_str);
}
else
{
if (index != MAX_KEY)
{
qpf->key_str.append(table->key_info[index].name);
explain->key_str.append(table->key_info[index].name);
}
// key_len stays NULL
}
qpf->rows= select ? select->records : table_rows;
explain->rows= select ? select->records : table_rows;
if (select && select->quick &&
select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_RANGE)
{
explain_append_mrr_info((QUICK_RANGE_SELECT*)select->quick, &qpf->mrr_type);
explain_append_mrr_info((QUICK_RANGE_SELECT*)select->quick,
&explain->mrr_type);
}
bool skip= updating_a_view;
......@@ -173,7 +175,7 @@ void Update_plan::save_explain_data_intern(Explain_query *query, QPF_update *qpf
clauses.
*/
if (!(unit->item && unit->item->eliminated))
qpf->add_child(unit->first_select()->select_number);
explain->add_child(unit->first_select()->select_number);
}
}
......
......@@ -511,7 +511,8 @@ int Explain_table_access::print_explain(select_result_sink *output, uint8 explai
/*
Elements in this array match members of enum Extra_tag, defined in opt_qpf.h.
Elements in this array match members of enum Extra_tag, defined in
sql_explain.h
*/
const char * extra_tag_text[]=
......@@ -740,8 +741,9 @@ void Explain_quick_select::print_key_len(String *str)
}
int QPF_delete::print_explain(Explain_query *query, select_result_sink *output,
uint8 explain_flags)
int Explain_delete::print_explain(Explain_query *query,
select_result_sink *output,
uint8 explain_flags)
{
if (deleting_all_rows)
{
......@@ -754,13 +756,14 @@ int QPF_delete::print_explain(Explain_query *query, select_result_sink *output,
}
else
{
return QPF_update::print_explain(query, output, explain_flags);
return Explain_update::print_explain(query, output, explain_flags);
}
}
int QPF_update::print_explain(Explain_query *query, select_result_sink *output,
uint8 explain_flags)
int Explain_update::print_explain(Explain_query *query,
select_result_sink *output,
uint8 explain_flags)
{
StringBuffer<64> extra_str;
if (impossible_where)
......
......@@ -172,7 +172,7 @@ public:
bool using_filesort;
};
class QPF_delete;
class Explain_delete;
/*
......@@ -226,8 +226,8 @@ public:
Explain_union *get_union(uint select_id);
/* QPF_delete inherits from QPF_update */
QPF_update *upd_del_plan;
/* Explain_delete inherits from Explain_update */
Explain_update *upd_del_plan;
/* Produce a tabular EXPLAIN output */
int print_explain(select_result_sink *output, uint8 explain_flags);
......@@ -448,7 +448,7 @@ private:
Also, it can have UPDATE operation options, but currently there aren't any.
*/
class QPF_update : public Explain_node
class Explain_update : public Explain_node
{
public:
virtual enum explain_node_type get_type() { return EXPLAIN_UPDATE; }
......@@ -479,10 +479,10 @@ public:
/*
Query Plan Footprint for a single-table DELETE.
Explain data of a single-table DELETE.
*/
class QPF_delete: public QPF_update
class Explain_delete: public Explain_update
{
public:
/*
......
......@@ -2568,22 +2568,22 @@ finish:
none
*/
void JOIN_CACHE::save_explain_data(struct st_explain_bka_type *qpf)
void JOIN_CACHE::save_explain_data(struct st_explain_bka_type *explain)
{
qpf->incremental= test(prev_cache);
explain->incremental= test(prev_cache);
switch (get_join_alg()) {
case BNL_JOIN_ALG:
qpf->join_alg= "BNL";
explain->join_alg= "BNL";
break;
case BNLH_JOIN_ALG:
qpf->join_alg= "BNLH";
explain->join_alg= "BNLH";
break;
case BKA_JOIN_ALG:
qpf->join_alg= "BKA";
explain->join_alg= "BKA";
break;
case BKAH_JOIN_ALG:
qpf->join_alg= "BKAH";
explain->join_alg= "BKAH";
break;
default:
DBUG_ASSERT(0);
......@@ -2613,17 +2613,17 @@ static void add_mrr_explain_info(String *str, uint mrr_mode, handler *file)
}
}
void JOIN_CACHE_BKA::save_explain_data(struct st_explain_bka_type *qpf)
void JOIN_CACHE_BKA::save_explain_data(struct st_explain_bka_type *explain)
{
JOIN_CACHE::save_explain_data(qpf);
add_mrr_explain_info(&qpf->mrr_type, mrr_mode, join_tab->table->file);
JOIN_CACHE::save_explain_data(explain);
add_mrr_explain_info(&explain->mrr_type, mrr_mode, join_tab->table->file);
}
void JOIN_CACHE_BKAH::save_explain_data(struct st_explain_bka_type *qpf)
void JOIN_CACHE_BKAH::save_explain_data(struct st_explain_bka_type *explain)
{
JOIN_CACHE::save_explain_data(qpf);
add_mrr_explain_info(&qpf->mrr_type, mrr_mode, join_tab->table->file);
JOIN_CACHE::save_explain_data(explain);
add_mrr_explain_info(&explain->mrr_type, mrr_mode, join_tab->table->file);
}
......
......@@ -658,7 +658,7 @@ public:
enum_nested_loop_state join_records(bool skip_last);
/* Add a comment on the join algorithm employed by the join cache */
virtual void save_explain_data(struct st_explain_bka_type *qpf);
virtual void save_explain_data(struct st_explain_bka_type *explain);
THD *thd();
......@@ -1336,7 +1336,7 @@ public:
/* Check index condition of the joined table for a record from BKA cache */
bool skip_index_tuple(range_id_t range_info);
void save_explain_data(struct st_explain_bka_type *qpf);
void save_explain_data(struct st_explain_bka_type *explain);
};
......@@ -1427,5 +1427,5 @@ public:
/* Check index condition of the joined table for a record from BKAH cache */
bool skip_index_tuple(range_id_t range_info);
void save_explain_data(struct st_explain_bka_type *qpf);
void save_explain_data(struct st_explain_bka_type *explain);
};
......@@ -4264,12 +4264,12 @@ int st_select_lex_unit::save_union_explain(Explain_query *output)
const char *msg="Query plan already deleted";
first->set_explain_type(TRUE/* on_the_fly */);
Explain_select *qp_sel= new (output->mem_root)Explain_select;
qp_sel->select_id= first->select_number;
qp_sel->select_type= first->type;
qp_sel->message= msg;
output->add_node(qp_sel);
eu->add_select(qp_sel->select_id);
Explain_select *explain= new (output->mem_root)Explain_select;
explain->select_id= first->select_number;
explain->select_type= first->type;
explain->message= msg;
output->add_node(explain);
eu->add_select(explain->select_id);
return 0;
}
......
......@@ -2369,7 +2369,7 @@ class Delete_plan;
class SQL_SELECT;
class Explain_query;
class QPF_update;
class Explain_update;
/*
Query plan of a single-table UPDATE.
......@@ -2399,7 +2399,7 @@ public:
void set_impossible_where() { impossible_where= true; }
void save_explain_data(Explain_query *query);
void save_explain_data_intern(Explain_query *query, QPF_update *qpf);
void save_explain_data_intern(Explain_query *query, Explain_update *eu);
virtual ~Update_plan() {}
Update_plan() : impossible_where(false), using_filesort(false) {}
......
This diff is collapsed.
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