Commit c0f7efb1 authored by Sergey Petrunya's avatar Sergey Petrunya

Code cleanup

parent d634638c
......@@ -339,7 +339,6 @@ int QPF_table_access::print_explain(select_result_sink *output, uint8 explain_fl
push_str(&item_list, join_type_str[type]);
/* `possible_keys` column */
//push_str(item_list, "TODO");
if (possible_keys_str.length() > 0)
push_string(&item_list, &possible_keys_str);
else
......
......@@ -4191,7 +4191,7 @@ bool st_select_lex::is_merged_child_of(st_select_lex *ancestor)
*/
int LEX::print_explain(select_result_sink *output, uint8 explain_flags,
bool *printed_anything) //TODO: remove printed_anything
bool *printed_anything)
{
int res;
if (query_plan_footprint && query_plan_footprint->have_query_plan())
......@@ -4209,74 +4209,20 @@ int LEX::print_explain(select_result_sink *output, uint8 explain_flags,
/*
*/
void st_select_lex::save_qpf(QPF_query *output)
{
int res;
if (join && join->have_query_plan == JOIN::QEP_AVAILABLE)
{
/*
There is a number of reasons join can be marked as degenerate, so all
three conditions below can happen simultaneously, or individually:
*/
if (!join->table_count || !join->tables_list || join->zero_result_cause)
{
/* It's a degenerate join */
const char *cause= join->zero_result_cause ? join-> zero_result_cause :
"No tables used";
res= join->save_qpf(output, FALSE, FALSE, FALSE, cause);
}
else
{
join->save_qpf(output, join->need_tmp, // need_tmp_table
!join->skip_sort_order && !join->no_order &&
(join->order || join->group_list), // bool need_order
join->select_distinct, // bool distinct
NULL); //const char *message
}
if (res)
goto err;
Save query plan of a UNION. The only variable member is whether the union has
"Using filesort".
for (SELECT_LEX_UNIT *unit= join->select_lex->first_inner_unit();
unit;
unit= unit->next_unit())
{
/*
Display subqueries only if they are not parts of eliminated WHERE/ON
clauses.
*/
if (!(unit->item && unit->item->eliminated))
{
unit->save_qpf(output);
}
}
}
else
{
const char *msg;
if (!join)
DBUG_ASSERT(0); /* Seems not to be possible */
There is also save_union_qpf_part2() function, which is called before we read
UNION's output.
/* Not printing anything useful, don't touch *printed_anything here */
if (join->have_query_plan == JOIN::QEP_NOT_PRESENT_YET)
msg= "Not yet optimized";
else
{
DBUG_ASSERT(join->have_query_plan == JOIN::QEP_DELETED);
msg= "Query plan already deleted";
}
set_explain_type(TRUE/* on_the_fly */);
QPF_select *qp_sel= new (output->mem_root) QPF_select;
qp_sel->select_id= select_number;
qp_sel->select_type= type;
qp_sel->message= msg;
output->add_node(qp_sel);
}
err:
return ;//res;
}
The reason for it is examples like this:
SELECT col1 FROM t1 UNION SELECT col2 FROM t2 ORDER BY (select ... from t3 ...)
Here, the (select ... from t3 ...) subquery must be a child of UNION's
st_select_lex. However, it is not connected as child until a very late
stage in execution.
*/
int st_select_lex_unit::save_union_qpf(QPF_query *output)
{
......@@ -4307,11 +4253,7 @@ int st_select_lex_unit::save_union_qpf(QPF_query *output)
}
for (SELECT_LEX *sl= first; sl; sl= sl->next_select())
{
if (!output->get_select(sl->select_number))
sl->save_qpf(output);
qpfu->add_select(sl->select_number);
}
// Save the UNION node
output->add_node(qpfu);
......@@ -4340,25 +4282,6 @@ int st_select_lex_unit::save_union_qpf_part2(QPF_query *output)
}
int st_select_lex_unit::save_qpf(QPF_query *output)
{
//int res= 0;
SELECT_LEX *first= first_select();
if (!first->next_select())
{
/* This is a 1-way UNION, i.e. not really a UNION */
if (!output->get_select(first->select_number))
first->save_qpf(output);
return 0;
}
save_union_qpf(output);
return 0;
}
/**
A routine used by the parser to decide whether we are specifying a full
partitioning or if only partitions to add or to split.
......
......@@ -732,7 +732,6 @@ public:
List<Item> *get_unit_column_types();
int save_qpf(QPF_query *output);
int save_union_qpf(QPF_query *output);
int save_union_qpf_part2(QPF_query *output);
};
......@@ -1053,11 +1052,7 @@ public:
bool save_prep_leaf_tables(THD *thd);
bool is_merged_child_of(st_select_lex *ancestor);
#if 0
int print_explain(select_result_sink *output, uint8 explain_flags,
bool *printed_anything);
#endif
void save_qpf(QPF_query *output);
/*
For MODE_ONLY_FULL_GROUP_BY we need to maintain two flags:
- Non-aggregated fields are used in this select.
......
......@@ -22464,7 +22464,7 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
const CHARSET_INFO *cs= system_charset_info;
int quick_type;
int error= 0;
DBUG_ENTER("JOIN::print_explain");
DBUG_ENTER("JOIN::save_qpf");
DBUG_PRINT("info", ("Select 0x%lx, type %s, message %s",
(ulong)join->select_lex, join->select_lex->type,
message ? message : "NULL"));
......@@ -22920,14 +22920,6 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
if (table->reginfo.not_exists_optimize)
qpt->push_extra(ET_NOT_EXISTS);
/*
if (quick_type == QUICK_SELECT_I::QS_TYPE_RANGE &&
!(((QUICK_RANGE_SELECT*)(tab->select->quick))->mrr_flags &
HA_MRR_USE_DEFAULT_IMPL))
{
extra.append(STRING_WITH_LEN("; Using MRR"));
}
*/
if (quick_type == QUICK_SELECT_I::QS_TYPE_RANGE)
{
explain_append_mrr_info((QUICK_RANGE_SELECT*)(tab->select->quick),
......@@ -22940,13 +22932,11 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
{
need_tmp_table=0;
qp_sel->using_temporary= true;
///extra.append(STRING_WITH_LEN("; Using temporary"));
}
if (need_order)
{
need_order=0;
qp_sel->using_filesort= true;
///extra.append(STRING_WITH_LEN("; Using filesort"));
}
if (distinct & test_all_bits(used_tables,
join->select_list_used_tables))
......@@ -22968,11 +22958,6 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
{
qpt->push_extra(ET_FIRST_MATCH);
TABLE *prev_table=tab->do_firstmatch->table;
/*
TODO: qpt->firstmatch_table...
This must be a reference to another QPF element. Or, its index.
*/
// extra.append(STRING_WITH_LEN("; FirstMatch("));
if (prev_table->derived_select_number)
{
char namebuf[NAME_LEN];
......@@ -22984,7 +22969,6 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
}
else
qpt->firstmatch_table_name.append(prev_table->pos_in_table_list->alias);
//extra.append(STRING_WITH_LEN(")"));
}
}
......@@ -23033,11 +23017,21 @@ int JOIN::save_qpf(QPF_query *output, bool need_tmp_table, bool need_order,
DBUG_RETURN(error);
}
//////////////////////////////////////////////////////////////////////////////////////////////
/*
See st_select_lex::print_explain() for the SHOW EXPLAIN counterpart
This function servers as "shortcut point" for EXPLAIN queries.
For UNIONs and JOINs, EXPLAIN statement executes just like its SELECT
statement would execute, except that JOIN::exec() will call select_describe()
instead of actually executing the query.
The purpose of select_describe() is:
- update the query plan with info about last-minute choices made at the start
of JOIN::exec
- Invoke "pseudo-execution" for the children subqueries.
Overall, select_describe() is a legacy of old EXPLAIN implementation and
should be removed.
*/
static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
......@@ -23055,12 +23049,6 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order,
qp->using_filesort= need_order;
}
/*
WE DONT NEED THIS here anymore:
join->save_qpf(thd->lex->query_plan_footprint, need_tmp_table, need_order,
distinct, message);
*/
for (SELECT_LEX_UNIT *unit= join->select_lex->first_inner_unit();
unit;
unit= unit->next_unit())
......
......@@ -1023,7 +1023,6 @@ exit_without_my_ok:
List<Item> dummy; /* note: looked in 5.6 and they too use a dummy list like this */
result->prepare(dummy, &thd->lex->unit);
thd->send_explain_fields(result);
//int err2= thd->lex->print_explain(result, 0 /* explain flags*/, &printed_anything);
int err2= thd->lex->query_plan_footprint->print_explain(result, 0 /* explain flags*/);
if (err2)
......
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