MDEV-3798: EXPLAIN UPDATE/DELETE

- Address review feedback: more renames
This commit is contained in:
Sergey Petrunya 2013-10-05 13:19:45 +04:00
parent 6a7f8af3f9
commit 72bc6d7364
10 changed files with 173 additions and 167 deletions

View File

@ -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; explain->quick_type= QS_TYPE_RANGE;
qpf->range.set(alloc, head->key_info[index].name, max_used_key_length); explain->range.set(alloc, head->key_info[index].name, max_used_key_length);
} }
void QUICK_GROUP_MIN_MAX_SELECT::save_info(MEM_ROOT *alloc, 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; explain->quick_type= QS_TYPE_GROUP_MIN_MAX;
qpf->range.set(alloc, head->key_info[index].name, max_used_key_length); explain->range.set(alloc, head->key_info[index].name, max_used_key_length);
} }
void QUICK_INDEX_SORT_SELECT::save_info(MEM_ROOT *alloc, 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; QUICK_RANGE_SELECT *quick;
Explain_quick_select *child_qpf; Explain_quick_select *child_qpf;
@ -11966,14 +11967,14 @@ void QUICK_INDEX_SORT_SELECT::save_info(MEM_ROOT *alloc,
while ((quick= it++)) while ((quick= it++))
{ {
child_qpf= new 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); quick->save_info(alloc, child_qpf);
} }
if (pk_quick_select) if (pk_quick_select)
{ {
child_qpf= new Explain_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); pk_quick_select->save_info(alloc, child_qpf);
} }
} }
@ -11983,15 +11984,15 @@ void QUICK_INDEX_SORT_SELECT::save_info(MEM_ROOT *alloc,
first first
*/ */
void QUICK_INDEX_INTERSECT_SELECT::save_info(MEM_ROOT *alloc, 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; Explain_quick_select *child_qpf;
if (pk_quick_select) if (pk_quick_select)
{ {
child_qpf= new Explain_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); 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++)) while ((quick= it++))
{ {
child_qpf= new 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); 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, 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; QUICK_SELECT_WITH_RECORD *qr;
List_iterator_fast<QUICK_SELECT_WITH_RECORD> it(quick_selects); List_iterator_fast<QUICK_SELECT_WITH_RECORD> it(quick_selects);
while ((qr= it++)) while ((qr= it++))
{ {
Explain_quick_select *child_qpf= new Explain_quick_select; 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); qr->quick->save_info(alloc, child_qpf);
} }
if (cpk_quick) if (cpk_quick)
{ {
Explain_quick_select *child_qpf= new Explain_quick_select; 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); cpk_quick->save_info(alloc, child_qpf);
} }
} }
void QUICK_ROR_UNION_SELECT::save_info(MEM_ROOT *alloc, 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; QUICK_SELECT_I *quick;
List_iterator_fast<QUICK_SELECT_I> it(quick_selects); List_iterator_fast<QUICK_SELECT_I> it(quick_selects);
while ((quick= it++)) while ((quick= it++))
{ {
Explain_quick_select *child_qpf= new Explain_quick_select; 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); quick->save_info(alloc, child_qpf);
} }
} }

View File

