summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sql/opt_range.cc114
-rw-r--r--sql/opt_range.h14
-rw-r--r--sql/sql_explain.h5
-rw-r--r--sql/sql_select.cc3
4 files changed, 81 insertions, 55 deletions
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index cee72be7bda..eec15ed93f9 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -11940,110 +11940,134 @@ void QUICK_SELECT_I::add_key_name(String *str, bool *first)
}
-void QUICK_RANGE_SELECT::save_info(MEM_ROOT *alloc,
- Explain_quick_select *explain)
+Explain_quick_select* QUICK_RANGE_SELECT::get_explain(MEM_ROOT *alloc)
{
- explain->quick_type= QS_TYPE_RANGE;
- explain->range.set(alloc, head->key_info[index].name, max_used_key_length);
+ Explain_quick_select *res;
+ if ((res= new (alloc) Explain_quick_select(QS_TYPE_RANGE)))
+ res->range.set(alloc, head->key_info[index].name, max_used_key_length);
+ return res;
}
-void QUICK_GROUP_MIN_MAX_SELECT::save_info(MEM_ROOT *alloc,
- Explain_quick_select *explain)
+Explain_quick_select* QUICK_GROUP_MIN_MAX_SELECT::get_explain(MEM_ROOT *alloc)
{
- explain->quick_type= QS_TYPE_GROUP_MIN_MAX;
- explain->range.set(alloc, head->key_info[index].name, max_used_key_length);
+ Explain_quick_select *res;
+ if ((res= new (alloc) Explain_quick_select(QS_TYPE_GROUP_MIN_MAX)))
+ res->range.set(alloc, head->key_info[index].name, max_used_key_length);
+ return res;
}
-void QUICK_INDEX_SORT_SELECT::save_info(MEM_ROOT *alloc,
- Explain_quick_select *explain)
+Explain_quick_select* QUICK_INDEX_SORT_SELECT::get_explain(MEM_ROOT *alloc)
{
- explain->quick_type= get_type();
+ Explain_quick_select *res;
+ if (!(res= new (alloc) Explain_quick_select(get_type())))
+ return NULL;
QUICK_RANGE_SELECT *quick;
- Explain_quick_select *child_qpf;
+ Explain_quick_select *child_explain;
List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects);
while ((quick= it++))
{
- child_qpf= new Explain_quick_select;
- explain->children.push_back(child_qpf);
- quick->save_info(alloc, child_qpf);
+ if ((child_explain= quick->get_explain(alloc)))
+ res->children.push_back(child_explain);
+ else
+ return NULL;
}
if (pk_quick_select)
{
- child_qpf= new Explain_quick_select;
- explain->children.push_back(child_qpf);
- pk_quick_select->save_info(alloc, child_qpf);
+ if ((child_explain= pk_quick_select->get_explain(alloc)))
+ res->children.push_back(child_explain);
+ else
+ return NULL;
}
+ return res;
}
+
/*
- Same as QUICK_INDEX_SORT_SELECT::save_info(), but primary key is printed
+ Same as QUICK_INDEX_SORT_SELECT::get_explain(), but primary key is printed
first
*/
-void QUICK_INDEX_INTERSECT_SELECT::save_info(MEM_ROOT *alloc,
- Explain_quick_select *explain)
+
+Explain_quick_select* QUICK_INDEX_INTERSECT_SELECT::get_explain(MEM_ROOT *alloc)
{
- explain->quick_type= get_type();
- Explain_quick_select *child_qpf;
+ Explain_quick_select *res;
+ Explain_quick_select *child_explain;
+
+ if (!(res= new (alloc) Explain_quick_select(get_type())))
+ return NULL;
if (pk_quick_select)
{
- child_qpf= new Explain_quick_select;
- explain->children.push_back(child_qpf);
- pk_quick_select->save_info(alloc, child_qpf);
+ if ((child_explain= pk_quick_select->get_explain(alloc)))
+ res->children.push_back(child_explain);
+ else
+ return NULL;
}
QUICK_RANGE_SELECT *quick;
List_iterator_fast<QUICK_RANGE_SELECT> it(quick_selects);
while ((quick= it++))
{
- child_qpf= new Explain_quick_select;
- explain->children.push_back(child_qpf);
- quick->save_info(alloc, child_qpf);
+ if ((child_explain= quick->get_explain(alloc)))
+ res->children.push_back(child_explain);
+ else
+ return NULL;
}
-
+ return res;
}
-void QUICK_ROR_INTERSECT_SELECT::save_info(MEM_ROOT *alloc,
- Explain_quick_select *explain)
+Explain_quick_select* QUICK_ROR_INTERSECT_SELECT::get_explain(MEM_ROOT *alloc)
{
- explain->quick_type= get_type();
+ Explain_quick_select *res;
+ Explain_quick_select *child_explain;
+
+ if (!(res= new (alloc) Explain_quick_select(get_type())))
+ return NULL;
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;
- explain->children.push_back(child_qpf);
- qr->quick->save_info(alloc, child_qpf);
+ if ((child_explain= qr->quick->get_explain(alloc)))
+ res->children.push_back(child_explain);
+ else
+ return NULL;
}
if (cpk_quick)
{
- Explain_quick_select *child_qpf= new Explain_quick_select;
- explain->children.push_back(child_qpf);
- cpk_quick->save_info(alloc, child_qpf);
+ if ((child_explain= cpk_quick->get_explain(alloc)))
+ res->children.push_back(child_explain);
+ else
+ return NULL;
}
+ return res;
}
-void QUICK_ROR_UNION_SELECT::save_info(MEM_ROOT *alloc,
- Explain_quick_select *explain)
+Explain_quick_select* QUICK_ROR_UNION_SELECT::get_explain(MEM_ROOT *alloc)
{
- explain->quick_type= get_type();
+ Explain_quick_select *res;
+ Explain_quick_select *child_explain;
+
+ if (!(res= new (alloc) Explain_quick_select(get_type())))
+ return NULL;
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;
- explain->children.push_back(child_qpf);
- quick->save_info(alloc, child_qpf);
+ if ((child_explain= quick->get_explain(alloc)))
+ res->children.push_back(child_explain);
+ else
+ return NULL;
}
+
+ return res;
}
diff --git a/sql/opt_range.h b/sql/opt_range.h
index 23274466990..29bb9ed88ff 100644
--- a/sql/opt_range.h
+++ b/sql/opt_range.h
@@ -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 *explain)= 0;
+ virtual Explain_quick_select* get_explain(MEM_ROOT *alloc)= 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 *explain);
+ Explain_quick_select *get_explain(MEM_ROOT *alloc);
#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 *explain);
+ Explain_quick_select *get_explain(MEM_ROOT *alloc);
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 *explain);
+ Explain_quick_select *get_explain(MEM_ROOT *alloc);
};
@@ -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 *explain);
+ Explain_quick_select *get_explain(MEM_ROOT *alloc);
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 *explain);
+ Explain_quick_select *get_explain(MEM_ROOT *alloc);
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 *explain);
+ Explain_quick_select *get_explain(MEM_ROOT *alloc);
};
diff --git a/sql/sql_explain.h b/sql/sql_explain.h
index 87ae29678e9..1eea61d98fb 100644
--- a/sql/sql_explain.h
+++ b/sql/sql_explain.h
@@ -341,7 +341,10 @@ public:
class Explain_quick_select : public Sql_alloc
{
public:
- int quick_type;
+ Explain_quick_select(int quick_type_arg) : quick_type(quick_type_arg)
+ {}
+
+ const int quick_type;
/* This is used when quick_type == QUICK_SELECT_I::QS_TYPE_RANGE */
Explain_index_use range;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index c787d659e36..00a9eb53fb9 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -22657,8 +22657,7 @@ int JOIN::save_explain_data(Explain_query *output, bool need_tmp_table,
*/
if (tab->select && tab->select->quick && tab_type != JT_CONST)
{
- eta->quick_info= new Explain_quick_select;
- tab->select->quick->save_info(thd->mem_root, eta->quick_info);
+ eta->quick_info= tab->select->quick->get_explain(thd->mem_root);
}
if (key_info) /* 'index' or 'ref' access */