diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/opt_trace.cc | 40 | ||||
-rw-r--r-- | sql/opt_trace.h | 3 | ||||
-rw-r--r-- | sql/sql_select.cc | 6 |
3 files changed, 34 insertions, 15 deletions
diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc index d7b3d83bb18..01819314bb3 100644 --- a/sql/opt_trace.cc +++ b/sql/opt_trace.cc @@ -562,13 +562,10 @@ void Opt_trace_stmt::set_allowed_mem_size(size_t mem_size) current_json->set_size_limit(mem_size); } -/* - Prefer this when you are iterating over JOIN_TABs -*/ -void Json_writer::add_table_name(const JOIN_TAB *tab) +void get_table_name_for_trace(const JOIN_TAB *tab, String *out) { - char table_name_buffer[SAFE_NAME_LEN]; + char table_name_buffer[64]; DBUG_ASSERT(tab != NULL); DBUG_ASSERT(tab->join->thd->trace_started()); @@ -578,7 +575,7 @@ void Json_writer::add_table_name(const JOIN_TAB *tab) size_t len= my_snprintf(table_name_buffer, sizeof(table_name_buffer)-1, "<derived%u>", tab->table->derived_select_number); - add_str(table_name_buffer, len); + out->copy(table_name_buffer, len, &my_charset_bin); } else if (tab->bush_children) { @@ -587,15 +584,27 @@ void Json_writer::add_table_name(const JOIN_TAB *tab) sizeof(table_name_buffer)-1, "<subquery%d>", ctab->emb_sj_nest->sj_subq_pred->get_identifier()); - add_str(table_name_buffer, len); + out->copy(table_name_buffer, len, &my_charset_bin); } else { TABLE_LIST *real_table= tab->table->pos_in_table_list; - add_str(real_table->alias.str, real_table->alias.length); + out->set(real_table->alias.str, real_table->alias.length, &my_charset_bin); } } +/* + Prefer this when you are iterating over JOIN_TABs +*/ + +void Json_writer::add_table_name(const JOIN_TAB *tab) +{ + String sbuf; + get_table_name_for_trace(tab, &sbuf); + add_str(sbuf.ptr(), sbuf.length()); +} + + void Json_writer::add_table_name(const TABLE *table) { add_str(table->pos_in_table_list->alias.str); @@ -642,18 +651,27 @@ void add_table_scan_values_to_trace(THD *thd, JOIN_TAB *tab) analysis of the various join orders. */ -void trace_plan_prefix(JOIN *join, uint idx, table_map join_tables) +void trace_plan_prefix(Json_writer_object *jsobj, JOIN *join, uint idx, + table_map join_tables) { THD *const thd= join->thd; DBUG_ASSERT(thd->trace_started()); - Json_writer_array plan_prefix(thd, "plan_prefix"); + String prefix_str; + prefix_str.length(0); for (uint i= 0; i < idx; i++) { TABLE_LIST *const tr= join->positions[i].table->tab_list; if (!(tr->map & join_tables)) - plan_prefix.add_table_name(join->positions[i].table); + { + String str; + get_table_name_for_trace(join->positions[i].table, &str); + if (prefix_str.length() != 0) + prefix_str.append(','); + prefix_str.append(str); + } } + jsobj->add("plan_prefix", prefix_str.ptr(), prefix_str.length()); } diff --git a/sql/opt_trace.h b/sql/opt_trace.h index a43c1dde54b..c6b5c4ea338 100644 --- a/sql/opt_trace.h +++ b/sql/opt_trace.h @@ -107,7 +107,8 @@ void opt_trace_print_expanded_query(THD *thd, SELECT_LEX *select_lex, Json_writer_object *trace_object); void add_table_scan_values_to_trace(THD *thd, JOIN_TAB *tab); -void trace_plan_prefix(JOIN *join, uint idx, table_map join_tables); +void trace_plan_prefix(Json_writer_object *jsobj, JOIN *join, uint idx, + table_map join_tables); void print_final_join_order(JOIN *join); void print_best_access_for_table(THD *thd, POSITION *pos); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 17068c51e83..61f47ea045f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -9670,7 +9670,7 @@ optimize_straight_join(JOIN *join, table_map remaining_tables) double original_record_count, current_record_count; if (unlikely(thd->trace_started())) - trace_plan_prefix(join, idx, remaining_tables); + trace_plan_prefix(&trace_one_table, join, idx, remaining_tables); /* Find the best access method from 's' to the current partial plan */ best_access_path(join, s, remaining_tables, join->positions, idx, disable_jbuf, record_count, @@ -10877,7 +10877,7 @@ best_extension_by_limited_search(JOIN *join, Json_writer_object trace_one_table(thd); JOIN_TAB **best_ref= join->best_ref + idx; if (unlikely(thd->trace_started())) - trace_plan_prefix(join, idx, remaining_tables); + trace_plan_prefix(&trace_one_table, join, idx, remaining_tables); Json_writer_array arr(thd, "get_costs_for_tables"); @@ -10944,7 +10944,7 @@ best_extension_by_limited_search(JOIN *join, if (unlikely(thd->trace_started())) { - trace_plan_prefix(join, idx, remaining_tables); + trace_plan_prefix(&trace_one_table, join, idx, remaining_tables); trace_one_table.add_table_name(s); } |