summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2019-01-03 05:03:57 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2019-01-03 07:01:41 +0530
commit4bdd97be25b70b53a0f265dfcda58db0d89ddb7c (patch)
tree4dc3f599c89c5808d6817c25878b6104f7c4d13e
parent2c978c8292e320912440a814fcd3ba77a9e85836 (diff)
downloadmariadb-git-10.4-mdev6111.tar.gz
Fixing minor stuff in code10.4-mdev6111
-rw-r--r--mysql-test/main/mysqld--help.result2
-rw-r--r--sql/my_json_writer.cc2
-rw-r--r--sql/opt_range.cc3
-rw-r--r--sql/opt_trace.cc18
-rw-r--r--sql/sp_head.h1
-rw-r--r--sql/sql_select.cc11
-rw-r--r--sql/sql_test.cc9
7 files changed, 36 insertions, 10 deletions
diff --git a/mysql-test/main/mysqld--help.result b/mysql-test/main/mysqld--help.result
index 491936ddf56..0bea068ee21 100644
--- a/mysql-test/main/mysqld--help.result
+++ b/mysql-test/main/mysqld--help.result
@@ -1547,7 +1547,7 @@ optimizer-prune-level 1
optimizer-search-depth 62
optimizer-selectivity-sampling-limit 100
optimizer-switch index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on
-optimizer-trace
+optimizer-trace enabled=on
optimizer-use-condition-selectivity 1
performance-schema FALSE
performance-schema-accounts-size -1
diff --git a/sql/my_json_writer.cc b/sql/my_json_writer.cc
index 24b9adb9f4f..ce25b2968e2 100644
--- a/sql/my_json_writer.cc
+++ b/sql/my_json_writer.cc
@@ -215,7 +215,7 @@ void Json_writer::add_str(const char *str, size_t length)
void Json_writer::add_str(const String &str)
{
- add_str(str.ptr());
+ add_str(str.ptr(), str.length());
}
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index e58a9f418c1..c7a47dceeaf 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -2276,6 +2276,7 @@ void TRP_RANGE::trace_basic_info(const PARAM *param,
DBUG_ASSERT(key);
String range_info;
+ range_info.length(0);
range_info.set_charset(system_charset_info);
append_range_all_keyparts(&trace_range, NULL, &range_info, key, key_part);
}
@@ -15782,7 +15783,7 @@ static void append_range_all_keyparts(Json_writer_array *range_trace,
else
{
range_trace->get_value_context()
- .add_str(range_so_far->c_ptr(), range_so_far->length());
+ .add_str(*range_so_far);
}
keypart_range= keypart_range->next;
range_so_far->length(save_range_so_far_length);
diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc
index 2fb4f6d3b73..f86ee595a75 100644
--- a/sql/opt_trace.cc
+++ b/sql/opt_trace.cc
@@ -208,9 +208,10 @@ void opt_trace_disable_if_no_stored_proc_func_access(THD *thd, sp_head *sp)
Opt_trace_context *const trace = &thd->opt_trace;
if (!trace->is_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 = sp->check_execute_access(thd);
+ 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();
return;
@@ -353,6 +354,7 @@ class Opt_trace_stmt {
{
delete current_json;
missing_priv= false;
+ ctx= NULL;
}
void set_query(const char *query_ptr, size_t length, const CHARSET_INFO *charset);
void open_struct(const char *key, char opening_bracket);
@@ -422,6 +424,15 @@ void Opt_trace_context::start(THD *thd, TABLE_LIST *tbl,
size_t query_length,
const CHARSET_INFO *query_charset)
{
+ /*
+ This is done currently because we don't want to have multiple
+ traces open at the same time, so as soon as a new trace is created
+ we forcefully end the previous one, if it has not ended by itself.
+ This would mostly happen with stored functions or procedures.
+
+ TODO: handle multiple traces
+ */
+ DBUG_ASSERT(!current_trace);
current_trace= new Opt_trace_stmt(this);
if (!inited)
{
@@ -463,13 +474,14 @@ Opt_trace_start::Opt_trace_start(THD *thd, TABLE_LIST *tbl,
sql_command_can_be_traced(sql_command) &&
!list_has_optimizer_trace_table(tbl) &&
!sets_var_optimizer_trace(sql_command, set_vars) &&
- !thd->system_thread)
+ !thd->system_thread &&
+ !ctx->is_started())
{
ctx->start(thd, tbl, sql_command, query, query_length, query_charset);
ctx->set_query(query, query_length, query_charset);
traceable= TRUE;
+ opt_trace_disable_if_no_tables_access(thd, tbl);
}
- opt_trace_disable_if_no_tables_access(thd, tbl);
}
Opt_trace_start::~Opt_trace_start()
diff --git a/sql/sp_head.h b/sql/sp_head.h
index 8db6ecac9e7..f59da93d8aa 100644
--- a/sql/sp_head.h
+++ b/sql/sp_head.h
@@ -2024,6 +2024,7 @@ private:
}; // class sp_instr_set_case_expr : public sp_instr_opt_meta
+bool check_show_routine_access(THD *thd, sp_head *sp, bool *full_access);
#ifndef NO_EMBEDDED_ACCESS_CHECKS
bool
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 81c79a78ee8..558cf4f537a 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -8023,9 +8023,17 @@ 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();
for (JOIN_TAB **pos= join->best_ref + idx ; (s= *pos) ; pos++)
{
+ Json_writer_object trace_one_table(writer);
+ if (unlikely(trace->get_current_trace()))
+ {
+ trace_plan_prefix(join, idx, join_tables);
+ trace_one_table.add_member("table").add_table_name(s->tab_list);
+ }
/* Find the best access method from 's' to the current partial plan */
best_access_path(join, s, join_tables, idx, disable_jbuf, record_count,
join->positions + idx, &loose_scan_pos);
@@ -27035,8 +27043,9 @@ test_if_cheaper_ordering(const JOIN_TAB *tab, ORDER *order, TABLE *table,
bool group= join && join->group && order == join->group_list;
ha_rows refkey_rows_estimate= table->quick_condition_rows;
const bool has_limit= (select_limit_arg != HA_POS_ERROR);
+ THD* thd= join ? join->thd : table->in_use;
- Opt_trace_context *const trace = &join->thd->opt_trace;
+ 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_cheaper_ordering(
diff --git a/sql/sql_test.cc b/sql/sql_test.cc
index bc51471c245..f0ac80c082d 100644
--- a/sql/sql_test.cc
+++ b/sql/sql_test.cc
@@ -276,9 +276,12 @@ void print_keyuse_array_for_trace(Opt_trace_context *trace, DYNAMIC_ARRAY *keyus
keyuse_elem.add_member("table").add_table_name(keyuse->table->pos_in_table_list);
keyuse_elem.add_member("field").add_str(
(keyuse->keypart == FT_KEYPART) ? "<fulltext>"
- : keyuse->table->key_info[keyuse->key]
- .key_part[keyuse->keypart]
- .field->field_name.str);
+ : (keyuse->is_for_hash_join()
+ ? keyuse->table->field[keyuse->keypart]
+ ->field_name.str
+ : keyuse->table->key_info[keyuse->key]
+ .key_part[keyuse->keypart]
+ .field->field_name.str));
keyuse_elem.add_member("equals").add_str(keyuse->val);
keyuse_elem.add_member("null_rejecting").add_bool(keyuse->null_rejecting);
}