1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

Moved the function trace_plan_prefix to the optimizer trace file

Also added comments for trace_plan_prefix and the class Json_writer_temp_disable
This commit is contained in:
Varun Gupta
2019-09-10 14:01:31 +05:30
parent 7b988e5ceb
commit 71c57bcf8f
5 changed files with 39 additions and 15 deletions

View File

@@ -562,6 +562,9 @@ public:
/* /*
RAII-based class to disable writing into the JSON document RAII-based class to disable writing into the JSON document
The tracing is disabled as soon as the object is created.
The destuctor is called as soon as we exit the scope of the object
and the tracing is enabled back.
*/ */
class Json_writer_temp_disable class Json_writer_temp_disable

View File

@@ -457,7 +457,6 @@ void best_access_path(JOIN *join, JOIN_TAB *s,
table_map remaining_tables, uint idx, table_map remaining_tables, uint idx,
bool disable_jbuf, double record_count, bool disable_jbuf, double record_count,
POSITION *pos, POSITION *loose_scan_pos); POSITION *pos, POSITION *loose_scan_pos);
void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_tables);
static Item *create_subq_in_equalities(THD *thd, SJ_MATERIALIZATION_INFO *sjm, static Item *create_subq_in_equalities(THD *thd, SJ_MATERIALIZATION_INFO *sjm,
Item_in_subselect *subq_pred); Item_in_subselect *subq_pred);
@@ -3859,7 +3858,7 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join)
join->cur_sj_inner_tables= 0; join->cur_sj_inner_tables= 0;
Json_writer_object semijoin_strategy(thd); Json_writer_object semijoin_strategy(thd);
semijoin_strategy.add("semi_join_strategy","LooseScan"); semijoin_strategy.add("semi_join_strategy","LooseScan");
Json_writer_array semijoin_plan(thd, "join_order"); Json_writer_array semijoin_plan(thd, "join_order");
for (idx= first; idx <= tablenr; idx++) for (idx= first; idx <= tablenr; idx++)
{ {
if (unlikely(thd->trace_started())) if (unlikely(thd->trace_started()))

View File

@@ -413,6 +413,12 @@ size_t Opt_trace_context::remaining_mem_size()
return max_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() bool Opt_trace_context::disable_tracing_if_required()
{ {
if (current_trace) if (current_trace)
@@ -631,6 +637,34 @@ void add_table_scan_values_to_trace(THD *thd, JOIN_TAB *tab)
.add("cost", tab->read_time); .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. Print the join order of all the tables for top level select.

View File

@@ -105,6 +105,7 @@ void opt_trace_print_expanded_query(THD *thd, SELECT_LEX *select_lex,
Json_writer_object *trace_object); Json_writer_object *trace_object);
void add_table_scan_values_to_trace(THD *thd, JOIN_TAB *tab); 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 print_final_join_order(JOIN *join); void print_final_join_order(JOIN *join);
void print_best_access_for_table(THD *thd, POSITION *pos, void print_best_access_for_table(THD *thd, POSITION *pos,
enum join_type type); enum join_type type);

View File

@@ -121,7 +121,6 @@ static bool best_extension_by_limited_search(JOIN *join,
double read_time, uint depth, double read_time, uint depth,
uint prune_level, uint prune_level,
uint use_cond_selectivity); uint use_cond_selectivity);
void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_tables);
static uint determine_search_depth(JOIN* join); static uint determine_search_depth(JOIN* join);
C_MODE_START C_MODE_START
static int join_tab_cmp(const void *dummy, const void* ptr1, const void* ptr2); static int join_tab_cmp(const void *dummy, const void* ptr1, const void* ptr2);
@@ -9191,18 +9190,6 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
} }
void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_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 & remaining_tables))
plan_prefix.add_table_name(join->positions[i].table);
}
}
/** /**
Find a good, possibly optimal, query execution plan (QEP) by a possibly Find a good, possibly optimal, query execution plan (QEP) by a possibly
exhaustive search. exhaustive search.