diff options
author | Alexander Barkov <bar@mariadb.com> | 2019-09-11 11:46:31 +0400 |
---|---|---|
committer | Alexander Barkov <bar@mariadb.com> | 2019-09-11 11:46:31 +0400 |
commit | 0636645e7e13d07a0262571f72bde11e5680a420 (patch) | |
tree | 4ea58843214ee400b12f994bf7f3907626d7d4f7 /sql/opt_trace.cc | |
parent | 2f99e1a2e9843e374b7d9c1c3b4c000f43406319 (diff) | |
parent | 71c57bcf8f87078772ccf5387583487bcd5d86f8 (diff) | |
download | mariadb-git-0636645e7e13d07a0262571f72bde11e5680a420.tar.gz |
Merge remote-tracking branch 'origin/10.4' into 10.5
Diffstat (limited to 'sql/opt_trace.cc')
-rw-r--r-- | sql/opt_trace.cc | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc index 4c9aa43669d..d95f0795542 100644 --- a/sql/opt_trace.cc +++ b/sql/opt_trace.cc @@ -416,6 +416,12 @@ size_t Opt_trace_context::remaining_mem_size() return max_mem_size; } +/* + Disable tracing for children if the current trace is already present. + Currently only one trace is stored and there is no mechanism + to restore traces, so disabling tracing for children is the best option. +*/ + bool Opt_trace_context::disable_tracing_if_required() { if (current_trace) @@ -633,6 +639,73 @@ void add_table_scan_values_to_trace(THD *thd, JOIN_TAB *tab) table_rec.add("rows", tab->found_records) .add("cost", tab->read_time); } + + +/* + @brief + Add the tables inside a partial join to the optimizer trace + + @param join join handler + @param idx length of the partial QEP in 'join->positions' + @table_map map of all non-const tables of the join + + @note + This function is used during best_access_path to print the tables + inside the partial join that were considered doing the cost based + analysis of the various join orders. +*/ + +void trace_plan_prefix(JOIN *join, uint idx, table_map join_tables) +{ + THD *const thd= join->thd; + Json_writer_array plan_prefix(thd, "plan_prefix"); + 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); + } +} + + +/* + Print the join order of all the tables for top level select. + + For example: + + select * from ot1 + where ot1.a IN (select it1.a from it1, it2 where it1.b=it2.a); + + So this function would print + ot1, <subquery2> ----> For select #1 +*/ + +void print_final_join_order(JOIN *join) +{ + Json_writer_object join_order(join->thd); + Json_writer_array best_order(join->thd, "best_join_order"); + JOIN_TAB *j; + uint i; + for (j= join->join_tab,i=0 ; i < join->top_join_tab_count; + i++, j++) + best_order.add_table_name(j); +} + + +void print_best_access_for_table(THD *thd, POSITION *pos, + enum join_type type) +{ + Json_writer_object trace_best_access(thd, "chosen_access_method"); + trace_best_access.add("type", type == JT_ALL ? "scan" : + join_type_str[type]); + trace_best_access.add("records", pos->records_read); + trace_best_access.add("cost", pos->read_time); + trace_best_access.add("uses_join_buffering", pos->use_join_buffer); + trace_best_access.add("filter_used", + pos->range_rowid_filter_info != NULL); +} + + /* Introduce enum_query_type flags parameter, maybe also allow EXPLAIN also use this function. |