@ -346,7 +346,7 @@ public:
void add_key_name(String *str, bool *first); void add_key_name(String *str, bool *first);
/* Save information about quick select's query plan */ /* 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 Return 1 if any index used by this quick select
@ -473,7 +473,7 @@ public:
{ file->position(record); } { file->position(record); }
int get_type() { return QS_TYPE_RANGE; } int get_type() { return QS_TYPE_RANGE; }
void add_keys_and_lengths(String *key_names, String *used_lengths); 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 #ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose); void dbug_dump(int indent, bool verbose);
#endif #endif
@ -610,7 +610,7 @@ public:
#ifndef DBUG_OFF #ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose); void dbug_dump(int indent, bool verbose);
#endif #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); bool push_quick_back(QUICK_RANGE_SELECT *quick_sel_range);
@ -674,7 +674,7 @@ public:
int get_next(); int get_next();
int get_type() { return QS_TYPE_INDEX_INTERSECT; } int get_type() { return QS_TYPE_INDEX_INTERSECT; }
void add_keys_and_lengths(String *key_names, String *used_lengths); 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; } bool unique_key_range() { return false; }
int get_type() { return QS_TYPE_ROR_INTERSECT; } int get_type() { return QS_TYPE_ROR_INTERSECT; }
void add_keys_and_lengths(String *key_names, String *used_lengths); 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); bool is_keys_used(const MY_BITMAP *fields);
#ifndef DBUG_OFF #ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose); void dbug_dump(int indent, bool verbose);
@ -791,7 +791,7 @@ public:
bool unique_key_range() { return false; } bool unique_key_range() { return false; }
int get_type() { return QS_TYPE_ROR_UNION; } int get_type() { return QS_TYPE_ROR_UNION; }
void add_keys_and_lengths(String *key_names, String *used_lengths); 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); bool is_keys_used(const MY_BITMAP *fields);
#ifndef DBUG_OFF #ifndef DBUG_OFF
void dbug_dump(int indent, bool verbose); void dbug_dump(int indent, bool verbose);
@ -940,7 +940,7 @@ public:
#endif #endif
bool is_agg_distinct() { return have_agg_distinct; } bool is_agg_distinct() { return have_agg_distinct; }
bool loose_scan_is_scanning() { return is_index_scan; } 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);
}; };

View File

@ -53,59 +53,60 @@
void Delete_plan::save_explain_data(Explain_query *query) 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) if (deleting_all_rows)
{ {
qpf->deleting_all_rows= true; explain->deleting_all_rows= true;
qpf->select_type= "SIMPLE"; explain->select_type= "SIMPLE";
} }
else else
{ {
qpf->deleting_all_rows= false; explain->deleting_all_rows= false;
Update_plan::save_explain_data_intern(query, qpf); 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) void Update_plan::save_explain_data(Explain_query *query)
{ {
QPF_update* qpf= new QPF_update; Explain_update* explain= new Explain_update;
save_explain_data_intern(query, qpf); save_explain_data_intern(query, explain);
query->upd_del_plan= qpf; 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"; explain->select_type= "SIMPLE";
qpf->table_name.append(table->pos_in_table_list->alias); explain->table_name.append(table->pos_in_table_list->alias);
if (impossible_where) if (impossible_where)
{ {
qpf->impossible_where= true; explain->impossible_where= true;
return; return;
} }
qpf->impossible_where= false; explain->impossible_where= false;
select_lex->set_explain_type(TRUE); select_lex->set_explain_type(TRUE);
qpf->select_type= select_lex->type; explain->select_type= select_lex->type;
/* Partitions */ /* Partitions */
{ {
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
partition_info *part_info; partition_info *part_info;
if ((part_info= table->part_info)) if ((part_info= table->part_info))
{ {
make_used_partitions_str(part_info, &qpf->used_partitions); make_used_partitions_str(part_info, &explain->used_partitions);
qpf->used_partitions_set= true; explain->used_partitions_set= true;
} }
else else
qpf->used_partitions_set= false; explain->used_partitions_set= false;
#else #else
/* just produce empty column if partitioning is not compiled in */ /* just produce empty column if partitioning is not compiled in */
qpf->used_partitions_set= false; explain->used_partitions_set= false;
#endif #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_INDEX_INTERSECT) ||
(quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT) || (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT) ||
(quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION)) (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION))
qpf->jtype= JT_INDEX_MERGE; explain->jtype= JT_INDEX_MERGE;
else else
qpf->jtype= JT_RANGE; explain->jtype= JT_RANGE;
} }
else else
{ {
if (index == MAX_KEY) if (index == MAX_KEY)
qpf->jtype= JT_ALL; explain->jtype= JT_ALL;
else else
qpf->jtype= JT_NEXT; explain->jtype= JT_NEXT;
} }
qpf->using_where= test(select && select->cond); explain->using_where= test(select && select->cond);
qpf->using_filesort= using_filesort; 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 */ /* Calculate key_len */
if (select && select->quick) 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 else
{ {
if (index != MAX_KEY) 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 // key_len stays NULL
} }
qpf->rows= select ? select->records : table_rows; explain->rows= select ? select->records : table_rows;
if (select && select->quick && if (select && select->quick &&
select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_RANGE) 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; bool skip= updating_a_view;
@ -173,7 +175,7 @@ void Update_plan::save_explain_data_intern(Explain_query *query, QPF_update *qpf
clauses. clauses.
*/ */
if (!(unit->item && unit->item->eliminated)) if (!(unit->item && unit->item->eliminated))
qpf->add_child(unit->first_select()->select_number); explain->add_child(unit->first_select()->select_number);
} }
} }

