summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2019-02-11 17:26:22 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2019-02-11 19:33:43 +0530
commit091535357f7680cee1f2958b9ee235ce6cd6cd44 (patch)
treed22c50fa772254e4ee6596d084104a5a7267b573
parentb31f7dfede39238205601d2504fb3c1510fe8b6e (diff)
downloadmariadb-git-10.4-optimizer_trace.tar.gz
-rw-r--r--sql/my_json_writer.cc16
-rw-r--r--sql/my_json_writer.h26
-rw-r--r--sql/opt_range.cc248
-rw-r--r--sql/opt_subselect.cc35
-rw-r--r--sql/opt_table_elimination.cc6
-rw-r--r--sql/opt_trace.cc22
-rw-r--r--sql/opt_trace.h2
-rw-r--r--sql/sp_head.cc5
-rw-r--r--sql/sql_class.cc5
-rw-r--r--sql/sql_class.h1
-rw-r--r--sql/sql_derived.cc17
-rw-r--r--sql/sql_parse.cc5
-rw-r--r--sql/sql_prepare.cc5
-rw-r--r--sql/sql_select.cc165
-rw-r--r--sql/sql_test.cc8
15 files changed, 254 insertions, 312 deletions
diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc
index 918886142b5..7ae0c58bd7d 100644
--- a/sql/my_json_writer.cc
+++ b/sql/my_json_writer.cc
@@ -219,15 +219,15 @@ void Json_writer::add_str(const String &str)
add_str(str.ptr(), str.length());
}
-Json_writer_object::Json_writer_object(Json_writer *writer) :
- Json_writer_struct(writer)
+Json_writer_object::Json_writer_object(THD *thd) :
+ Json_writer_struct(thd)
{
if (my_writer)
my_writer->start_object();
}
-Json_writer_object::Json_writer_object(Json_writer *writer, const char *str)
- : Json_writer_struct(writer)
+Json_writer_object::Json_writer_object(THD* thd, const char *str)
+ : Json_writer_struct(thd)
{
if (my_writer)
my_writer->add_member(str).start_object();
@@ -240,15 +240,15 @@ Json_writer_object::~Json_writer_object()
closed= TRUE;
}
-Json_writer_array::Json_writer_array(Json_writer *writer) :
- Json_writer_struct(writer)
+Json_writer_array::Json_writer_array(THD *thd) :
+ Json_writer_struct(thd)
{
if (my_writer)
my_writer->start_array();
}
-Json_writer_array::Json_writer_array(Json_writer *writer, const char *str)
- :Json_writer_struct(writer)
+Json_writer_array::Json_writer_array(THD *thd, const char *str)
+ :Json_writer_struct(thd)
{
if (my_writer)
my_writer->add_member(str).start_array();
diff --git a/sql/my_json_writer.h b/sql/my_json_writer.h
index bd60ea16c87..4701cb4165b 100644
--- a/sql/my_json_writer.h
+++ b/sql/my_json_writer.h
@@ -101,7 +101,7 @@ public:
/*
- Something that looks like class String, but has an internal limit of
+ Something that looks like class String, but has an internal limit of
how many bytes one can append to it.
Bytes that were truncated due to the size limitation are counted.
@@ -116,7 +116,7 @@ public:
str.length(0);
}
- size_t get_truncated_bytes() const { return truncated_len; }
+ size_t get_truncated_bytes() const { return truncated_len; }
size_t get_size_limit() { return size_limit; }
void set_size_limit(size_t limit_arg)
@@ -252,7 +252,7 @@ public:
};
/* A class to add values to Json_writer_object and Json_writer_array */
-class Json_value_context
+class Json_value_helper
{
Json_writer* writer;
@@ -326,17 +326,17 @@ class Json_writer_struct
{
protected:
Json_writer* my_writer;
- Json_value_context context;
+ Json_value_helper context;
/*
Tells when a json_writer_struct has been closed or not
*/
bool closed;
public:
- explicit Json_writer_struct(Json_writer* writer)
+ explicit Json_writer_struct(THD *thd)
{
- my_writer= writer;
- context.init(writer);
+ my_writer= thd->opt_trace.get_current_json();
+ context.init(my_writer);
closed= false;
}
};
@@ -347,7 +347,7 @@ public:
There is "ignore mode": one can initialize Json_writer_object with a NULL
Json_writer argument, and then all its calls will do nothing. This is used
- by optimizer trace which can be enabled or disabled.
+ by optimizer trace which can be enabled or disabled.
*/
class Json_writer_object : public Json_writer_struct
@@ -359,8 +359,8 @@ private:
my_writer->add_member(name);
}
public:
- explicit Json_writer_object(Json_writer *w);
- explicit Json_writer_object(Json_writer *w, const char *str);
+ explicit Json_writer_object(THD *thd);
+ explicit Json_writer_object(THD *thd, const char *str);
Json_writer_object& add(const char *name, bool value)
{
@@ -473,14 +473,14 @@ public:
There is "ignore mode": one can initialize Json_writer_array with a NULL
Json_writer argument, and then all its calls will do nothing. This is used
- by optimizer trace which can be enabled or disabled.
+ by optimizer trace which can be enabled or disabled.
*/
class Json_writer_array : public Json_writer_struct
{
public:
- Json_writer_array(Json_writer *w);
- Json_writer_array(Json_writer *w, const char *str);
+ Json_writer_array(THD *thd);
+ Json_writer_array(THD *thd, const char *str);
void end()
{
DBUG_ASSERT(!closed);
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 0f04cf871c7..c87a0595a7d 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -2261,8 +2261,6 @@ void TRP_RANGE::trace_basic_info(const PARAM *param,
Json_writer_object *trace_object) const
{
DBUG_ASSERT(param->using_real_indexes);
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
const uint keynr_in_table = param->real_keynr[key_idx];
const KEY &cur_key = param->table->key_info[keynr_in_table];
@@ -2272,7 +2270,7 @@ void TRP_RANGE::trace_basic_info(const PARAM *param,
.add("index", cur_key.name)
.add("rows", records);
- Json_writer_array trace_range(writer, "ranges");
+ Json_writer_array trace_range(param->thd, "ranges");
// TRP_RANGE should not be created if there are no range intervals
DBUG_ASSERT(key);
@@ -2328,13 +2326,12 @@ public:
void TRP_ROR_UNION::trace_basic_info(const PARAM *param,
Json_writer_object *trace_object) const
{
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
+ THD *thd= param->thd;
trace_object->add("type", "index_roworder_union");
- Json_writer_array ota(writer, "union_of");
+ Json_writer_array smth_trace(thd, "union_of");
for (TABLE_READ_PLAN **current = first_ror; current != last_ror; current++)
{
- Json_writer_object trp_info(writer);
+ Json_writer_object trp_info(thd);
(*current)->trace_basic_info(param, &trp_info);
}
}
@@ -2364,14 +2361,13 @@ public:
void TRP_INDEX_INTERSECT::trace_basic_info(const PARAM *param,
Json_writer_object *trace_object) const
{
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
+ THD *thd= param->thd;
trace_object->add("type", "index_sort_intersect");
- Json_writer_array ota(writer, "index_sort_intersect_of");
+ Json_writer_array smth_trace(thd, "index_sort_intersect_of");
for (TRP_RANGE **current = range_scans; current != range_scans_end;
current++)
{
- Json_writer_object trp_info(writer);
+ Json_writer_object trp_info(thd);
(*current)->trace_basic_info(param, &trp_info);
}
}
@@ -2398,13 +2394,12 @@ public:
void TRP_INDEX_MERGE::trace_basic_info(const PARAM *param,
Json_writer_object *trace_object) const
{
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
+ THD *thd= param->thd;
trace_object->add("type", "index_merge");
- Json_writer_array ota(writer, "index_merge_of");
+ Json_writer_array smth_trace(thd, "index_merge_of");
for (TRP_RANGE **current= range_scans; current != range_scans_end; current++)
{
- Json_writer_object trp_info(writer);
+ Json_writer_object trp_info(thd);
(*current)->trace_basic_info(param, &trp_info);
}
}
@@ -2467,6 +2462,7 @@ public:
void TRP_GROUP_MIN_MAX::trace_basic_info(const PARAM *param,
Json_writer_object *trace_object) const
{
+ THD *thd= param->thd;
trace_object->add("type", "index_group").add("index", index_info->name);
if (min_max_arg_part)
@@ -2481,10 +2477,8 @@ void TRP_GROUP_MIN_MAX::trace_basic_info(const PARAM *param,
.add("cost", read_cost);
const KEY_PART_INFO *key_part = index_info->key_part;
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
{
- Json_writer_array trace_keyparts(writer, "key_parts_used_for_access");
+ Json_writer_array trace_keyparts(thd, "key_parts_used_for_access");
for (uint partno = 0; partno < used_key_parts; partno++)
{
const KEY_PART_INFO *cur_key_part = key_part + partno;
@@ -2492,7 +2486,7 @@ void TRP_GROUP_MIN_MAX::trace_basic_info(const PARAM *param,
}
}
- Json_writer_array trace_range(writer, "ranges");
+ Json_writer_array trace_range(thd, "ranges");
// can have group quick without ranges
if (index_tree)
@@ -2680,16 +2674,14 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
DBUG_PRINT("info",("Time to scan table: %g", read_time));
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
- Json_writer_object table_records(writer);
+ Json_writer_object table_records(thd);
if (head->reginfo.join_tab)
table_records.add_table_name(head->reginfo.join_tab);
else
table_records.add_table_name(head);
- Json_writer_object trace_range(writer, "range_analysis");
+ Json_writer_object trace_range(thd, "range_analysis");
{
- Json_writer_object table_rec(writer, "table_scan");
+ Json_writer_object table_rec(thd, "table_scan");
table_rec.add("rows", records).add("cost", read_time);
}
@@ -2747,11 +2739,11 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
key_info= head->key_info;
uint max_key_len= 0;
- Json_writer_array trace_idx(writer, "potential_range_indexes");
+ Json_writer_array trace_idx(thd, "potential_range_indexes");
for (idx=0 ; idx < head->s->keys ; idx++, key_info++)
{
- Json_writer_object trace_idx_details(writer);
+ Json_writer_object trace_idx_details(thd);
trace_idx_details.add("index", key_info->name);
KEY_PART_INFO *key_part_info;
uint n_key_parts= head->actual_n_key_parts(key_info);
@@ -2759,7 +2751,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
if (!keys_to_use.is_set(idx))
{
trace_idx_details.add("usable", false)
- .add("cause", "not_applicable");
+ .add("cause", "not applicable");
continue;
}
if (key_info->flags & HA_FULLTEXT)
@@ -2772,7 +2764,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
param.key[param.keys]=key_parts;
key_part_info= key_info->key_part;
uint cur_key_len= 0;
- Json_writer_array trace_keypart(writer, "key_parts");
+ Json_writer_array trace_keypart(thd, "key_parts");
for (uint part= 0 ; part < n_key_parts ;
part++, key_parts++, key_part_info++)
{
@@ -2817,7 +2809,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
DBUG_PRINT("info", ("'all'+'using index' scan will be using key %d, "
"read time %g", key_for_use, key_read_time));
- Json_writer_object trace_cov(writer, "best_covering_index_scan");
+ Json_writer_object trace_cov(thd, "best_covering_index_scan");
bool chosen= FALSE;
if (key_read_time < read_time)
{
@@ -2837,7 +2829,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
if (cond)
{
{
- Json_writer_array trace_range_summary(writer,
+ Json_writer_array trace_range_summary(thd,
"setup_range_conditions");
tree= cond->get_mm_tree(&param, &cond);
}
@@ -2871,9 +2863,9 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
{
param.table->quick_condition_rows= MY_MIN(group_trp->records,
head->stat_records());
- Json_writer_object grp_summary(writer, "best_group_range_summary");
+ Json_writer_object grp_summary(thd, "best_group_range_summary");
- if (unlikely(trace->is_started()))
+ if (unlikely(thd->trace_started()))
group_trp->trace_basic_info(&param, &grp_summary);
if (group_trp->read_cost < best_read_time)
@@ -2896,7 +2888,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
TRP_ROR_INTERSECT *rori_trp;
TRP_INDEX_INTERSECT *intersect_trp;
bool can_build_covering= FALSE;
- Json_writer_object trace_range(writer, "analyzing_range_alternatives");
+ Json_writer_object trace_range(thd, "analyzing_range_alternatives");
remove_nonrange_trees(&param, tree);
@@ -2964,7 +2956,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
DBUG_PRINT("info",("No range reads possible,"
" trying to construct index_merge"));
List_iterator_fast<SEL_IMERGE> it(tree->merges);
- Json_writer_array trace_idx_merge(writer, "analyzing_index_merge_union");
+ Json_writer_array trace_idx_merge(thd, "analyzing_index_merge_union");
while ((imerge= it++))
{
new_conj_trp= get_best_disjunct_quick(&param, imerge, best_read_time);
@@ -2999,12 +2991,12 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
possible_keys= param.possible_keys;
free_mem:
- if (unlikely(quick && best_trp && trace->is_started()))
+ if (unlikely(quick && best_trp && thd->trace_started()))
{
- Json_writer_object trace_range_summary(writer,
+ Json_writer_object trace_range_summary(thd,
"chosen_range_access_summary");
{
- Json_writer_object trace_range_plan(writer, "range_access_plan");
+ Json_writer_object trace_range_plan(thd, "range_access_plan");
best_trp->trace_basic_info(&param, &trace_range_plan);
}
trace_range_summary.add("rows_for_plan", quick->records)
@@ -3241,9 +3233,6 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
double table_records= (double)table->stat_records();
DBUG_ENTER("calculate_cond_selectivity_for_table");
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
-
table->cond_selectivity= 1.0;
if (table_records == 0)
@@ -3277,8 +3266,8 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
estimate sources.
*/
- Json_writer_object trace_wrapper(writer);
- Json_writer_array selectivity_for_indexes(writer, "selectivity_for_indexes");
+ Json_writer_object trace_wrapper(thd);
+ Json_writer_array selectivity_for_indexes(thd, "selectivity_for_indexes");
for (keynr= 0; keynr < table->s->keys; keynr++)
{
@@ -3329,7 +3318,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
not yet been accounted for.
*/
table->cond_selectivity*= quick_cond_selectivity;
- Json_writer_object selectivity_for_index(writer);
+ Json_writer_object selectivity_for_index(thd);
selectivity_for_index.add("index_name", key_info->name)
.add("selectivity_from_index",
quick_cond_selectivity);
@@ -3382,7 +3371,7 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
supported by any index and selectivity of the range condition
over the fields whose selectivity has not been set yet.
*/
- Json_writer_array selectivity_for_columns(writer, "selectivity_for_columns");
+ Json_writer_array selectivity_for_columns(thd, "selectivity_for_columns");
if (thd->variables.optimizer_use_condition_selectivity > 2 &&
!bitmap_is_clear_all(used_fields) &&
@@ -3442,14 +3431,14 @@ bool calculate_cond_selectivity_for_table(THD *thd, TABLE *table, Item **cond)
SEL_ARG *key= tree->keys[idx];
if (key)
{
- Json_writer_object selectivity_for_column(writer);
+ Json_writer_object selectivity_for_column(thd);
selectivity_for_column.add("column_name", key->field->field_name);
if (key->type == SEL_ARG::IMPOSSIBLE)
{
rows= 0;
table->reginfo.impossible_range= 1;
selectivity_for_column.add("selectivity_from_histograms", rows);
- selectivity_for_column.add("cause", "impossible_range");
+ selectivity_for_column.add("cause", "impossible range");
goto free_alloc;
}
else
@@ -5027,6 +5016,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
ha_rows roru_total_records;
double roru_intersect_part= 1.0;
size_t n_child_scans;
+ THD *thd= param->thd;
DBUG_ENTER("get_best_disjunct_quick");
DBUG_PRINT("info", ("Full table scan cost: %g", read_time));
@@ -5052,10 +5042,8 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
sizeof(TRP_RANGE*)*
n_child_scans)))
DBUG_RETURN(NULL);
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
- Json_writer_object trace_best_disjunct(writer);
- Json_writer_array to_merge(writer, "indexes_to_merge");
+ Json_writer_object trace_best_disjunct(thd);
+ Json_writer_array to_merge(thd, "indexes_to_merge");
/*
Collect best 'range' scan for each of disjuncts, and, while doing so,
analyze possibility of ROR scans. Also calculate some values needed by
@@ -5067,7 +5055,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
{
DBUG_EXECUTE("info", print_sel_tree(param, *ptree, &(*ptree)->keys_map,
"tree in SEL_IMERGE"););
- Json_writer_object trace_idx(writer);
+ Json_writer_object trace_idx(thd);
if (!(*cur_child= get_key_scans_params(param, *ptree, TRUE, FALSE, read_time)))
{
/*
@@ -5132,7 +5120,7 @@ TABLE_READ_PLAN *get_best_disjunct_quick(PARAM *param, SEL_IMERGE *imerge,
roru_read_plans= (TABLE_READ_PLAN**)range_scans;
trace_best_disjunct.add("use_roworder_union", true)
.add("cause",
- "always_cheaper_than_non_roworder_retrieval");
+ "always cheaper than non roworder retrieval");
goto skip_to_ror_scan;
}
@@ -5232,15 +5220,15 @@ skip_to_ror_scan:
roru_total_records= 0;
cur_roru_plan= roru_read_plans;
- Json_writer_array trace_analyze_ror(writer, "analyzing_roworder_scans");
+ Json_writer_array trace_analyze_ror(thd, "analyzing_roworder_scans");
/* Find 'best' ROR scan for each of trees in disjunction */
for (ptree= imerge->trees, cur_child= range_scans;
ptree != imerge->trees_next;
ptree++, cur_child++, cur_roru_plan++)
{
- Json_writer_object trp_info(writer);
- if (unlikely(trace->is_started()))
+ Json_writer_object trp_info(thd);
+ if (unlikely(thd->trace_started()))
(*cur_child)->trace_basic_info(param, &trp_info);
/*
Assume the best ROR scan is the one that has cheapest full-row-retrieval
@@ -5582,10 +5570,10 @@ ha_rows get_table_cardinality_for_index_intersect(TABLE *table)
}
static
-void print_keyparts(Json_writer *writer, KEY *key, uint key_parts)
+void print_keyparts(THD *thd, KEY *key, uint key_parts)
{
KEY_PART_INFO *part= key->key_part;
- Json_writer_array keyparts= Json_writer_array(writer, "keyparts");
+ Json_writer_array keyparts= Json_writer_array(thd, "keyparts");
for(uint i= 0; i < key_parts; i++, part++)
keyparts.add(part->field->field_name);
}
@@ -5642,8 +5630,7 @@ bool prepare_search_best_index_intersect(PARAM *param,
INDEX_SCAN_INFO *cpk_scan= NULL;
TABLE *table= param->table;
uint n_index_scans= (uint)(tree->index_scans_end - tree->index_scans);
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
+ THD *thd= param->thd;
if (n_index_scans <= 1)
return 1;
@@ -5686,10 +5673,10 @@ bool prepare_search_best_index_intersect(PARAM *param,
bzero(common->search_scans, sizeof(INDEX_SCAN_INFO *) * i);
INDEX_SCAN_INFO **selected_index_scans= common->search_scans;
- Json_writer_array potential_idx_scans(writer, "potential_index_scans");
+ Json_writer_array potential_idx_scans(thd, "potential_index_scans");
for (i=0, index_scan= tree->index_scans; i < n_index_scans; i++, index_scan++)
{
- Json_writer_object idx_scan(writer);
+ Json_writer_object idx_scan(thd);
uint used_key_parts= (*index_scan)->used_key_parts;
KEY *key_info= (*index_scan)->key_info;
idx_scan.add("index", key_info->name);
@@ -5697,14 +5684,14 @@ bool prepare_search_best_index_intersect(PARAM *param,
if (*index_scan == cpk_scan)
{
idx_scan.add("chosen", "false")
- .add("cause", "clustered_index_used_for_filtering");
+ .add("cause", "clustered index used for filtering");
continue;
}
if (cpk_scan && cpk_scan->used_key_parts >= used_key_parts &&
same_index_prefix(cpk_scan->key_info, key_info, used_key_parts))
{
idx_scan.add("chosen", "false")
- .add("cause", "clustered_index_used_for_filtering");
+ .add("cause", "clustered index used for filtering");
continue;
}
@@ -5736,9 +5723,9 @@ bool prepare_search_best_index_intersect(PARAM *param,
{
idx_scan.add("chosen", true);
if (!*scan_ptr)
- idx_scan.add("cause", "first_occurence_of_index_prefix");
+ idx_scan.add("cause", "first occurence of index prefix");
else
- idx_scan.add("cause", "better_cost_for_same_idx_prefix");
+ idx_scan.add("cause", "better cost for same idx prefix");
*scan_ptr= *index_scan;
(*scan_ptr)->index_read_cost= cost;
}
@@ -5787,7 +5774,7 @@ bool prepare_search_best_index_intersect(PARAM *param,
my_qsort(selected_index_scans, n_search_scans, sizeof(INDEX_SCAN_INFO *),
(qsort_cmp) cmp_intersect_index_scan);
- Json_writer_array selected_idx_scans(writer, "selected_index_scans");
+ Json_writer_array selected_idx_scans(thd, "selected_index_scans");
if (cpk_scan)
{
PARTIAL_INDEX_INTERSECT_INFO curr;
@@ -5805,11 +5792,11 @@ bool prepare_search_best_index_intersect(PARAM *param,
ha_rows records= records_in_index_intersect_extension(&curr, *scan_ptr);
(*scan_ptr)->filtered_out= records >= scan_records ?
0 : scan_records-records;
- if (trace->is_started())
+ if (thd->trace_started())
{
- Json_writer_object selected_idx(writer);
+ Json_writer_object selected_idx(thd);
selected_idx.add("index", key_info->name);
- print_keyparts(writer, key_info, (*scan_ptr)->used_key_parts);
+ print_keyparts(thd, key_info, (*scan_ptr)->used_key_parts);
selected_idx.add("records", (*scan_ptr)->records)
.add("filtered_records", (*scan_ptr)->filtered_out);
}
@@ -5821,11 +5808,11 @@ bool prepare_search_best_index_intersect(PARAM *param,
{
KEY *key_info= (*scan_ptr)->key_info;
(*scan_ptr)->filtered_out= 0;
- if (trace->is_started())
+ if (thd->trace_started())
{
- Json_writer_object selected_idx(writer);
+ Json_writer_object selected_idx(thd);
selected_idx.add("index", key_info->name);
- print_keyparts(writer, key_info, (*scan_ptr)->used_key_parts);
+ print_keyparts(thd, key_info, (*scan_ptr)->used_key_parts);
selected_idx.add("records", (*scan_ptr)->records)
.add("filtered_records", (*scan_ptr)->filtered_out);
}
@@ -6286,13 +6273,11 @@ TRP_INDEX_INTERSECT *get_best_index_intersect(PARAM *param, SEL_TREE *tree,
PARTIAL_INDEX_INTERSECT_INFO init;
TRP_INDEX_INTERSECT *intersect_trp= NULL;
TABLE *table= param->table;
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
-
+ THD *thd= param->thd;
DBUG_ENTER("get_best_index_intersect");
- Json_writer_object trace_idx_interect(writer, "analyzing_sort_intersect");
+ Json_writer_object trace_idx_interect(thd, "analyzing_sort_intersect");
if (prepare_search_best_index_intersect(param, tree, &common, &init,
read_time))
@@ -6376,27 +6361,26 @@ typedef struct st_ror_scan_info : INDEX_SCAN_INFO
void TRP_ROR_INTERSECT::trace_basic_info(const PARAM *param,
Json_writer_object *trace_object) const
{
+ THD *thd= param->thd;
trace_object->add("type", "index_roworder_intersect");
trace_object->add("rows", records);
trace_object->add("cost", read_cost);
trace_object->add("covering", is_covering);
trace_object->add("clustered_pk_scan", cpk_scan != NULL);
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
- Json_writer_array ota(writer, "intersect_of");
+ Json_writer_array smth_trace(thd, "intersect_of");
for (ROR_SCAN_INFO **cur_scan = first_scan; cur_scan != last_scan;
cur_scan++)
{
const KEY &cur_key = param->table->key_info[(*cur_scan)->keynr];
const KEY_PART_INFO *key_part = cur_key.key_part;
- Json_writer_object trace_isect_idx(writer);
+ Json_writer_object trace_isect_idx(thd);
trace_isect_idx.add("type", "range_scan");
trace_isect_idx.add("index", cur_key.name);
trace_isect_idx.add("rows", (*cur_scan)->records);
- Json_writer_array trace_range(writer, "ranges");
+ Json_writer_array trace_range(thd, "ranges");
for (const SEL_ARG *current = (*cur_scan)->sel_arg->first(); current;
current = current->next)
{
@@ -6940,15 +6924,14 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
uint idx;
double min_cost= DBL_MAX;
DBUG_ENTER("get_best_ror_intersect");
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
- Json_writer_object trace_ror(writer, "analyzing_roworder_intersect");
+ THD *thd= param->thd;
+ Json_writer_object trace_ror(thd, "analyzing_roworder_intersect");
if ((tree->n_ror_scans < 2) || !param->table->stat_records() ||
!optimizer_flag(param->thd, OPTIMIZER_SWITCH_INDEX_MERGE_INTERSECT))
{
if (tree->n_ror_scans < 2)
- trace_ror.add("cause", "too_few_roworder_scans");
+ trace_ror.add("cause", "too few roworder scans");
DBUG_RETURN(NULL);
}
@@ -7025,10 +7008,10 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
ROR_SCAN_INFO **intersect_scans_best;
cur_ror_scan= tree->ror_scans;
intersect_scans_best= intersect_scans;
- Json_writer_array trace_isect_idx(writer, "intersecting_indexes");
+ Json_writer_array trace_isect_idx(thd, "intersecting_indexes");
while (cur_ror_scan != tree->ror_scans_end && !intersect->is_covering)
{
- Json_writer_object trace_idx(writer);
+ Json_writer_object trace_idx(thd);
trace_idx.add("index",
param->table->key_info[(*cur_ror_scan)->keynr].name);
@@ -7036,7 +7019,7 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
if (!ror_intersect_add(intersect, *cur_ror_scan, &trace_idx, FALSE))
{
trace_idx.add("usable", false)
- .add("cause", "does_not_reduce_cost_of_intersect");
+ .add("cause", "does not reduce cost of intersect");
cur_ror_scan++;
continue;
}
@@ -7059,7 +7042,7 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
else
{
trace_idx.add("chosen", false)
- .add("cause", "does_not_reduce_cost");
+ .add("cause", "does not reduce cost");
}
}
trace_isect_idx.end();
@@ -7068,7 +7051,7 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
{
DBUG_PRINT("info", ("None of scans increase selectivity"));
trace_ror.add("chosen", false)
- .add("cause","does_not_increase_selectivity");
+ .add("cause","does not increase selectivity");
DBUG_RETURN(NULL);
}
@@ -7086,7 +7069,7 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
Check if we should add a CPK scan. If the obtained ROR-intersection is
covering, it doesn't make sense to add CPK scan.
*/
- Json_writer_object trace_cpk(writer, "clustered_pk");
+ Json_writer_object trace_cpk(thd, "clustered_pk");
if (cpk_scan && !intersect->is_covering)
{
if (ror_intersect_add(intersect, cpk_scan, &trace_cpk, TRUE) &&
@@ -7106,8 +7089,8 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
else
{
trace_cpk.add("clustered_pk_added_to_intersect", false)
- .add("cause", cpk_scan ? "roworder_is_covering"
- : "no_clustered_pk_index");
+ .add("cause", cpk_scan ? "roworder is covering"
+ : "no clustered pk index");
cpk_scan= 0; // Don't use cpk_scan
}
trace_cpk.end();
@@ -7146,7 +7129,7 @@ TRP_ROR_INTERSECT *get_best_ror_intersect(const PARAM *param, SEL_TREE *tree,
{
trace_ror.add("chosen", false)
.add("cause", (read_time > min_cost)
- ? "too_few_indexes_to_merge"
+ ? "too few indexes to merge"
: "cost");
}
DBUG_RETURN(trp);
@@ -7335,8 +7318,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
UNINIT_VAR(best_buf_size); /* protected by key_to_read */
TRP_RANGE* read_plan= NULL;
DBUG_ENTER("get_key_scans_params");
- Opt_trace_context *const trace = &param->thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
+ THD *thd= param->thd;
/*
Note that there may be trees that have type SEL_TREE::KEY but contain no
key reads at all, e.g. tree for expression "key1 is not null" where key1
@@ -7344,7 +7326,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
*/
DBUG_EXECUTE("info", print_sel_tree(param, tree, &tree->keys_map,
"tree scans"););
- Json_writer_array range_scan_alt(writer, "range_scan_alternatives");
+ Json_writer_array range_scan_alt(thd, "range_scan_alternatives");
tree->ror_scans_map.clear_all();
tree->n_ror_scans= 0;
@@ -7374,7 +7356,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
bool read_index_only= index_read_must_be_used ? TRUE :
(bool) param->table->covering_keys.is_set(keynr);
- Json_writer_object trace_idx(writer);
+ Json_writer_object trace_idx(thd);
trace_idx.add("index", param->table->key_info[keynr].name);
found_records= check_quick_select(param, idx, read_index_only, key,
@@ -7385,7 +7367,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
(index_scan= (INDEX_SCAN_INFO *)alloc_root(param->mem_root,
sizeof(INDEX_SCAN_INFO))))
{
- Json_writer_array trace_range(writer, "ranges");
+ Json_writer_array trace_range(thd, "ranges");
const KEY &cur_key = param->table->key_info[keynr];
const KEY_PART_INFO *key_part = cur_key.key_part;
@@ -7402,7 +7384,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
index_scan->sel_arg= key;
*tree->index_scans_end++= index_scan;
- if (trace->is_started())
+ if (unlikely(thd->trace_started()))
append_range_all_keyparts(&trace_range, NULL, &range_info, key,
key_part);
trace_range.end();
@@ -7434,7 +7416,7 @@ static TRP_RANGE *get_key_scans_params(PARAM *param, SEL_TREE *tree,
trace_idx.add("chosen", false);
if (found_records == HA_POS_ERROR)
if (key->type == SEL_ARG::Type::MAYBE_KEY)
- trace_idx.add("cause", "depends_on_unread_values");
+ trace_idx.add("cause", "depends on unread values");
else
trace_idx.add("cause", "unknown");
else
@@ -13073,23 +13055,21 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
DBUG_ENTER("get_best_group_min_max");
- Opt_trace_context* trace= &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
- Json_writer_object trace_group(writer, "group_index_range");
+ Json_writer_object trace_group(thd, "group_index_range");
const char* cause= NULL;
/* Perform few 'cheap' tests whether this access method is applicable. */
if (!join) /* This is not a select statement. */
- cause= "no_join";
+ cause= "no join";
else if (join->table_count != 1) /* The query must reference one table. */
- cause= "not_single_table";
+ cause= "not single_table";
else if (join->select_lex->olap == ROLLUP_TYPE) /* Check (B3) for ROLLUP */
cause= "rollup";
else if (table->s->keys == 0) /* There are no indexes to use. */
- cause= "no_index";
+ cause= "no index";
else if (join->conds && join->conds->used_tables()
& OUTER_REF_TABLE_BIT) /* Cannot execute with correlated conditions. */
- cause= "correlated_conditions";
+ cause= "correlated conditions";
if (cause)
{
@@ -13105,7 +13085,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
(!join->select_distinct) &&
!is_agg_distinct)
{
- trace_group.add("chosen", false).add("cause","no_group_by_or_distinct");
+ trace_group.add("chosen", false).add("cause","no group by or distinct");
DBUG_RETURN(NULL);
}
/* Analyze the query in more detail. */
@@ -13128,7 +13108,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
else
{
trace_group.add("chosen", false)
- .add("cause", "not_applicable_aggregate_function");
+ .add("cause", "not applicable aggregate function");
DBUG_RETURN(NULL);
}
@@ -13141,14 +13121,14 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
else if (! min_max_arg_item->eq(expr, 1))
{
trace_group.add("chosen", false)
- .add("cause", "arguments_different_in_min_max_function");
+ .add("cause", "arguments different in min max function");
DBUG_RETURN(NULL);
}
}
else
{
trace_group.add("chosen", false)
- .add("cause", "no_field_item_in_min_max_function");
+ .add("cause", "no field item in min max function");
DBUG_RETURN(NULL);
}
}
@@ -13158,7 +13138,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
if (is_agg_distinct && (have_max || have_min))
{
trace_group.add("chosen", false)
- .add("cause", "have_both_agg_distinct_and_min_max");
+ .add("cause", "have both agg distinct and min max");
DBUG_RETURN(NULL);
}
@@ -13171,7 +13151,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
if (item->real_item()->type() != Item::FIELD_ITEM)
{
trace_group.add("chosen", false)
- .add("cause", "distinct_field_is_expression");
+ .add("cause", "distinct field is expression");
DBUG_RETURN(NULL);
}
}
@@ -13184,7 +13164,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
if ((*tmp_group->item)->real_item()->type() != Item::FIELD_ITEM)
{
trace_group.add("chosen", false)
- .add("cause", "group_field_is_expression");
+ .add("cause", "group field is expression");
DBUG_RETURN(NULL);
}
elements_in_group++;
@@ -13208,14 +13188,14 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
ha_rows cur_quick_prefix_records= 0;
// We go through allowed indexes
- Json_writer_array trace_indexes(writer, "potential_group_range_indexes");
+ Json_writer_array trace_indexes(thd, "potential_group_range_indexes");
for (uint cur_param_idx= 0; cur_param_idx < param->keys ; ++cur_param_idx)
{
const uint cur_index= param->real_keynr[cur_param_idx];
KEY *const cur_index_info= &table->key_info[cur_index];
- Json_writer_object trace_idx(writer);
+ Json_writer_object trace_idx(thd);
trace_idx.add("index", cur_index_info->name);
KEY_PART_INFO *cur_part;
@@ -13243,7 +13223,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
if (!table->covering_keys.is_set(cur_index) ||
!table->keys_in_use_for_group_by.is_set(cur_index))
{
- cause= "not_covering";
+ cause= "not covering";
goto next_index;
}
@@ -13254,7 +13234,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
*/
if (elements_in_group > table->actual_n_key_parts(cur_index_info))
{
- cause= "group_key_parts_greater_than_index_key_parts";
+ cause= "group key parts greater than index key parts";
goto next_index;
}
@@ -13283,7 +13263,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
if (bitmap_is_set(table->read_set, cur_field->field_index) &&
!cur_field->part_of_key_not_clustered.is_set(cur_index))
{
- cause= "not_covering";
+ cause= "not covering";
goto next_index; // Field was not part of key
}
}
@@ -13322,7 +13302,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
}
else
{
- cause= "group_attribute_not_prefix_in_index";
+ cause= "group attribute not prefix in index";
goto next_index;
}
}
@@ -13354,7 +13334,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
/* not doing loose index scan for derived tables */
if (!item_field->field)
{
- cause= "derived_table";
+ cause= "derived table";
goto next_index;
}
@@ -13369,7 +13349,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
if (key_part_nr < 1 ||
(!is_agg_distinct && key_part_nr > join->fields_list.elements))
{
- cause= "select_attribute_not_prefix_in_index";
+ cause= "select attribute not prefix in index";
goto next_index;
}
cur_part= cur_index_info->key_part + key_part_nr - 1;
@@ -13397,7 +13377,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
key_part_nr= get_field_keypart(cur_index_info, min_max_arg_item->field);
if (key_part_nr <= cur_group_key_parts)
{
- cause = "aggregate_column_not_suffix_in_idx";
+ cause = "aggregate column not suffix in idx";
goto next_index;
}
min_max_arg_part= cur_index_info->key_part + key_part_nr - 1;
@@ -13410,7 +13390,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
if (cur_index_info->flags & HA_NOSAME &&
cur_group_key_parts == cur_index_info->user_defined_key_parts)
{
- cause= "using_unique_index";
+ cause= "using unique index";
goto next_index;
}
@@ -13451,7 +13431,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
&cur_key_infix_len,
&first_non_infix_part))
{
- cause = "nonconst_equality_gap_attribute";
+ cause = "nonconst equality gap attribute";
goto next_index;
}
}
@@ -13462,7 +13442,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
There is a gap but no range tree, thus no predicates at all for the
non-group keyparts.
*/
- cause = "no_nongroup_keypart_predicate";
+ cause = "no nongroup keypart predicate";
goto next_index;
}
else if (first_non_group_part && join->conds)
@@ -13487,7 +13467,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
if (join->conds->walk(&Item::find_item_in_field_list_processor, 0,
key_part_range))
{
- cause = "keypart_reference_from_where_clause";
+ cause = "keypart reference from where clause";
goto next_index;
}
}
@@ -13505,7 +13485,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
{
if (bitmap_is_set(table->read_set, cur_part->field->field_index))
{
- cause = "keypart_after_infix_in_query";
+ cause = "keypart after infix in query";
goto next_index;
}
}
@@ -13524,7 +13504,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
index_range_tree, &cur_range) ||
(cur_range && cur_range->type != SEL_ARG::KEY_RANGE))
{
- cause = "minmax_keypart_in_disjunctive_query";
+ cause = "minmax keypart in disjunctive query";
goto next_index;
}
}
@@ -13547,9 +13527,9 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
cur_index_tree, TRUE,
&mrr_flags, &mrr_bufsize,
&dummy_cost);
- if (unlikely(cur_index_tree && trace->is_started()))
+ if (unlikely(cur_index_tree && thd->trace_started()))
{
- Json_writer_array trace_range(writer, "ranges");
+ Json_writer_array trace_range(thd, "ranges");
const KEY_PART_INFO *key_part = cur_index_info->key_part;
@@ -13609,7 +13589,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
&has_min_max_fld, &has_other_fld))
{
trace_group.add("usable", false)
- .add("cause", "unsupported_predicate_on_agg_attribute");
+ .add("cause", "unsupported predicate on agg attribute");
DBUG_RETURN(NULL);
}
@@ -13620,7 +13600,7 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time)
table->file->primary_key_is_clustered())
{
trace_group.add("usable", false)
- .add("cause", "index_is_clustered");
+ .add("cause", "index is clustered");
DBUG_RETURN(NULL);
}
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index 450fa97302a..228fcd0f7e6 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -572,8 +572,6 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
if (select_lex == select_lex->master_unit()->fake_select_lex)
DBUG_RETURN(0);
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
/*
If
1) this join is inside a subquery (of any type except FROM-clause
@@ -699,7 +697,7 @@ int check_and_do_in_subquery_rewrites(JOIN *join)
if (arena)
thd->restore_active_arena(arena, &backup);
in_subs->is_registered_semijoin= TRUE;
- OPT_TRACE_TRANSFORM(writer, oto0, oto1, select_lex->select_number,
+ OPT_TRACE_TRANSFORM(thd, oto0, oto1, select_lex->select_number,
"IN (SELECT)", "semijoin");
oto1.add("chosen", true);
}
@@ -837,14 +835,12 @@ bool subquery_types_allow_materialization(THD* thd, Item_in_subselect *in_subs)
List_iterator<Item> it(in_subs->unit->first_select()->item_list);
uint elements= in_subs->unit->first_select()->item_list.elements;
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
const char* cause= NULL;
in_subs->types_allow_materialization= FALSE; // Assign default values
in_subs->sjm_scan_allowed= FALSE;
- OPT_TRACE_TRANSFORM(writer, oto0, oto1,
+ OPT_TRACE_TRANSFORM(thd, oto0, oto1,
in_subs->get_select_lex()->select_number,
"IN (SELECT)", "materialization");
@@ -861,7 +857,7 @@ bool subquery_types_allow_materialization(THD* thd, Item_in_subselect *in_subs)
outer))
{
oto1.add("possible", false);
- oto1.add("cause", "types_mismatch");
+ oto1.add("cause", "types mismatch");
DBUG_RETURN(FALSE);
}
}
@@ -874,11 +870,11 @@ bool subquery_types_allow_materialization(THD* thd, Item_in_subselect *in_subs)
greater than 0.
*/
if (!total_key_length)
- cause= "zero_length_key_for_materialized_table";
+ cause= "zero length key for materialized table";
else if (total_key_length > tmp_table_max_key_length())
- cause= "length_of_key_greater_than_allowed_key_length_for_materialized_tables";
+ cause= "length of key greater than allowed key length for materialized tables";
else if (elements > tmp_table_max_key_parts())
- cause= "#keyparts_greater_than_allowed_key_parts_for_materialized_tables";
+ cause= "#keyparts greater than allowed key parts for materialized tables";
else
{
in_subs->types_allow_materialization= TRUE;
@@ -1084,8 +1080,6 @@ bool convert_join_subqueries_to_semijoins(JOIN *join)
Query_arena *arena, backup;
Item_in_subselect *in_subq;
THD *thd= join->thd;
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
DBUG_ENTER("convert_join_subqueries_to_semijoins");
if (join->select_lex->sj_subselects.is_empty())
@@ -1242,24 +1236,24 @@ bool convert_join_subqueries_to_semijoins(JOIN *join)
/* Stop processing if we've reached a subquery that's attached to the ON clause */
if (in_subq->do_not_convert_to_sj)
{
- OPT_TRACE_TRANSFORM(writer, oto0, oto1,
+ OPT_TRACE_TRANSFORM(thd, oto0, oto1,
in_subq->get_select_lex()->select_number,
"IN (SELECT)", "semijoin");
oto1.add("converted_to_semi_join", false)
- .add("cause", "subquery_attached_to_the_ON_clause");
+ .add("cause", "subquery attached to the ON clause");
break;
}
if (in_subq->is_flattenable_semijoin)
{
- OPT_TRACE_TRANSFORM(writer, oto0, oto1,
+ OPT_TRACE_TRANSFORM(thd, oto0, oto1,
in_subq->get_select_lex()->select_number,
"IN (SELECT)", "semijoin");
if (join->table_count +
in_subq->unit->first_select()->join->table_count >= MAX_TABLES)
{
oto1.add("converted_to_semi_join", false);
- oto1.add("cause", "table_in_parent_join_now_exceeds_MAX_TABLES");
+ oto1.add("cause", "table in parent join now exceeds MAX_TABLES");
break;
}
if (convert_subq_to_sj(join, in_subq))
@@ -2383,14 +2377,13 @@ int pull_out_semijoin_tables(JOIN *join)
bool optimize_semijoin_nests(JOIN *join, table_map all_table_map)
{
DBUG_ENTER("optimize_semijoin_nests");
- Opt_trace_context* const trace= &join->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
+ THD *thd= join->thd;
List_iterator<TABLE_LIST> sj_list_it(join->select_lex->sj_nests);
TABLE_LIST *sj_nest;
- Json_writer_object wrapper(writer);
- Json_writer_object trace_semijoin_nest(writer,
+ Json_writer_object wrapper(thd);
+ Json_writer_object trace_semijoin_nest(thd,
"execution_plan_for_potential_materialization");
- Json_writer_array trace_steps_array(writer, "steps");
+ Json_writer_array trace_steps_array(thd, "steps");
while ((sj_nest= sj_list_it++))
{
/* semi-join nests with only constant tables are not valid */
diff --git a/sql/opt_table_elimination.cc b/sql/opt_table_elimination.cc
index 022bae86892..03516146de2 100644
--- a/sql/opt_table_elimination.cc
+++ b/sql/opt_table_elimination.cc
@@ -612,9 +612,7 @@ void eliminate_tables(JOIN *join)
if (!optimizer_flag(thd, OPTIMIZER_SWITCH_TABLE_ELIMINATION))
DBUG_VOID_RETURN; /* purecov: inspected */
- Opt_trace_context* trace= &thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
- Json_writer_object trace_wrapper(writer);
+ Json_writer_object trace_wrapper(thd);
/* Find the tables that are referred to from WHERE/HAVING */
used_tables= (join->conds? join->conds->used_tables() : 0) |
@@ -673,7 +671,7 @@ void eliminate_tables(JOIN *join)
}
table_map all_tables= join->all_tables_map();
- Json_writer_array eliminated_tables(writer,"eliminated_tables");
+ Json_writer_array eliminated_tables(thd,"eliminated_tables");
if (all_tables & ~used_tables)
{
/* There are some tables that we probably could eliminate. Try it. */
diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc
index 263d2782f33..ca05f36579a 100644
--- a/sql/opt_trace.cc
+++ b/sql/opt_trace.cc
@@ -103,9 +103,7 @@ void opt_trace_print_expanded_query(THD *thd, SELECT_LEX *select_lex,
Json_writer_object *writer)
{
- Opt_trace_context *const trace = &thd->opt_trace;
-
- if (!trace->is_started())
+ if (!thd->trace_started())
return;
char buff[1024];
String str(buff, sizeof(buff), system_charset_info);
@@ -144,7 +142,7 @@ void opt_trace_disable_if_no_security_context_access(THD *thd)
return;
}
Opt_trace_context *const trace = &thd->opt_trace;
- if (!trace->is_started())
+ if (!thd->trace_started())
{
/*
@@optimizer_trace has "enabled=on" but trace is not started.
@@ -200,14 +198,15 @@ void opt_trace_disable_if_no_stored_proc_func_access(THD *thd, sp_head *sp)
return;
Opt_trace_context *const trace = &thd->opt_trace;
- if (!trace->is_started())
+ if (!thd->trace_started())
return;
bool full_access;
Security_context *const backup_thd_sctx = thd->security_context();
thd->set_security_context(&thd->main_security_ctx);
const bool rc = check_show_routine_access(thd, sp, &full_access) || !full_access;
thd->set_security_context(backup_thd_sctx);
- if (rc) trace->missing_privilege();
+ if (rc)
+ trace->missing_privilege();
return;
}
@@ -234,7 +233,7 @@ void opt_trace_disable_if_no_tables_access(THD *thd, TABLE_LIST *tbl)
return;
Opt_trace_context *const trace = &thd->opt_trace;
- if (!trace->is_started())
+ if (!thd->trace_started())
return;
Security_context *const backup_thd_sctx = thd->security_context();
@@ -294,7 +293,7 @@ void opt_trace_disable_if_no_view_access(THD *thd, TABLE_LIST *view,
thd->system_thread)
return;
Opt_trace_context *const trace = &thd->opt_trace;
- if (!trace->is_started())
+ if (!thd->trace_started())
return;
Security_context *const backup_table_sctx = view->security_ctx;
@@ -642,12 +641,11 @@ void Json_writer::add_table_name(const TABLE *table)
}
-void add_table_scan_values_to_trace(Opt_trace_context* trace, JOIN_TAB *tab)
+void add_table_scan_values_to_trace(THD *thd, JOIN_TAB *tab)
{
- Json_writer *writer= trace->get_current_json();
- Json_writer_object table_records(writer);
+ Json_writer_object table_records(thd);
table_records.add_table_name(tab);
- Json_writer_object table_rec(writer, "table_scan");
+ Json_writer_object table_rec(thd, "table_scan");
table_rec.add("rows", tab->found_records)
.add("cost", tab->read_time);
}
diff --git a/sql/opt_trace.h b/sql/opt_trace.h
index 4bd3f7c3e67..0e2d0146a49 100644
--- a/sql/opt_trace.h
+++ b/sql/opt_trace.h
@@ -104,7 +104,7 @@ class Opt_trace_start {
void opt_trace_print_expanded_query(THD *thd, SELECT_LEX *select_lex,
Json_writer_object *trace_object);
-void add_table_scan_values_to_trace(Opt_trace_context* trace, JOIN_TAB *tab);
+void add_table_scan_values_to_trace(THD *thd, JOIN_TAB *tab);
/*
Security related (need to add a proper comment here)
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index d102e44126c..11c1234e2db 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -3308,9 +3308,8 @@ sp_lex_keeper::reset_lex_and_exec_core(THD *thd, uint *nextp,
NULL, 0,
thd->variables.character_set_client);
- Json_writer *writer= thd->opt_trace.get_current_json();
- Json_writer_object trace_command(writer);
- Json_writer_array trace_command_steps(writer, "steps");
+ Json_writer_object trace_command(thd);
+ Json_writer_array trace_command_steps(thd, "steps");
if (open_tables)
res= check_dependencies_in_with_clauses(m_lex->with_clauses_list) ||
instr->exec_open_and_lock_tables(thd, m_lex->query_tables);
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 4b8dcd15a29..55ae64fb552 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -2188,6 +2188,11 @@ void THD::reset_globals()
net.thd= 0;
}
+bool THD::trace_started()
+{
+ return opt_trace.is_started();
+}
+
/*
Cleanup after query.
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 2273dd6d610..f5b787829c6 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -3308,6 +3308,7 @@ public:
void reset_for_reuse();
bool store_globals();
void reset_globals();
+ bool trace_started();
#ifdef SIGNAL_WITH_VIO_CLOSE
inline void set_active_vio(Vio* vio)
{
diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc
index ff283dbb221..28d28ca2425 100644
--- a/sql/sql_derived.cc
+++ b/sql/sql_derived.cc
@@ -366,8 +366,6 @@ bool mysql_derived_merge(THD *thd, LEX *lex, TABLE_LIST *derived)
uint tablenr;
SELECT_LEX *parent_lex= derived->select_lex;
Query_arena *arena, backup;
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
DBUG_ENTER("mysql_derived_merge");
DBUG_PRINT("enter", ("Alias: '%s' Unit: %p",
(derived->alias.str ? derived->alias.str : "<NULL>"),
@@ -489,14 +487,14 @@ exit_merge:
unconditional_materialization:
- if (unlikely(trace->is_started()))
+ if (unlikely(thd->trace_started()))
{
/*
Add to the optimizer trace the change in choice for merged
derived tables/views to materialised ones.
*/
- Json_writer_object trace_wrapper(writer);
- Json_writer_object trace_derived(writer, derived->is_derived() ?
+ Json_writer_object trace_wrapper(thd);
+ Json_writer_object trace_derived(thd, derived->is_derived() ?
"derived" : "view");
trace_derived.add("table", derived->alias.str ? derived->alias.str : "<NULL>")
.add_select_number(derived->get_unit()->
@@ -674,9 +672,6 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
DBUG_ENTER("mysql_derived_prepare");
DBUG_PRINT("enter", ("unit: %p table_list: %p alias: '%s'",
unit, derived, derived->alias.str));
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
-
if (!unit)
DBUG_RETURN(FALSE);
@@ -769,14 +764,14 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
}
}
- if (unlikely(trace->is_started()))
+ if (unlikely(thd->trace_started()))
{
/*
Add to optimizer trace whether a derived table/view
is merged into the parent select or not.
*/
- Json_writer_object trace_wrapper(writer);
- Json_writer_object trace_derived(writer, derived->is_derived() ?
+ Json_writer_object trace_wrapper(thd);
+ Json_writer_object trace_derived(thd, derived->is_derived() ?
"derived" : "view");
trace_derived.add("table", derived->alias.str ? derived->alias.str : "<NULL>")
.add_select_number(derived->get_unit()->first_select()->select_number);
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index 0462095b7f0..9c25db776ba 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -3413,9 +3413,8 @@ mysql_execute_command(THD *thd)
thd->query(), thd->query_length(),
thd->variables.character_set_client);
- Json_writer *writer= thd->opt_trace.get_current_json();
- Json_writer_object trace_command(writer);
- Json_writer_array trace_command_steps(writer, "steps");
+ Json_writer_object trace_command(thd);
+ Json_writer_array trace_command_steps(thd, "steps");
#ifdef WITH_WSREP
if (WSREP(thd))
diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc
index 6bb1d54f2ed..6c3ad9c6924 100644
--- a/sql/sql_prepare.cc
+++ b/sql/sql_prepare.cc
@@ -2282,9 +2282,8 @@ static bool check_prepared_statement(Prepared_statement *stmt)
thd->query(), thd->query_length(),
thd->variables.character_set_client);
- Json_writer *writer= thd->opt_trace.get_current_json();
- Json_writer_object trace_command(writer);
- Json_writer_array trace_command_steps(writer, "steps");
+ Json_writer_object trace_command(thd);
+ Json_writer_array trace_command_steps(thd, "steps");
/* Reset warning count for each query that uses tables */
if (tables)
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 11319900ad4..06205a46f40 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -349,16 +349,15 @@ bool dbug_user_var_equals_int(THD *thd, const char *name, int value)
}
#endif
-static void trace_table_dependencies(Opt_trace_context *trace,
+static void trace_table_dependencies(THD *thd,
JOIN_TAB *join_tabs, uint table_count)
{
- Json_writer* writer= trace->get_current_json();
- Json_writer_object trace_wrapper(writer);
- Json_writer_array trace_dep(writer, "table_dependencies");
+ Json_writer_object trace_wrapper(thd);
+ Json_writer_array trace_dep(thd, "table_dependencies");
for (uint i = 0; i < table_count; i++)
{
TABLE_LIST *table_ref = join_tabs[i].tab_list;
- Json_writer_object trace_one_table(writer);
+ Json_writer_object trace_one_table(thd);
trace_one_table.add_table_name(&join_tabs[i]);
trace_one_table.add("row_may_be_null",
(bool)table_ref->table->maybe_null);
@@ -372,7 +371,7 @@ static void trace_table_dependencies(Opt_trace_context *trace,
break;
}
}
- Json_writer_array depends_on(writer, "depends_on_map_bits");
+ Json_writer_array depends_on(thd, "depends_on_map_bits");
static_assert(sizeof(table_ref->get_map()) <= 64,
"RAND_TABLE_BIT may be in join_tabs[i].dependent, so we test "
"all 64 bits.");
@@ -1033,12 +1032,10 @@ JOIN::prepare(TABLE_LIST *tables_init,
join_list= &select_lex->top_join_list;
union_part= unit_arg->is_unit_op();
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
- Json_writer_object trace_wrapper(writer);
- Json_writer_object trace_prepare(writer, "join_preparation");
+ Json_writer_object trace_wrapper(thd);
+ Json_writer_object trace_prepare(thd, "join_preparation");
trace_prepare.add_select_number(select_lex->select_number);
- Json_writer_array trace_steps(writer, "steps");
+ Json_writer_array trace_steps(thd, "steps");
// simple check that we got usable conds
dbug_print_item(conds);
@@ -1383,7 +1380,7 @@ JOIN::prepare(TABLE_LIST *tables_init,
}
{
- Json_writer_object trace_wrapper(writer);
+ Json_writer_object trace_wrapper(thd);
opt_trace_print_expanded_query(thd, select_lex, &trace_wrapper);
}
@@ -1568,12 +1565,10 @@ JOIN::optimize_inner()
set_allowed_join_cache_types();
need_distinct= TRUE;
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
- Json_writer_object trace_wrapper(writer);
- Json_writer_object trace_prepare(writer, "join_optimization");
+ Json_writer_object trace_wrapper(thd);
+ Json_writer_object trace_prepare(thd, "join_optimization");
trace_prepare.add_select_number(select_lex->select_number);
- Json_writer_array trace_steps(writer, "steps");
+ Json_writer_array trace_steps(thd, "steps");
/*
Needed in case optimizer short-cuts,
@@ -3973,12 +3968,10 @@ void JOIN::exec_inner()
UNION temp table.
*/
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
- Json_writer_object trace_wrapper(writer);
- Json_writer_object trace_exec(writer, "join_execution");
+ Json_writer_object trace_wrapper(thd);
+ Json_writer_object trace_exec(thd, "join_execution");
trace_exec.add_select_number(select_lex->select_number);
- Json_writer_array trace_steps(writer, "steps");
+ Json_writer_array trace_steps(thd, "steps");
if (!select_lex->outer_select() && // (1)
select_lex != select_lex->master_unit()->fake_select_lex) // (2)
@@ -4531,8 +4524,6 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
List_iterator<TABLE_LIST> ti(tables_list);
TABLE_LIST *tables;
THD *thd= join->thd;
- Opt_trace_context* trace= &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
DBUG_ENTER("make_join_statistics");
table_count=join->table_count;
@@ -4728,8 +4719,8 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
}
}
- if (trace->is_started())
- trace_table_dependencies(trace, stat, join->table_count);
+ if (thd->trace_started())
+ trace_table_dependencies(thd, stat, join->table_count);
if (join->conds || outer_join)
{
@@ -4749,7 +4740,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
skip_unprefixed_keyparts))
goto error;
DBUG_EXECUTE("opt", print_keyuse_array(keyuse_array););
- if (trace->is_started())
+ if (thd->trace_started())
print_keyuse_array_for_trace(thd, keyuse_array);
}
@@ -5041,15 +5032,15 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
Another way would be to enclose them in a scope {};
*/
{
- Json_writer_object rows_estimation_wrapper(writer);
- Json_writer_array rows_estimation(writer, "rows_estimation");
+ Json_writer_object rows_estimation_wrapper(thd);
+ Json_writer_array rows_estimation(thd, "rows_estimation");
for (s=stat ; s < stat_end ; s++)
{
s->startup_cost= 0;
if (s->type == JT_SYSTEM || s->type == JT_CONST)
{
- Json_writer_object table_records(writer);
+ Json_writer_object table_records(thd);
/* Only one matching row */
s->found_records= s->records= 1;
s->read_time=1.0;
@@ -5184,10 +5175,10 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
if (select)
delete select;
else
- add_table_scan_values_to_trace(trace, s);
+ add_table_scan_values_to_trace(thd, s);
}
else
- add_table_scan_values_to_trace(trace, s);
+ add_table_scan_values_to_trace(thd, s);
}
}
@@ -6947,8 +6938,6 @@ best_access_path(JOIN *join,
MY_BITMAP *eq_join_set= &s->table->eq_join_set;
KEYUSE *hj_start_key= 0;
SplM_plan_info *spl_plan= 0;
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
const char* cause= NULL;
disable_jbuf= disable_jbuf || idx == join->const_tables;
@@ -6956,8 +6945,8 @@ best_access_path(JOIN *join,
Loose_scan_opt loose_scan_opt;
DBUG_ENTER("best_access_path");
- Json_writer_object trace_wrapper(writer, "best_access_path");
- Json_writer_array trace_paths(writer, "considered_access_paths");
+ Json_writer_object trace_wrapper(thd, "best_access_path");
+ Json_writer_array trace_paths(thd, "considered_access_paths");
bitmap_clear_all(eq_join_set);
@@ -7072,7 +7061,7 @@ best_access_path(JOIN *join,
if (rec < MATCHING_ROWS_IN_OTHER_TABLE)
rec= MATCHING_ROWS_IN_OTHER_TABLE; // Fix for small tables
- Json_writer_object trace_access_idx(writer);
+ Json_writer_object trace_access_idx(thd);
/*
ft-keys require special treatment
*/
@@ -7138,7 +7127,7 @@ best_access_path(JOIN *join,
/* quick_range couldn't use key! */
records= (double) s->records/rec;
trace_access_idx.add("used_range_estimates", false)
- .add("cause", "not_available");
+ .add("cause", "not available");
}
}
else
@@ -7180,12 +7169,12 @@ best_access_path(JOIN *join,
{
trace_access_idx.add("used_range_estimates",false)
.add("cause",
- "not_better_than_ref_estimates");
+ "not better than ref estimates");
}
else
{
trace_access_idx.add("used_range_estimates", false)
- .add("cause", "not_available");
+ .add("cause", "not available");
}
}
}
@@ -7295,7 +7284,7 @@ best_access_path(JOIN *join,
table->quick_key_parts[key] < max_key_part)
{
trace_access_idx.add("chosen", false);
- cause= "range_uses_more_keyparts";
+ cause= "range uses more keyparts";
}
}
@@ -7431,7 +7420,7 @@ best_access_path(JOIN *join,
(!(s->table->map & join->outer_join) ||
join->allowed_outer_join_with_cache)) // (2)
{
- Json_writer_object trace_access_hash(writer);
+ Json_writer_object trace_access_hash(thd);
double join_sel= 0.1;
/* Estimate the cost of the hash join access to the table */
double rnd_records= matching_candidates_in_table(s, found_constraint,
@@ -7491,7 +7480,7 @@ best_access_path(JOIN *join,
can be [considered to be] more expensive, which causes lookups not to
be used for cases with small datasets, which is annoying.
*/
- Json_writer_object trace_access_scan(writer);
+ Json_writer_object trace_access_scan(thd);
if ((records >= s->found_records || best > s->read_time) && // (1)
!(s->quick && best_key && s->quick->index == best_key->key && // (2)
best_max_key_part >= s->table->quick_key_parts[best_key->key]) &&// (2)
@@ -7768,13 +7757,12 @@ choose_plan(JOIN *join, table_map join_tables)
uint use_cond_selectivity=
join->thd->variables.optimizer_use_condition_selectivity;
bool straight_join= MY_TEST(join->select_options & SELECT_STRAIGHT_JOIN);
+ THD *thd= join->thd;
DBUG_ENTER("choose_plan");
join->cur_embedding_map= 0;
reset_nj_counters(join, join->join_list);
qsort2_cmp jtab_sort_func;
- Opt_trace_context* const trace= &join->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
if (join->emb_sjm_nest)
{
@@ -7806,8 +7794,8 @@ choose_plan(JOIN *join, table_map join_tables)
join->table_count - join->const_tables, sizeof(JOIN_TAB*),
jtab_sort_func, (void*)join->emb_sjm_nest);
- Json_writer_object wrapper(writer);
- Json_writer_array trace_plan(writer,"considered_execution_plans");
+ Json_writer_object wrapper(thd);
+ Json_writer_array trace_plan(thd,"considered_execution_plans");
if (!join->emb_sjm_nest)
{
@@ -8102,13 +8090,12 @@ optimize_straight_join(JOIN *join, table_map join_tables)
uint use_cond_selectivity=
join->thd->variables.optimizer_use_condition_selectivity;
POSITION loose_scan_pos;
- Opt_trace_context* const trace= &join->thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
+ THD *thd= join->thd;
for (JOIN_TAB **pos= join->best_ref + idx ; (s= *pos) ; pos++)
{
- Json_writer_object trace_one_table(writer);
- if (unlikely(trace->is_started()))
+ Json_writer_object trace_one_table(thd);
+ if (unlikely(thd->trace_started()))
{
trace_plan_prefix(join, idx, join_tables);
trace_one_table.add_table_name(s);
@@ -8844,9 +8831,7 @@ double table_cond_selectivity(JOIN *join, uint idx, JOIN_TAB *s,
static void trace_plan_prefix(JOIN *join, uint idx, table_map remaining_tables)
{
THD *const thd = join->thd;
- Opt_trace_context* const trace= &thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
- Json_writer_array plan_prefix(writer, "plan_prefix");
+ 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;
@@ -9009,8 +8994,6 @@ best_extension_by_limited_search(JOIN *join,
double best_record_count= DBL_MAX;
double best_read_time= DBL_MAX;
bool disable_jbuf= join->thd->variables.join_cache_level == 0;
- Opt_trace_context* const trace= &thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
DBUG_EXECUTE("opt", print_plan(join, idx, record_count, read_time, read_time,
"part_plan"););
@@ -9034,8 +9017,8 @@ best_extension_by_limited_search(JOIN *join,
double current_record_count, current_read_time;
POSITION *position= join->positions + idx;
- Json_writer_object trace_one_table(writer);
- if (unlikely(trace->is_started()))
+ Json_writer_object trace_one_table(thd);
+ if (unlikely(thd->trace_started()))
{
trace_plan_prefix(join, idx, remaining_tables);
trace_one_table.add_table_name(s);
@@ -9120,7 +9103,7 @@ best_extension_by_limited_search(JOIN *join,
if ( (search_depth > 1) && (remaining_tables & ~real_table_bit) & allowed_tables )
{ /* Recursively expand the current partial plan */
swap_variables(JOIN_TAB*, join->best_ref[idx], *pos);
- Json_writer_array trace_rest(writer, "rest_of_plan");
+ Json_writer_array trace_rest(thd, "rest_of_plan");
if (best_extension_by_limited_search(join,
remaining_tables & ~real_table_bit,
idx + 1,
@@ -10699,8 +10682,6 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
{
THD *thd= join->thd;
DBUG_ENTER("make_join_select");
- Opt_trace_context* const trace= &thd->opt_trace;
- Json_writer* writer= trace->get_current_json();
if (select)
{
add_not_null_conds(join);
@@ -10738,12 +10719,12 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (const_cond)
{
- Json_writer_object trace_const_cond(writer);
+ Json_writer_object trace_const_cond(thd);
trace_const_cond.add("condition_on_constant_tables", const_cond);
if (const_cond->is_expensive())
{
trace_const_cond.add("evalualted", "false")
- .add("cause", "expensive_cond");
+ .add("cause", "expensive cond");
}
else
{
@@ -10752,7 +10733,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
{
DBUG_PRINT("info",("Found impossible WHERE condition"));
trace_const_cond.add("evalualted", "true")
- .add("found", "impossible_where");
+ .add("found", "impossible where");
join->exec_const_cond= NULL;
DBUG_RETURN(1);
}
@@ -10794,10 +10775,10 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
/*
Step #2: Extract WHERE/ON parts
*/
- Json_writer_object trace_wrapper(writer);
- Json_writer_object trace_conditions(writer, "attaching_conditions_to_tables");
+ Json_writer_object trace_wrapper(thd);
+ Json_writer_object trace_conditions(thd, "attaching_conditions_to_tables");
trace_conditions.add("original_condition", cond);
- Json_writer_array trace_attached_comp(writer,
+ Json_writer_array trace_attached_comp(thd,
"attached_conditions_computation");
uint i;
for (i= join->top_join_tab_count - 1; i >= join->const_tables; i--)
@@ -10868,9 +10849,9 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
have a range that uses longer key.
Lets take @spetrunia's opinion
*/
- Json_writer_object ref_to_range(writer);
+ Json_writer_object ref_to_range(thd);
ref_to_range.add("ref_to_range", true);
- ref_to_range.add("cause", "range_uses_longer_key");
+ ref_to_range.add("cause", "range uses longer key");
tab->type=JT_ALL;
use_quick_range=1;
tab->use_quick=1;
@@ -11313,7 +11294,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
}
trace_attached_comp.end();
- Json_writer_array trace_attached_summary(writer,
+ Json_writer_array trace_attached_summary(thd,
"attached_conditions_summary");
for (tab= first_depth_first_tab(join); tab;
tab= next_depth_first_tab(join, tab))
@@ -11321,7 +11302,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
if (!tab->table)
continue;
Item *const cond = tab->select_cond;
- Json_writer_object trace_one_table(writer);
+ Json_writer_object trace_one_table(thd);
trace_one_table.add_table_name(tab);
trace_one_table.add("attached", cond);
}
@@ -16252,21 +16233,19 @@ optimize_cond(JOIN *join, COND *conds,
multiple equality contains a constant.
*/
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
- Json_writer_object trace_wrapper(writer);
- Json_writer_object trace_cond(writer, "condition_processing");
+ Json_writer_object trace_wrapper(thd);
+ Json_writer_object trace_cond(thd, "condition_processing");
trace_cond.add("condition", join->conds == conds ? "WHERE" : "HAVING")
.add("original_condition", conds);
- Json_writer_array trace_steps(writer, "steps");
- DBUG_EXECUTE("where", print_where(conds, "original", QT_ORDINARY););
+ Json_writer_array trace_steps(thd, "steps");
+ DBUG_EXECUTE("where", print_where(conds, "original", QT_ORDINARY););
conds= build_equal_items(join, conds, NULL, join_list,
ignore_on_conds, cond_equal,
MY_TEST(flags & OPT_LINK_EQUAL_FIELDS));
DBUG_EXECUTE("where",print_where(conds,"after equal_items", QT_ORDINARY););
{
- Json_writer_object equal_prop_wrapper(writer);
+ Json_writer_object equal_prop_wrapper(thd);
equal_prop_wrapper.add("transformation", "equality_propagation")
.add("resulting_condition", conds);
}
@@ -16279,7 +16258,7 @@ optimize_cond(JOIN *join, COND *conds,
*/
DBUG_EXECUTE("where",print_where(conds,"after const change", QT_ORDINARY););
{
- Json_writer_object const_prop_wrapper(writer);
+ Json_writer_object const_prop_wrapper(thd);
const_prop_wrapper.add("transformation", "constant_propagation")
.add("resulting_condition", conds);
}
@@ -16289,7 +16268,7 @@ optimize_cond(JOIN *join, COND *conds,
*cond_equal= &((Item_cond_and*) conds)->m_cond_equal;
{
- Json_writer_object cond_removal_wrapper(writer);
+ Json_writer_object cond_removal_wrapper(thd);
cond_removal_wrapper.add("transformation", "trivial_condition_removal")
.add("resulting_condition", conds);
}
@@ -27182,11 +27161,9 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
const bool has_limit= (select_limit_arg != HA_POS_ERROR);
THD* thd= join ? join->thd : table->in_use;
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
- Json_writer_object trace_wrapper(writer);
+ Json_writer_object trace_wrapper(thd);
Json_writer_object trace_cheaper_ordering(
- writer, "reconsidering_access_paths_for_index_ordering");
+ thd, "reconsidering_access_paths_for_index_ordering");
trace_cheaper_ordering.add("clause", group ? "GROUP BY" : "ORDER BY");
/*
@@ -27254,13 +27231,13 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
trace_cheaper_ordering.add_table_name(table);
trace_cheaper_ordering.add("rows_estimation", refkey_rows_estimate);
- Json_writer_array possible_keys(writer,"possible_keys");
+ Json_writer_array possible_keys(thd,"possible_keys");
for (nr=0; nr < table->s->keys ; nr++)
{
int direction;
ha_rows select_limit= select_limit_arg;
uint used_key_parts= 0;
- Json_writer_object possible_key(writer);
+ Json_writer_object possible_key(thd);
possible_key.add("index", table->key_info[nr].name);
if (keys.is_set(nr) &&
@@ -27443,14 +27420,14 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
if (is_best_covering && !is_covering)
{
possible_key.add("chosen", false);
- possible_key.add("cause", "covering_index_already_found");
+ possible_key.add("cause", "covering index already found");
continue;
}
if (is_covering && refkey_select_limit < select_limit)
{
possible_key.add("chosen", false);
- possible_key.add("cause", "ref_estimates_better");
+ possible_key.add("cause", "ref estimates better");
continue;
}
if (table->quick_keys.is_set(nr))
@@ -27477,13 +27454,13 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
char const *cause;
possible_key.add("chosen", false);
if (is_covering)
- cause= "covering_index_already_found";
+ cause= "covering index already found";
else
{
if (select_limit <= MY_MIN(quick_records,best_records))
- cause= "keyparts_greater_than_the_current_best_keyparts";
+ cause= "keyparts greater than the current best keyparts";
else
- cause= "rows_estimation_greater";
+ cause= "rows estimation greater";
}
possible_key.add("cause", cause);
}
@@ -27498,7 +27475,7 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
{
possible_key.add("usable", false);
if (!group && select_limit == HA_POS_ERROR)
- possible_key.add("cause", "order_by_without_limit");
+ possible_key.add("cause", "order by without limit");
}
}
else
@@ -27506,12 +27483,12 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
if (keys.is_set(nr))
{
possible_key.add("can_resolve_order", false);
- possible_key.add("cause", "order_can_not_be_resolved_by_key");
+ possible_key.add("cause", "order can not be resolved by key");
}
else
{
possible_key.add("can_resolve_order", false);
- possible_key.add("cause", "not_usable_index_for_the query");
+ possible_key.add("cause", "not usable index for the query");
}
}
}
diff --git a/sql/sql_test.cc b/sql/sql_test.cc
index d6917711520..f247fb10f89 100644
--- a/sql/sql_test.cc
+++ b/sql/sql_test.cc
@@ -658,14 +658,12 @@ Memory allocated by threads: %s\n",
void print_keyuse_array_for_trace(THD *thd, DYNAMIC_ARRAY *keyuse_array)
{
- Opt_trace_context *const trace = &thd->opt_trace;
- Json_writer *writer= trace->get_current_json();
- Json_writer_object wrapper(writer);
- Json_writer_array trace_key_uses(writer, "ref_optimizer_key_uses");
+ Json_writer_object wrapper(thd);
+ Json_writer_array trace_key_uses(thd, "ref_optimizer_key_uses");
for(uint i=0; i < keyuse_array->elements; i++)
{
KEYUSE *keyuse= (KEYUSE*)dynamic_array_ptr(keyuse_array, i);
- Json_writer_object keyuse_elem(writer);
+ Json_writer_object keyuse_elem(thd);
keyuse_elem.add_table_name(keyuse->table->reginfo.join_tab);
keyuse_elem.add("field", (keyuse->keypart == FT_KEYPART) ? "<fulltext>"
: (keyuse->is_for_hash_join()