mirror of
https://github.com/MariaDB/server.git
synced 2025-08-05 13:16:09 +03:00
Merge 10.10 into 10.11
This commit is contained in:
@@ -39,8 +39,8 @@ const char *unit_operation_text[4]=
|
||||
const char *pushed_derived_text= "PUSHED DERIVED";
|
||||
const char *pushed_select_text= "PUSHED SELECT";
|
||||
|
||||
static void write_item(Json_writer *writer, Item *item, bool no_tmp_tbl);
|
||||
static void append_item_to_str(String *out, Item *item, bool no_tmp_tbl);
|
||||
static void write_item(Json_writer *writer, Item *item);
|
||||
static void append_item_to_str(String *out, Item *item);
|
||||
|
||||
Explain_query::Explain_query(THD *thd_arg, MEM_ROOT *root) :
|
||||
mem_root(root), upd_del_plan(nullptr), insert_plan(nullptr),
|
||||
@@ -199,7 +199,7 @@ int Explain_query::send_explain(THD *thd, bool extended)
|
||||
|
||||
int res= 0;
|
||||
if (thd->lex->explain_json)
|
||||
print_explain_json(result, thd->lex->analyze_stmt, false /*is_show_cmd*/);
|
||||
print_explain_json(result, thd->lex->analyze_stmt);
|
||||
else
|
||||
{
|
||||
res= print_explain(result, lex->describe, thd->lex->analyze_stmt);
|
||||
@@ -255,16 +255,8 @@ int Explain_query::print_explain(select_result_sink *output,
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@param is_show_cmd TRUE<=> This is a SHOW EXPLAIN|ANALYZE command.
|
||||
(These commands may be called at late stage in
|
||||
the query processing, we need to pass no_tmp_tbl=true
|
||||
to other print functions)
|
||||
*/
|
||||
|
||||
int Explain_query::print_explain_json(select_result_sink *output,
|
||||
bool is_analyze,
|
||||
bool is_show_cmd,
|
||||
ulonglong query_time_in_progress_ms)
|
||||
{
|
||||
Json_writer writer;
|
||||
@@ -274,12 +266,7 @@ int Explain_query::print_explain_json(select_result_sink *output,
|
||||
#endif
|
||||
|
||||
writer.start_object();
|
||||
|
||||
/*
|
||||
If we are printing ANALYZE FORMAT=JSON output, take into account that
|
||||
query's temporary tables have already been freed. See sql_explain.h,
|
||||
sql_explain.h:ExplainDataStructureLifetime for details.
|
||||
*/
|
||||
|
||||
if (is_analyze)
|
||||
{
|
||||
if (query_time_in_progress_ms > 0){
|
||||
@@ -288,11 +275,9 @@ int Explain_query::print_explain_json(select_result_sink *output,
|
||||
}
|
||||
|
||||
print_query_optimization_json(&writer);
|
||||
is_show_cmd = true;
|
||||
}
|
||||
|
||||
bool plan_found = print_query_blocks_json(&writer, is_analyze, is_show_cmd);
|
||||
|
||||
bool plan_found = print_query_blocks_json(&writer, is_analyze);
|
||||
writer.end_object();
|
||||
|
||||
if( plan_found )
|
||||
@@ -316,21 +301,19 @@ void Explain_query::print_query_optimization_json(Json_writer *writer)
|
||||
}
|
||||
}
|
||||
|
||||
bool Explain_query::print_query_blocks_json(Json_writer *writer,
|
||||
const bool is_analyze,
|
||||
const bool is_show_cmd)
|
||||
bool Explain_query::print_query_blocks_json(Json_writer *writer, const bool is_analyze)
|
||||
{
|
||||
if (upd_del_plan)
|
||||
upd_del_plan->print_explain_json(this, writer, is_analyze, is_show_cmd);
|
||||
upd_del_plan->print_explain_json(this, writer, is_analyze);
|
||||
else if (insert_plan)
|
||||
insert_plan->print_explain_json(this, writer, is_analyze, is_show_cmd);
|
||||
insert_plan->print_explain_json(this, writer, is_analyze);
|
||||
else
|
||||
{
|
||||
/* Start printing from root node with id=1 */
|
||||
Explain_node *node= get_node(1);
|
||||
if (!node)
|
||||
return false; /* No query plan */
|
||||
node->print_explain_json(this, writer, is_analyze, is_show_cmd);
|
||||
node->print_explain_json(this, writer, is_analyze);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -695,8 +678,7 @@ int Explain_union::print_explain(Explain_query *query,
|
||||
|
||||
|
||||
void Explain_union::print_explain_json(Explain_query *query,
|
||||
Json_writer *writer, bool is_analyze,
|
||||
bool no_tmp_tbl)
|
||||
Json_writer *writer, bool is_analyze)
|
||||
{
|
||||
Json_writer_nesting_guard guard(writer);
|
||||
char table_name_buffer[SAFE_NAME_LEN];
|
||||
@@ -741,12 +723,12 @@ void Explain_union::print_explain_json(Explain_query *query,
|
||||
//writer->add_member("dependent").add_str("TODO");
|
||||
//writer->add_member("cacheable").add_str("TODO");
|
||||
Explain_select *sel= query->get_select(union_members.at(i));
|
||||
sel->print_explain_json(query, writer, is_analyze, no_tmp_tbl);
|
||||
sel->print_explain_json(query, writer, is_analyze);
|
||||
writer->end_object();
|
||||
}
|
||||
writer->end_array();
|
||||
|
||||
print_explain_json_for_children(query, writer, is_analyze, no_tmp_tbl);
|
||||
print_explain_json_for_children(query, writer, is_analyze);
|
||||
|
||||
writer->end_object(); // union_result
|
||||
writer->end_object(); // query_block
|
||||
@@ -808,8 +790,7 @@ bool is_connection_printable_in_json(enum Explain_node::explain_connection_type
|
||||
|
||||
void Explain_node::print_explain_json_for_children(Explain_query *query,
|
||||
Json_writer *writer,
|
||||
bool is_analyze,
|
||||
bool no_tmp_tbl)
|
||||
bool is_analyze)
|
||||
{
|
||||
Json_writer_nesting_guard guard(writer);
|
||||
|
||||
@@ -836,7 +817,7 @@ void Explain_node::print_explain_json_for_children(Explain_query *query,
|
||||
}
|
||||
|
||||
writer->start_object();
|
||||
node->print_explain_json(query, writer, is_analyze, no_tmp_tbl);
|
||||
node->print_explain_json(query, writer, is_analyze);
|
||||
writer->end_object();
|
||||
}
|
||||
|
||||
@@ -1016,8 +997,7 @@ void Explain_select::add_linkage(Json_writer *writer)
|
||||
}
|
||||
|
||||
void Explain_select::print_explain_json(Explain_query *query,
|
||||
Json_writer *writer, bool is_analyze,
|
||||
bool no_tmp_tbl)
|
||||
Json_writer *writer, bool is_analyze)
|
||||
{
|
||||
Json_writer_nesting_guard guard(writer);
|
||||
|
||||
@@ -1039,7 +1019,7 @@ void Explain_select::print_explain_json(Explain_query *query,
|
||||
message);
|
||||
writer->end_object();
|
||||
|
||||
print_explain_json_for_children(query, writer, is_analyze, no_tmp_tbl);
|
||||
print_explain_json_for_children(query, writer, is_analyze);
|
||||
writer->end_object();
|
||||
}
|
||||
else
|
||||
@@ -1061,17 +1041,17 @@ void Explain_select::print_explain_json(Explain_query *query,
|
||||
if (exec_const_cond)
|
||||
{
|
||||
writer->add_member("const_condition");
|
||||
write_item(writer, exec_const_cond, no_tmp_tbl);
|
||||
write_item(writer, exec_const_cond);
|
||||
}
|
||||
if (outer_ref_cond)
|
||||
{
|
||||
writer->add_member("outer_ref_condition");
|
||||
write_item(writer, outer_ref_cond, no_tmp_tbl);
|
||||
write_item(writer, outer_ref_cond);
|
||||
}
|
||||
if (pseudo_bits_cond)
|
||||
{
|
||||
writer->add_member("pseudo_bits_condition");
|
||||
write_item(writer, pseudo_bits_cond, no_tmp_tbl);
|
||||
write_item(writer, pseudo_bits_cond);
|
||||
}
|
||||
|
||||
/* we do not print HAVING which always evaluates to TRUE */
|
||||
@@ -1079,7 +1059,7 @@ void Explain_select::print_explain_json(Explain_query *query,
|
||||
{
|
||||
writer->add_member("having_condition");
|
||||
if (likely(having))
|
||||
write_item(writer, having, no_tmp_tbl);
|
||||
write_item(writer, having);
|
||||
else
|
||||
{
|
||||
/* Normally we should not go this branch, left just for safety */
|
||||
@@ -1103,7 +1083,7 @@ void Explain_select::print_explain_json(Explain_query *query,
|
||||
{
|
||||
writer->add_member("filesort").start_object();
|
||||
auto aggr_node= (Explain_aggr_filesort*)node;
|
||||
aggr_node->print_json_members(writer, is_analyze, no_tmp_tbl);
|
||||
aggr_node->print_json_members(writer, is_analyze);
|
||||
break;
|
||||
}
|
||||
case AGGR_OP_REMOVE_DUPLICATES:
|
||||
@@ -1114,7 +1094,7 @@ void Explain_select::print_explain_json(Explain_query *query,
|
||||
//TODO: make print_json_members virtual?
|
||||
writer->add_member("window_functions_computation").start_object();
|
||||
auto aggr_node= (Explain_aggr_window_funcs*)node;
|
||||
aggr_node->print_json_members(writer, is_analyze, no_tmp_tbl);
|
||||
aggr_node->print_json_members(writer, is_analyze);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -1123,8 +1103,7 @@ void Explain_select::print_explain_json(Explain_query *query,
|
||||
started_objects++;
|
||||
}
|
||||
|
||||
Explain_basic_join::print_explain_json_interns(query, writer, is_analyze,
|
||||
no_tmp_tbl);
|
||||
Explain_basic_join::print_explain_json_interns(query, writer, is_analyze);
|
||||
|
||||
for (;started_objects; started_objects--)
|
||||
writer->end_object();
|
||||
@@ -1153,8 +1132,7 @@ Explain_aggr_filesort::Explain_aggr_filesort(MEM_ROOT *mem_root,
|
||||
|
||||
|
||||
void Explain_aggr_filesort::print_json_members(Json_writer *writer,
|
||||
bool is_analyze,
|
||||
bool no_tmp_tbl)
|
||||
bool is_analyze)
|
||||
{
|
||||
char item_buf[256];
|
||||
String str(item_buf, sizeof(item_buf), &my_charset_bin);
|
||||
@@ -1174,7 +1152,7 @@ void Explain_aggr_filesort::print_json_members(Json_writer *writer,
|
||||
{
|
||||
str.append(STRING_WITH_LEN(", "));
|
||||
}
|
||||
append_item_to_str(&str, item, no_tmp_tbl);
|
||||
append_item_to_str(&str, item);
|
||||
if (*direction == ORDER::ORDER_DESC)
|
||||
str.append(STRING_WITH_LEN(" desc"));
|
||||
}
|
||||
@@ -1187,8 +1165,7 @@ void Explain_aggr_filesort::print_json_members(Json_writer *writer,
|
||||
|
||||
|
||||
void Explain_aggr_window_funcs::print_json_members(Json_writer *writer,
|
||||
bool is_analyze,
|
||||
bool no_tmp_tbl)
|
||||
bool is_analyze)
|
||||
{
|
||||
Explain_aggr_filesort *srt;
|
||||
List_iterator<Explain_aggr_filesort> it(sorts);
|
||||
@@ -1197,19 +1174,19 @@ void Explain_aggr_window_funcs::print_json_members(Json_writer *writer,
|
||||
{
|
||||
Json_writer_object sort(writer);
|
||||
Json_writer_object filesort(writer, "filesort");
|
||||
srt->print_json_members(writer, is_analyze, no_tmp_tbl);
|
||||
srt->print_json_members(writer, is_analyze);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Explain_basic_join::print_explain_json(Explain_query *query,
|
||||
Json_writer *writer,
|
||||
bool is_analyze, bool no_tmp_tbl)
|
||||
bool is_analyze)
|
||||
{
|
||||
writer->add_member("query_block").start_object();
|
||||
writer->add_member("select_id").add_ll(select_id);
|
||||
|
||||
print_explain_json_interns(query, writer, is_analyze, no_tmp_tbl);
|
||||
print_explain_json_interns(query, writer, is_analyze);
|
||||
|
||||
writer->end_object();
|
||||
}
|
||||
@@ -1218,7 +1195,7 @@ void Explain_basic_join::print_explain_json(Explain_query *query,
|
||||
void Explain_basic_join::
|
||||
print_explain_json_interns(Explain_query *query,
|
||||
Json_writer *writer,
|
||||
bool is_analyze, bool no_tmp_tbl)
|
||||
bool is_analyze)
|
||||
{
|
||||
{
|
||||
Json_writer_array loop(writer, "nested_loop");
|
||||
@@ -1231,7 +1208,7 @@ print_explain_json_interns(Explain_query *query,
|
||||
writer->start_array();
|
||||
}
|
||||
|
||||
join_tabs[i]->print_explain_json(query, writer, is_analyze, no_tmp_tbl);
|
||||
join_tabs[i]->print_explain_json(query, writer, is_analyze);
|
||||
|
||||
if (join_tabs[i]->end_dups_weedout)
|
||||
{
|
||||
@@ -1240,7 +1217,7 @@ print_explain_json_interns(Explain_query *query,
|
||||
}
|
||||
}
|
||||
} // "nested_loop"
|
||||
print_explain_json_for_children(query, writer, is_analyze, no_tmp_tbl);
|
||||
print_explain_json_for_children(query, writer, is_analyze);
|
||||
}
|
||||
|
||||
|
||||
@@ -1640,7 +1617,7 @@ const char *String_list::append_str(MEM_ROOT *mem_root, const char *str)
|
||||
}
|
||||
|
||||
|
||||
static void write_item(Json_writer *writer, Item *item, bool no_tmp_tbl)
|
||||
static void write_item(Json_writer *writer, Item *item)
|
||||
{
|
||||
THD *thd= current_thd;
|
||||
char item_buf[256];
|
||||
@@ -1650,27 +1627,25 @@ static void write_item(Json_writer *writer, Item *item, bool no_tmp_tbl)
|
||||
ulonglong save_option_bits= thd->variables.option_bits;
|
||||
thd->variables.option_bits &= ~OPTION_QUOTE_SHOW_CREATE;
|
||||
|
||||
auto qtype= QT_EXPLAIN | (no_tmp_tbl? QT_DONT_ACCESS_TMP_TABLES : 0);
|
||||
item->print(&str, (enum_query_type)qtype);
|
||||
item->print(&str, QT_EXPLAIN);
|
||||
|
||||
thd->variables.option_bits= save_option_bits;
|
||||
writer->add_str(str.c_ptr_safe());
|
||||
}
|
||||
|
||||
static void append_item_to_str(String *out, Item *item, bool no_tmp_tbl)
|
||||
static void append_item_to_str(String *out, Item *item)
|
||||
{
|
||||
THD *thd= current_thd;
|
||||
ulonglong save_option_bits= thd->variables.option_bits;
|
||||
thd->variables.option_bits &= ~OPTION_QUOTE_SHOW_CREATE;
|
||||
|
||||
auto qtype= QT_EXPLAIN | (no_tmp_tbl? QT_DONT_ACCESS_TMP_TABLES : 0);
|
||||
item->print(out, (enum_query_type)qtype);
|
||||
item->print(out, QT_EXPLAIN);
|
||||
|
||||
thd->variables.option_bits= save_option_bits;
|
||||
}
|
||||
|
||||
void Explain_table_access::tag_to_json(Json_writer *writer,
|
||||
enum explain_extra_tag tag,
|
||||
bool no_tmp_tbl)
|
||||
enum explain_extra_tag tag)
|
||||
{
|
||||
switch (tag)
|
||||
{
|
||||
@@ -1694,11 +1669,11 @@ void Explain_table_access::tag_to_json(Json_writer *writer,
|
||||
break;
|
||||
case ET_USING_INDEX_CONDITION:
|
||||
writer->add_member("index_condition");
|
||||
write_item(writer, pushed_index_cond, no_tmp_tbl);
|
||||
write_item(writer, pushed_index_cond);
|
||||
break;
|
||||
case ET_USING_INDEX_CONDITION_BKA:
|
||||
writer->add_member("index_condition_bka");
|
||||
write_item(writer, pushed_index_cond, no_tmp_tbl);
|
||||
write_item(writer, pushed_index_cond);
|
||||
break;
|
||||
case ET_USING_WHERE:
|
||||
{
|
||||
@@ -1712,7 +1687,7 @@ void Explain_table_access::tag_to_json(Json_writer *writer,
|
||||
if (item)
|
||||
{
|
||||
writer->add_member("attached_condition");
|
||||
write_item(writer, item, no_tmp_tbl);
|
||||
write_item(writer, item);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1846,7 +1821,7 @@ static void trace_engine_stats(handler *file, Json_writer *writer)
|
||||
|
||||
void Explain_table_access::print_explain_json(Explain_query *query,
|
||||
Json_writer *writer,
|
||||
bool is_analyze, bool no_tmp_tbl)
|
||||
bool is_analyze)
|
||||
{
|
||||
Json_writer_object jsobj(writer);
|
||||
|
||||
@@ -1877,7 +1852,7 @@ void Explain_table_access::print_explain_json(Explain_query *query,
|
||||
}
|
||||
}
|
||||
writer->add_member("filesort").start_object();
|
||||
pre_join_sort->print_json_members(writer, is_analyze, no_tmp_tbl);
|
||||
pre_join_sort->print_json_members(writer, is_analyze);
|
||||
}
|
||||
|
||||
if (bka_type.is_using_jbuf())
|
||||
@@ -2015,7 +1990,7 @@ void Explain_table_access::print_explain_json(Explain_query *query,
|
||||
|
||||
for (int i=0; i < (int)extra_tags.elements(); i++)
|
||||
{
|
||||
tag_to_json(writer, extra_tags.at(i), no_tmp_tbl);
|
||||
tag_to_json(writer, extra_tags.at(i));
|
||||
}
|
||||
|
||||
if (full_scan_on_null_key)
|
||||
@@ -2036,7 +2011,7 @@ void Explain_table_access::print_explain_json(Explain_query *query,
|
||||
if (where_cond)
|
||||
{
|
||||
writer->add_member("attached_condition");
|
||||
write_item(writer, where_cond, no_tmp_tbl);
|
||||
write_item(writer, where_cond);
|
||||
}
|
||||
|
||||
if (is_analyze)
|
||||
@@ -2083,7 +2058,7 @@ void Explain_table_access::print_explain_json(Explain_query *query,
|
||||
{
|
||||
writer->add_member("lateral").add_ll(1);
|
||||
}
|
||||
node->print_explain_json(query, writer, is_analyze, no_tmp_tbl);
|
||||
node->print_explain_json(query, writer, is_analyze);
|
||||
writer->end_object();
|
||||
}
|
||||
if (non_merged_sjm_number)
|
||||
@@ -2093,7 +2068,7 @@ void Explain_table_access::print_explain_json(Explain_query *query,
|
||||
writer->add_member("unique").add_ll(1);
|
||||
Explain_node *node= query->get_node(non_merged_sjm_number);
|
||||
node->connection_type= Explain_node::EXPLAIN_NODE_NON_MERGED_SJ;
|
||||
node->print_explain_json(query, writer, is_analyze, no_tmp_tbl);
|
||||
node->print_explain_json(query, writer, is_analyze);
|
||||
writer->end_object();
|
||||
}
|
||||
if (sjm_nest)
|
||||
@@ -2101,7 +2076,7 @@ void Explain_table_access::print_explain_json(Explain_query *query,
|
||||
/* This is a non-merged semi-join table. Print its contents here */
|
||||
writer->add_member("materialized").start_object();
|
||||
writer->add_member("unique").add_ll(1);
|
||||
sjm_nest->print_explain_json(query, writer, is_analyze, no_tmp_tbl);
|
||||
sjm_nest->print_explain_json(query, writer, is_analyze);
|
||||
writer->end_object();
|
||||
}
|
||||
|
||||
@@ -2407,8 +2382,7 @@ int Explain_delete::print_explain(Explain_query *query,
|
||||
|
||||
void Explain_delete::print_explain_json(Explain_query *query,
|
||||
Json_writer *writer,
|
||||
bool is_analyze,
|
||||
bool no_tmp_tbl)
|
||||
bool is_analyze)
|
||||
{
|
||||
Json_writer_nesting_guard guard(writer);
|
||||
|
||||
@@ -2423,7 +2397,7 @@ void Explain_delete::print_explain_json(Explain_query *query,
|
||||
writer->end_object(); // query_block
|
||||
return;
|
||||
}
|
||||
Explain_update::print_explain_json(query, writer, is_analyze, no_tmp_tbl);
|
||||
Explain_update::print_explain_json(query, writer, is_analyze);
|
||||
}
|
||||
|
||||
|
||||
@@ -2526,8 +2500,7 @@ int Explain_update::print_explain(Explain_query *query,
|
||||
|
||||
void Explain_update::print_explain_json(Explain_query *query,
|
||||
Json_writer *writer,
|
||||
bool is_analyze,
|
||||
bool no_tmp_tbl)
|
||||
bool is_analyze)
|
||||
{
|
||||
Json_writer_nesting_guard guard(writer);
|
||||
|
||||
@@ -2694,7 +2667,7 @@ void Explain_update::print_explain_json(Explain_query *query,
|
||||
if (where_cond)
|
||||
{
|
||||
writer->add_member("attached_condition");
|
||||
write_item(writer, where_cond, no_tmp_tbl);
|
||||
write_item(writer, where_cond);
|
||||
}
|
||||
|
||||
/*** The part of plan that is before the buffering/sorting ends here ***/
|
||||
@@ -2706,7 +2679,7 @@ void Explain_update::print_explain_json(Explain_query *query,
|
||||
|
||||
writer->end_object(); // table
|
||||
|
||||
print_explain_json_for_children(query, writer, is_analyze, no_tmp_tbl);
|
||||
print_explain_json_for_children(query, writer, is_analyze);
|
||||
writer->end_object(); // query_block
|
||||
}
|
||||
|
||||
@@ -2736,8 +2709,7 @@ int Explain_insert::print_explain(Explain_query *query,
|
||||
}
|
||||
|
||||
void Explain_insert::print_explain_json(Explain_query *query,
|
||||
Json_writer *writer, bool is_analyze,
|
||||
bool no_tmp_tbl)
|
||||
Json_writer *writer, bool is_analyze)
|
||||
{
|
||||
Json_writer_nesting_guard guard(writer);
|
||||
|
||||
@@ -2746,7 +2718,7 @@ void Explain_insert::print_explain_json(Explain_query *query,
|
||||
writer->add_member("table").start_object();
|
||||
writer->add_member("table_name").add_str(table_name.c_ptr());
|
||||
writer->end_object(); // table
|
||||
print_explain_json_for_children(query, writer, is_analyze, no_tmp_tbl);
|
||||
print_explain_json_for_children(query, writer, is_analyze);
|
||||
writer->end_object(); // query_block
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user