View File

@ -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[]= const char * extra_tag_text[]=
@ -740,7 +741,8 @@ void Explain_quick_select::print_key_len(String *str)
} }
int QPF_delete::print_explain(Explain_query *query, select_result_sink *output, int Explain_delete::print_explain(Explain_query *query,
select_result_sink *output,
uint8 explain_flags) uint8 explain_flags)
{ {
if (deleting_all_rows) if (deleting_all_rows)
@ -754,12 +756,13 @@ int QPF_delete::print_explain(Explain_query *query, select_result_sink *output,
} }
else 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, int Explain_update::print_explain(Explain_query *query,
select_result_sink *output,
uint8 explain_flags) uint8 explain_flags)
{ {
StringBuffer<64> extra_str; StringBuffer<64> extra_str;

View File

@ -172,7 +172,7 @@ public:
bool using_filesort; bool using_filesort;
}; };
class QPF_delete; class Explain_delete;
/* /*
@ -226,8 +226,8 @@ public:
Explain_union *get_union(uint select_id); Explain_union *get_union(uint select_id);
/* QPF_delete inherits from QPF_update */ /* Explain_delete inherits from Explain_update */
QPF_update *upd_del_plan; Explain_update *upd_del_plan;
/* Produce a tabular EXPLAIN output */ /* Produce a tabular EXPLAIN output */
int print_explain(select_result_sink *output, uint8 explain_flags); 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. 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: public:
virtual enum explain_node_type get_type() { return EXPLAIN_UPDATE; } 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: public:
/* /*

View File

@ -2568,22 +2568,22 @@ finish:
none 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()) { switch (get_join_alg()) {
case BNL_JOIN_ALG: case BNL_JOIN_ALG:
qpf->join_alg= "BNL"; explain->join_alg= "BNL";
break; break;
case BNLH_JOIN_ALG: case BNLH_JOIN_ALG:
qpf->join_alg= "BNLH"; explain->join_alg= "BNLH";
break; break;
case BKA_JOIN_ALG: case BKA_JOIN_ALG:
qpf->join_alg= "BKA"; explain->join_alg= "BKA";
break; break;
case BKAH_JOIN_ALG: case BKAH_JOIN_ALG:
qpf->join_alg= "BKAH"; explain->join_alg= "BKAH";
break; break;
default: default:
DBUG_ASSERT(0); 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); JOIN_CACHE::save_explain_data(explain);
add_mrr_explain_info(&qpf->mrr_type, mrr_mode, join_tab->table->file); 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); JOIN_CACHE::save_explain_data(explain);
add_mrr_explain_info(&qpf->mrr_type, mrr_mode, join_tab->table->file); add_mrr_explain_info(&explain->mrr_type, mrr_mode, join_tab->table->file);
} }

View File

@ -658,7 +658,7 @@ public:
enum_nested_loop_state join_records(bool skip_last); enum_nested_loop_state join_records(bool skip_last);
/* Add a comment on the join algorithm employed by the join cache */ /* 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(); THD *thd();
@ -1336,7 +1336,7 @@ public:
/* Check index condition of the joined table for a record from BKA cache */ /* Check index condition of the joined table for a record from BKA cache */
bool skip_index_tuple(range_id_t range_info); 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 */ /* Check index condition of the joined table for a record from BKAH cache */
bool skip_index_tuple(range_id_t range_info); 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);
}; };

View File

