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
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

View File

@@ -457,7 +457,6 @@ void best_access_path(JOIN *join, JOIN_TAB *s,
table_map remaining_tables, uint idx,
bool disable_jbuf, double record_count,
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,
Item_in_subselect *subq_pred);

View File

@@ -413,6 +413,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)
@@ -631,6 +637,34 @@ void add_table_scan_values_to_trace(THD *thd, JOIN_TAB *tab)
.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.

View File

@@ -105,6 +105,7 @@ 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 print_final_join_order(JOIN *join);
void print_best_access_for_table(THD *thd, POSITION *pos,
enum join_type type);

View File

@@ -121,7 +121,6 @@ static bool best_extension_by_limited_search(JOIN *join,
double read_time, uint depth,
uint prune_level,
uint use_cond_selectivity);
void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_tables);
static uint determine_search_depth(JOIN* join);
C_MODE_START
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
exhaustive search.