summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2019-09-10 14:01:31 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2019-09-11 04:32:40 +0530
commit71c57bcf8f87078772ccf5387583487bcd5d86f8 (patch)
tree2617f883a81f1593bc91a4a9038deb0984887e54 /sql
parent7b988e5cebf3c6979694056e474f8256b8466696 (diff)
downloadmariadb-git-71c57bcf8f87078772ccf5387583487bcd5d86f8.tar.gz
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
Diffstat (limited to 'sql')
-rw-r--r--sql/my_json_writer.h3
-rw-r--r--sql/opt_subselect.cc3
-rw-r--r--sql/opt_trace.cc34
-rw-r--r--sql/opt_trace.h1
-rw-r--r--sql/sql_select.cc13
5 files changed, 39 insertions, 15 deletions
diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h
index 07a46f65390..f1f1be70bb0 100644
--- a/sql/my_json_writer.h
+++ b/sql/my_json_writer.h
@@ -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
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index e0873185461..c4cb9b81170 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -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);
@@ -3859,7 +3858,7 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join)
join->cur_sj_inner_tables= 0;
Json_writer_object semijoin_strategy(thd);
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++)
{
if (unlikely(thd->trace_started()))
diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc
index c80037ba864..7c82ba829bc 100644
--- a/sql/opt_trace.cc
+++ b/sql/opt_trace.cc
@@ -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.
diff --git a/sql/opt_trace.h b/sql/opt_trace.h
index 6fe179d79d8..46adbec2c3c 100644
--- a/sql/opt_trace.h
+++ b/sql/opt_trace.h
@@ -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);
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index f6435af4ccb..3dae58a78e2 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -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.