@ -4264,12 +4264,12 @@ int st_select_lex_unit::save_union_explain(Explain_query *output)
const char *msg="Query plan already deleted"; const char *msg="Query plan already deleted";
first->set_explain_type(TRUE/* on_the_fly */); first->set_explain_type(TRUE/* on_the_fly */);
Explain_select *qp_sel= new (output->mem_root)Explain_select; Explain_select *explain= new (output->mem_root)Explain_select;
qp_sel->select_id= first->select_number; explain->select_id= first->select_number;
qp_sel->select_type= first->type; explain->select_type= first->type;
qp_sel->message= msg; explain->message= msg;
output->add_node(qp_sel); output->add_node(explain);
eu->add_select(qp_sel->select_id); eu->add_select(explain->select_id);
return 0; return 0;
} }

View File

@ -2369,7 +2369,7 @@ class Delete_plan;
class SQL_SELECT; class SQL_SELECT;
class Explain_query; class Explain_query;
class QPF_update; class Explain_update;
/* /*
Query plan of a single-table UPDATE. Query plan of a single-table UPDATE.
@ -2399,7 +2399,7 @@ public:
void set_impossible_where() { impossible_where= true; } void set_impossible_where() { impossible_where= true; }
void save_explain_data(Explain_query *query); 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() {} virtual ~Update_plan() {}
Update_plan() : impossible_where(false), using_filesort(false) {} Update_plan() : impossible_where(false), using_filesort(false) {}

View File

@ -22481,7 +22481,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
bool need_order, bool distinct, bool need_order, bool distinct,
const char *message) const char *message)
{ {
Explain_node *qp_node; Explain_node *explain_node;
JOIN *join= this; /* Legacy: this code used to be a non-member function */ JOIN *join= this; /* Legacy: this code used to be a non-member function */
THD *thd=join->thd; THD *thd=join->thd;
const CHARSET_INFO *cs= system_charset_info; const CHARSET_INFO *cs= system_charset_info;
@ -22497,7 +22497,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
if (message) if (message)
{ {
Explain_select *xpl_sel; Explain_select *xpl_sel;
qp_node= xpl_sel= new (output->mem_root) Explain_select; explain_node= xpl_sel= new (output->mem_root) Explain_select;
join->select_lex->set_explain_type(true); join->select_lex->set_explain_type(true);
xpl_sel->select_id= join->select_lex->select_number; xpl_sel->select_id= join->select_lex->select_number;
@ -22514,7 +22514,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
join->select_lex->master_unit()->derived->is_materialized_derived()) join->select_lex->master_unit()->derived->is_materialized_derived())
{ {
Explain_select *xpl_sel; Explain_select *xpl_sel;
qp_node= xpl_sel= new (output->mem_root) Explain_select; explain_node= xpl_sel= new (output->mem_root) Explain_select;
table_map used_tables=0; table_map used_tables=0;
join->select_lex->set_explain_type(true); join->select_lex->set_explain_type(true);
@ -22562,16 +22562,16 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
tab= pre_sort_join_tab; tab= pre_sort_join_tab;
} }
Explain_table_access *qpt= new (output->mem_root) Explain_table_access; Explain_table_access *eta= new (output->mem_root) Explain_table_access;
xpl_sel->add_table(qpt); xpl_sel->add_table(eta);
qpt->key.set(thd->mem_root, NULL, (uint)-1); eta->key.set(thd->mem_root, NULL, (uint)-1);
qpt->quick_info= NULL; eta->quick_info= NULL;
/* id */ /* id */
if (tab->bush_root_tab) if (tab->bush_root_tab)
qpt->sjm_nest_select_id= select_id; eta->sjm_nest_select_id= select_id;
else else
qpt->sjm_nest_select_id= 0; eta->sjm_nest_select_id= 0;
/* select_type */ /* select_type */
xpl_sel->select_type= join->select_lex->type; xpl_sel->select_type= join->select_lex->type;
@ -22583,7 +22583,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
int len= my_snprintf(table_name_buffer, sizeof(table_name_buffer)-1, int len= my_snprintf(table_name_buffer, sizeof(table_name_buffer)-1,
"<derived%u>", "<derived%u>",
table->derived_select_number); table->derived_select_number);
qpt->table_name.copy(table_name_buffer, len, cs); eta->table_name.copy(table_name_buffer, len, cs);
} }
else if (tab->bush_children) else if (tab->bush_children)
{ {
@ -22593,12 +22593,12 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
sizeof(table_name_buffer)-1, sizeof(table_name_buffer)-1,
"<subquery%d>", "<subquery%d>",
ctab->emb_sj_nest->sj_subq_pred->get_identifier()); ctab->emb_sj_nest->sj_subq_pred->get_identifier());
qpt->table_name.copy(table_name_buffer, len, cs); eta->table_name.copy(table_name_buffer, len, cs);
} }
else else
{ {
TABLE_LIST *real_table= table->pos_in_table_list; TABLE_LIST *real_table= table->pos_in_table_list;
qpt->table_name.copy(real_table->alias, strlen(real_table->alias), cs); eta->table_name.copy(real_table->alias, strlen(real_table->alias), cs);
} }
/* "partitions" column */ /* "partitions" column */
@ -22608,14 +22608,14 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
if (!table->derived_select_number && if (!table->derived_select_number &&
(part_info= table->part_info)) (part_info= table->part_info))
{ {
make_used_partitions_str(part_info, &qpt->used_partitions); make_used_partitions_str(part_info, &eta->used_partitions);
qpt->used_partitions_set= true; eta->used_partitions_set= true;
} }
else else
qpt->used_partitions_set= false; eta->used_partitions_set= false;
#else #else
/* just produce empty column if partitioning is not compiled in */ /* just produce empty column if partitioning is not compiled in */
qpt->used_partitions_set= false; eta->used_partitions_set= false;
#endif #endif
} }
@ -22634,10 +22634,10 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
else else
tab_type= tab->type == JT_ALL ? JT_RANGE : JT_HASH_RANGE; tab_type= tab->type == JT_ALL ? JT_RANGE : JT_HASH_RANGE;
} }
qpt->type= tab_type; eta->type= tab_type;
/* Build "possible_keys" value */ /* Build "possible_keys" value */
append_possible_keys(&qpt->possible_keys_str, table, tab->keys); append_possible_keys(&eta->possible_keys_str, table, tab->keys);
/* Build "key", "key_len", and "ref" */ /* Build "key", "key_len", and "ref" */
if (tab_type == JT_NEXT) if (tab_type == JT_NEXT)
@ -22657,13 +22657,13 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
*/ */
if (tab->select && tab->select->quick && tab_type != JT_CONST) if (tab->select && tab->select->quick && tab_type != JT_CONST)
{ {
qpt->quick_info= new Explain_quick_select; eta->quick_info= new Explain_quick_select;
tab->select->quick->save_info(thd->mem_root, qpt->quick_info); tab->select->quick->save_info(thd->mem_root, eta->quick_info);
} }
if (key_info) /* 'index' or 'ref' access */ if (key_info) /* 'index' or 'ref' access */
{ {
qpt->key.set(thd->mem_root, key_info->name, key_len); eta->key.set(thd->mem_root, key_info->name, key_len);
if (tab->ref.key_parts && tab_type != JT_FT) if (tab->ref.key_parts && tab_type != JT_FT)
{ {
@ -22686,7 +22686,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
if (tab_type == JT_HASH_NEXT) /* full index scan + hash join */ if (tab_type == JT_HASH_NEXT) /* full index scan + hash join */
{ {
qpt->hash_next_key.set(thd->mem_root, eta->hash_next_key.set(thd->mem_root,
table->key_info[tab->index].name, table->key_info[tab->index].name,
table->key_info[tab->index].key_length); table->key_info[tab->index].key_length);
} }
@ -22695,11 +22695,11 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
{ {
if (key_info && tab_type != JT_NEXT) if (key_info && tab_type != JT_NEXT)
{ {
qpt->ref.copy(tmp4); eta->ref.copy(tmp4);
qpt->ref_set= true; eta->ref_set= true;
} }
else else
qpt->ref_set= false; eta->ref_set= false;
} }
else else
{ {
@ -22728,9 +22728,9 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
} }
if (key_name_buf.length()) if (key_name_buf.length())
qpt->key.set(thd->mem_root, key_name_buf.c_ptr_safe(), -1); eta->key.set(thd->mem_root, key_name_buf.c_ptr_safe(), -1);
} }
qpt->ref_set= false; eta->ref_set= false;
} }
/* "rows" */ /* "rows" */
@ -22738,15 +22738,15 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
table_list->schema_table) table_list->schema_table)
{ {
/* I_S tables have rows=extra=NULL */ /* I_S tables have rows=extra=NULL */
qpt->rows_set= false; eta->rows_set= false;
qpt->filtered_set= false; eta->filtered_set= false;
} }
else else
{ {
ha_rows examined_rows= tab->get_examined_rows(); ha_rows examined_rows= tab->get_examined_rows();
qpt->rows_set= true; eta->rows_set= true;
qpt->rows= examined_rows; eta->rows= examined_rows;
/* "filtered" */ /* "filtered" */
float f= 0.0; float f= 0.0;
@ -22759,8 +22759,8 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
f= (float) (100.0 * pushdown_cond_selectivity); f= (float) (100.0 * pushdown_cond_selectivity);
} }
set_if_smaller(f, 100.0); set_if_smaller(f, 100.0);
qpt->filtered_set= true; eta->filtered_set= true;
qpt->filtered= f; eta->filtered= f;
} }
/* Build "Extra" field and save it */ /* Build "Extra" field and save it */
@ -22774,16 +22774,16 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
if (tab->info) if (tab->info)
{ {
qpt->push_extra(tab->info); eta->push_extra(tab->info);
} }
else if (tab->packed_info & TAB_INFO_HAVE_VALUE) else if (tab->packed_info & TAB_INFO_HAVE_VALUE)
{ {
if (tab->packed_info & TAB_INFO_USING_INDEX) if (tab->packed_info & TAB_INFO_USING_INDEX)
qpt->push_extra(ET_USING_INDEX); eta->push_extra(ET_USING_INDEX);
if (tab->packed_info & TAB_INFO_USING_WHERE) if (tab->packed_info & TAB_INFO_USING_WHERE)
qpt->push_extra(ET_USING_WHERE); eta->push_extra(ET_USING_WHERE);
if (tab->packed_info & TAB_INFO_FULL_SCAN_ON_NULL) if (tab->packed_info & TAB_INFO_FULL_SCAN_ON_NULL)
qpt->push_extra(ET_FULL_SCAN_ON_NULL_KEY); eta->push_extra(ET_FULL_SCAN_ON_NULL_KEY);
} }
else else
{ {
@ -22795,23 +22795,23 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
if (keyno != MAX_KEY && keyno == table->file->pushed_idx_cond_keyno && if (keyno != MAX_KEY && keyno == table->file->pushed_idx_cond_keyno &&
table->file->pushed_idx_cond) table->file->pushed_idx_cond)
qpt->push_extra(ET_USING_INDEX_CONDITION); eta->push_extra(ET_USING_INDEX_CONDITION);
else if (tab->cache_idx_cond) else if (tab->cache_idx_cond)
qpt->push_extra(ET_USING_INDEX_CONDITION_BKA); eta->push_extra(ET_USING_INDEX_CONDITION_BKA);
if (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION || if (quick_type == QUICK_SELECT_I::QS_TYPE_ROR_UNION ||
quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT || quick_type == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT ||
quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_INTERSECT || quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_INTERSECT ||
quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE) quick_type == QUICK_SELECT_I::QS_TYPE_INDEX_MERGE)
{ {
qpt->push_extra(ET_USING); eta->push_extra(ET_USING);
} }
if (tab->select) if (tab->select)
{ {
if (tab->use_quick == 2) if (tab->use_quick == 2)
{ {
qpt->push_extra(ET_RANGE_CHECKED_FOR_EACH_RECORD); eta->push_extra(ET_RANGE_CHECKED_FOR_EACH_RECORD);
qpt->range_checked_map= tab->keys; eta->range_checked_map= tab->keys;
} }
else if (tab->select->cond) else if (tab->select->cond)
{ {
@ -22823,7 +22823,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
HA_MUST_USE_TABLE_CONDITION_PUSHDOWN)) && HA_MUST_USE_TABLE_CONDITION_PUSHDOWN)) &&
pushed_cond) pushed_cond)
{ {
qpt->push_extra(ET_USING_WHERE_WITH_PUSHED_CONDITION); eta->push_extra(ET_USING_WHERE_WITH_PUSHED_CONDITION);
/* /*
psergey-todo: what to do? This was useful with NDB only. psergey-todo: what to do? This was useful with NDB only.
@ -22835,7 +22835,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
*/ */
} }
else else
qpt->push_extra(ET_USING_WHERE); eta->push_extra(ET_USING_WHERE);
} }
} }
if (table_list /* SJM bushes don't have table_list */ && if (table_list /* SJM bushes don't have table_list */ &&
@ -22843,20 +22843,20 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
table_list->schema_table->i_s_requested_object & OPTIMIZE_I_S_TABLE) table_list->schema_table->i_s_requested_object & OPTIMIZE_I_S_TABLE)
{ {
if (!table_list->table_open_method) if (!table_list->table_open_method)
qpt->push_extra(ET_SKIP_OPEN_TABLE); eta->push_extra(ET_SKIP_OPEN_TABLE);
else if (table_list->table_open_method == OPEN_FRM_ONLY) else if (table_list->table_open_method == OPEN_FRM_ONLY)
qpt->push_extra(ET_OPEN_FRM_ONLY); eta->push_extra(ET_OPEN_FRM_ONLY);
else else
qpt->push_extra(ET_OPEN_FULL_TABLE); eta->push_extra(ET_OPEN_FULL_TABLE);
/* psergey-note: the following has a bug.*/ /* psergey-note: the following has a bug.*/
if (table_list->has_db_lookup_value && if (table_list->has_db_lookup_value &&
table_list->has_table_lookup_value) table_list->has_table_lookup_value)
qpt->push_extra(ET_SCANNED_0_DATABASES); eta->push_extra(ET_SCANNED_0_DATABASES);
else if (table_list->has_db_lookup_value || else if (table_list->has_db_lookup_value ||
table_list->has_table_lookup_value) table_list->has_table_lookup_value)
qpt->push_extra(ET_SCANNED_1_DATABASE); eta->push_extra(ET_SCANNED_1_DATABASE);
else else
qpt->push_extra(ET_SCANNED_ALL_DATABASES); eta->push_extra(ET_SCANNED_ALL_DATABASES);
} }
if (key_read) if (key_read)
{ {
@ -22864,21 +22864,21 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
{ {
QUICK_GROUP_MIN_MAX_SELECT *qgs= QUICK_GROUP_MIN_MAX_SELECT *qgs=
(QUICK_GROUP_MIN_MAX_SELECT *) tab->select->quick; (QUICK_GROUP_MIN_MAX_SELECT *) tab->select->quick;
qpt->push_extra(ET_USING_INDEX_FOR_GROUP_BY); eta->push_extra(ET_USING_INDEX_FOR_GROUP_BY);
qpt->loose_scan_is_scanning= qgs->loose_scan_is_scanning(); eta->loose_scan_is_scanning= qgs->loose_scan_is_scanning();
} }
else else
qpt->push_extra(ET_USING_INDEX); eta->push_extra(ET_USING_INDEX);
} }
if (table->reginfo.not_exists_optimize) if (table->reginfo.not_exists_optimize)
qpt->push_extra(ET_NOT_EXISTS); eta->push_extra(ET_NOT_EXISTS);
if (quick_type == QUICK_SELECT_I::QS_TYPE_RANGE) if (quick_type == QUICK_SELECT_I::QS_TYPE_RANGE)
{ {
explain_append_mrr_info((QUICK_RANGE_SELECT*)(tab->select->quick), explain_append_mrr_info((QUICK_RANGE_SELECT*)(tab->select->quick),
&qpt->mrr_type); &eta->mrr_type);
if (qpt->mrr_type.length() > 0) if (eta->mrr_type.length() > 0)
qpt->push_extra(ET_USING_MRR); eta->push_extra(ET_USING_MRR);
} }
if (need_tmp_table) if (need_tmp_table)
@ -22893,23 +22893,23 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
} }
if (distinct & test_all_bits(used_tables, if (distinct & test_all_bits(used_tables,
join->select_list_used_tables)) join->select_list_used_tables))
qpt->push_extra(ET_DISTINCT); eta->push_extra(ET_DISTINCT);
if (tab->loosescan_match_tab) if (tab->loosescan_match_tab)
{ {
qpt->push_extra(ET_LOOSESCAN); eta->push_extra(ET_LOOSESCAN);
} }
if (tab->first_weedout_table) if (tab->first_weedout_table)
qpt->push_extra(ET_START_TEMPORARY); eta->push_extra(ET_START_TEMPORARY);
if (tab->check_weed_out_table) if (tab->check_weed_out_table)
qpt->push_extra(ET_END_TEMPORARY); eta->push_extra(ET_END_TEMPORARY);
else if (tab->do_firstmatch) else if (tab->do_firstmatch)
{ {
if (tab->do_firstmatch == /*join->join_tab*/ first_top_tab - 1) if (tab->do_firstmatch == /*join->join_tab*/ first_top_tab - 1)
qpt->push_extra(ET_FIRST_MATCH); eta->push_extra(ET_FIRST_MATCH);
else else
{ {
qpt->push_extra(ET_FIRST_MATCH); eta->push_extra(ET_FIRST_MATCH);
TABLE *prev_table=tab->do_firstmatch->table; TABLE *prev_table=tab->do_firstmatch->table;
if (prev_table->derived_select_number) if (prev_table->derived_select_number)
{ {
@ -22918,10 +22918,10 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
int len= my_snprintf(namebuf, sizeof(namebuf)-1, int len= my_snprintf(namebuf, sizeof(namebuf)-1,
"<derived%u>", "<derived%u>",
prev_table->derived_select_number); prev_table->derived_select_number);
qpt->firstmatch_table_name.append(namebuf, len); eta->firstmatch_table_name.append(namebuf, len);
} }
else else
qpt->firstmatch_table_name.append(prev_table->pos_in_table_list->alias); eta->firstmatch_table_name.append(prev_table->pos_in_table_list->alias);
} }
} }
@ -22929,15 +22929,15 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
{ {
if (tab->ref.cond_guards[part]) if (tab->ref.cond_guards[part])
{ {
qpt->push_extra(ET_FULL_SCAN_ON_NULL_KEY); eta->push_extra(ET_FULL_SCAN_ON_NULL_KEY);
break; break;
} }
} }
if (tab->cache) if (tab->cache)
{ {
qpt->push_extra(ET_USING_JOIN_BUFFER); eta->push_extra(ET_USING_JOIN_BUFFER);
tab->cache->save_explain_data(&qpt->bka_type); tab->cache->save_explain_data(&eta->bka_type);
} }
} }
@ -22963,7 +22963,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
if (!(unit->item && unit->item->eliminated) && // (1) if (!(unit->item && unit->item->eliminated) && // (1)
(!unit->derived || unit->derived->is_materialized_derived())) // (2) (!unit->derived || unit->derived->is_materialized_derived())) // (2)
{ {
qp_node->add_child(unit->first_select()->select_number); explain_node->add_child(unit->first_select()->select_number);
} }
} }
@ -22995,12 +22995,12 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
DBUG_ENTER("select_describe"); DBUG_ENTER("select_describe");
/* Update the QPF with latest values of using_temporary, using_filesort */ /* Update the QPF with latest values of using_temporary, using_filesort */
Explain_select *qp; Explain_select *explain_sel;
uint select_nr= join->select_lex->select_number; uint select_nr= join->select_lex->select_number;
if ((qp= thd->lex->explain->get_select(select_nr))) if ((explain_sel= thd->lex->explain->get_select(select_nr)))
{ {
qp->using_temporary= need_tmp_table; explain_sel->using_temporary= need_tmp_table;
qp->using_filesort= need_order; explain_sel->using_filesort= need_order;
} }
for (SELECT_LEX_UNIT *unit= join->select_lex->first_inner_unit(); for (SELECT_LEX_UNIT *unit= join->select_lex->first_inner_unit();