mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
MDEV-30059: Optimizer Trace: plan_prefix should be a comma-separated-list
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@ -208,7 +208,7 @@ explain select * from t1 where a=1 or b=1 {
|
|||||||
{
|
{
|
||||||
"considered_execution_plans": [
|
"considered_execution_plans": [
|
||||||
{
|
{
|
||||||
"plan_prefix": [],
|
"plan_prefix": "",
|
||||||
"get_costs_for_tables": [
|
"get_costs_for_tables": [
|
||||||
{
|
{
|
||||||
"best_access_path": {
|
"best_access_path": {
|
||||||
@ -238,7 +238,7 @@ explain select * from t1 where a=1 or b=1 {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"plan_prefix": [],
|
"plan_prefix": "",
|
||||||
"table": "t1",
|
"table": "t1",
|
||||||
"rows_for_plan": 2,
|
"rows_for_plan": 2,
|
||||||
"cost_for_plan": 0.005004612
|
"cost_for_plan": 0.005004612
|
||||||
@ -424,17 +424,13 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.analyzing_range_alternatives'))
|
|||||||
"analyzing_index_merge_union":
|
"analyzing_index_merge_union":
|
||||||
[]
|
[]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"range_scan_alternatives":
|
"range_scan_alternatives":
|
||||||
[
|
[
|
||||||
|
|
||||||
{
|
{
|
||||||
"index": "key2",
|
"index": "key2",
|
||||||
"ranges":
|
"ranges":
|
||||||
[
|
["(100) <= (key2) <= (100)"],
|
||||||
"(100) <= (key2) <= (100)"
|
|
||||||
],
|
|
||||||
"rowid_ordered": true,
|
"rowid_ordered": true,
|
||||||
"using_mrr": false,
|
"using_mrr": false,
|
||||||
"index_only": true,
|
"index_only": true,
|
||||||
@ -478,7 +474,6 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
|
|||||||
"cost_for_plan": 0.572490756,
|
"cost_for_plan": 0.572490756,
|
||||||
"chosen": true
|
"chosen": true
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
"range_access_plan":
|
"range_access_plan":
|
||||||
{
|
{
|
||||||
@ -486,9 +481,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.chosen_range_access_summary'))
|
|||||||
"index": "key2",
|
"index": "key2",
|
||||||
"rows": 2243,
|
"rows": 2243,
|
||||||
"ranges":
|
"ranges":
|
||||||
[
|
["(100) <= (key2) <= (100)"]
|
||||||
"(100) <= (key2) <= (100)"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"rows_for_plan": 2243,
|
"rows_for_plan": 2243,
|
||||||
"cost_for_plan": 0.312832109,
|
"cost_for_plan": 0.312832109,
|
||||||
|
@ -202,7 +202,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
|
|||||||
{
|
{
|
||||||
"considered_execution_plans": [
|
"considered_execution_plans": [
|
||||||
{
|
{
|
||||||
"plan_prefix": [],
|
"plan_prefix": "",
|
||||||
"get_costs_for_tables": [
|
"get_costs_for_tables": [
|
||||||
{
|
{
|
||||||
"best_access_path": {
|
"best_access_path": {
|
||||||
@ -237,7 +237,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"plan_prefix": [],
|
"plan_prefix": "",
|
||||||
"table": "t1",
|
"table": "t1",
|
||||||
"rows_for_plan": 1,
|
"rows_for_plan": 1,
|
||||||
"cost_for_plan": 0.00335956
|
"cost_for_plan": 0.00335956
|
||||||
|
@ -89,7 +89,7 @@ select * from db1.t1 {
|
|||||||
{
|
{
|
||||||
"considered_execution_plans": [
|
"considered_execution_plans": [
|
||||||
{
|
{
|
||||||
"plan_prefix": [],
|
"plan_prefix": "",
|
||||||
"get_costs_for_tables": [
|
"get_costs_for_tables": [
|
||||||
{
|
{
|
||||||
"best_access_path": {
|
"best_access_path": {
|
||||||
@ -120,7 +120,7 @@ select * from db1.t1 {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"plan_prefix": [],
|
"plan_prefix": "",
|
||||||
"table": "t1",
|
"table": "t1",
|
||||||
"rows_for_plan": 3,
|
"rows_for_plan": 3,
|
||||||
"cost_for_plan": 0.010504815
|
"cost_for_plan": 0.010504815
|
||||||
@ -228,7 +228,7 @@ select * from db1.v1 {
|
|||||||
{
|
{
|
||||||
"considered_execution_plans": [
|
"considered_execution_plans": [
|
||||||
{
|
{
|
||||||
"plan_prefix": [],
|
"plan_prefix": "",
|
||||||
"get_costs_for_tables": [
|
"get_costs_for_tables": [
|
||||||
{
|
{
|
||||||
"best_access_path": {
|
"best_access_path": {
|
||||||
@ -259,7 +259,7 @@ select * from db1.v1 {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"plan_prefix": [],
|
"plan_prefix": "",
|
||||||
"table": "t1",
|
"table": "t1",
|
||||||
"rows_for_plan": 3,
|
"rows_for_plan": 3,
|
||||||
"cost_for_plan": 0.010504815
|
"cost_for_plan": 0.010504815
|
||||||
|
@ -34,8 +34,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
|
|||||||
[
|
[
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"plan_prefix":
|
"plan_prefix": "",
|
||||||
[],
|
|
||||||
"get_costs_for_tables":
|
"get_costs_for_tables":
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -96,8 +95,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"plan_prefix":
|
"plan_prefix": "",
|
||||||
[],
|
|
||||||
"table": "t1",
|
"table": "t1",
|
||||||
"rows_for_plan": 7,
|
"rows_for_plan": 7,
|
||||||
"cost_for_plan": 0.045367017
|
"cost_for_plan": 0.045367017
|
||||||
@ -129,8 +127,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
|
|||||||
[
|
[
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"plan_prefix":
|
"plan_prefix": "",
|
||||||
[],
|
|
||||||
"get_costs_for_tables":
|
"get_costs_for_tables":
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -188,8 +185,7 @@ JSON_DETAILED(JSON_EXTRACT(trace, '$**.considered_execution_plans'))
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"plan_prefix":
|
"plan_prefix": "",
|
||||||
[],
|
|
||||||
"table": "t1",
|
"table": "t1",
|
||||||
"rows_for_plan": 0.6,
|
"rows_for_plan": 0.6,
|
||||||
"cost_for_plan": 0.005306142,
|
"cost_for_plan": 0.005306142,
|
||||||
|
@ -25,7 +25,6 @@ json_detailed(JSON_EXTRACT(trace, '$**.ranges'))
|
|||||||
"(2) <= (key1) <= (2)",
|
"(2) <= (key1) <= (2)",
|
||||||
"(3) <= (key1) <= (3)"
|
"(3) <= (key1) <= (3)"
|
||||||
],
|
],
|
||||||
|
|
||||||
[
|
[
|
||||||
"(1) <= (key1) <= (1)",
|
"(1) <= (key1) <= (1)",
|
||||||
"(2) <= (key1) <= (2)",
|
"(2) <= (key1) <= (2)",
|
||||||
|
@ -562,13 +562,10 @@ void Opt_trace_stmt::set_allowed_mem_size(size_t mem_size)
|
|||||||
current_json->set_size_limit(mem_size);
|
current_json->set_size_limit(mem_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Prefer this when you are iterating over JOIN_TABs
|
|
||||||
*/
|
|
||||||
|
|
||||||
void Json_writer::add_table_name(const JOIN_TAB *tab)
|
void get_table_name_for_trace(const JOIN_TAB *tab, String *out)
|
||||||
{
|
{
|
||||||
char table_name_buffer[SAFE_NAME_LEN];
|
char table_name_buffer[64];
|
||||||
DBUG_ASSERT(tab != NULL);
|
DBUG_ASSERT(tab != NULL);
|
||||||
DBUG_ASSERT(tab->join->thd->trace_started());
|
DBUG_ASSERT(tab->join->thd->trace_started());
|
||||||
|
|
||||||
@ -578,7 +575,7 @@ void Json_writer::add_table_name(const JOIN_TAB *tab)
|
|||||||
size_t len= my_snprintf(table_name_buffer, sizeof(table_name_buffer)-1,
|
size_t len= my_snprintf(table_name_buffer, sizeof(table_name_buffer)-1,
|
||||||
"<derived%u>",
|
"<derived%u>",
|
||||||
tab->table->derived_select_number);
|
tab->table->derived_select_number);
|
||||||
add_str(table_name_buffer, len);
|
out->copy(table_name_buffer, len, &my_charset_bin);
|
||||||
}
|
}
|
||||||
else if (tab->bush_children)
|
else if (tab->bush_children)
|
||||||
{
|
{
|
||||||
@ -587,15 +584,27 @@ void Json_writer::add_table_name(const JOIN_TAB *tab)
|
|||||||
sizeof(table_name_buffer)-1,
|
sizeof(table_name_buffer)-1,
|
||||||
"<subquery%d>",
|
"<subquery%d>",
|
||||||
ctab->emb_sj_nest->sj_subq_pred->get_identifier());
|
ctab->emb_sj_nest->sj_subq_pred->get_identifier());
|
||||||
add_str(table_name_buffer, len);
|
out->copy(table_name_buffer, len, &my_charset_bin);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
TABLE_LIST *real_table= tab->table->pos_in_table_list;
|
TABLE_LIST *real_table= tab->table->pos_in_table_list;
|
||||||
add_str(real_table->alias.str, real_table->alias.length);
|
out->set(real_table->alias.str, real_table->alias.length, &my_charset_bin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Prefer this when you are iterating over JOIN_TABs
|
||||||
|
*/
|
||||||
|
|
||||||
|
void Json_writer::add_table_name(const JOIN_TAB *tab)
|
||||||
|
{
|
||||||
|
String sbuf;
|
||||||
|
get_table_name_for_trace(tab, &sbuf);
|
||||||
|
add_str(sbuf.ptr(), sbuf.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Json_writer::add_table_name(const TABLE *table)
|
void Json_writer::add_table_name(const TABLE *table)
|
||||||
{
|
{
|
||||||
add_str(table->pos_in_table_list->alias.str);
|
add_str(table->pos_in_table_list->alias.str);
|
||||||
@ -642,18 +651,26 @@ void add_table_scan_values_to_trace(THD *thd, JOIN_TAB *tab)
|
|||||||
analysis of the various join orders.
|
analysis of the various join orders.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void trace_plan_prefix(JOIN *join, uint idx, table_map join_tables)
|
void trace_plan_prefix(Json_writer_object *jsobj, JOIN *join, uint idx,
|
||||||
|
table_map join_tables)
|
||||||
{
|
{
|
||||||
THD *const thd= join->thd;
|
DBUG_ASSERT(join->thd->trace_started());
|
||||||
DBUG_ASSERT(thd->trace_started());
|
|
||||||
|
|
||||||
Json_writer_array plan_prefix(thd, "plan_prefix");
|
String prefix_str;
|
||||||
|
prefix_str.length(0);
|
||||||
for (uint i= 0; i < idx; i++)
|
for (uint i= 0; i < idx; i++)
|
||||||
{
|
{
|
||||||
TABLE_LIST *const tr= join->positions[i].table->tab_list;
|
TABLE_LIST *const tr= join->positions[i].table->tab_list;
|
||||||
if (!(tr->map & join_tables))
|
if (!(tr->map & join_tables))
|
||||||
plan_prefix.add_table_name(join->positions[i].table);
|
{
|
||||||
|
String str;
|
||||||
|
get_table_name_for_trace(join->positions[i].table, &str);
|
||||||
|
if (prefix_str.length() != 0)
|
||||||
|
prefix_str.append(',');
|
||||||
|
prefix_str.append(str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
jsobj->add("plan_prefix", prefix_str.ptr(), prefix_str.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,7 +107,8 @@ 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 trace_plan_prefix(Json_writer_object *jsobj, 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);
|
||||||
|
|
||||||
|
@ -9748,7 +9748,7 @@ optimize_straight_join(JOIN *join, table_map remaining_tables)
|
|||||||
double original_record_count, current_record_count;
|
double original_record_count, current_record_count;
|
||||||
|
|
||||||
if (unlikely(thd->trace_started()))
|
if (unlikely(thd->trace_started()))
|
||||||
trace_plan_prefix(join, idx, remaining_tables);
|
trace_plan_prefix(&trace_one_table, join, idx, remaining_tables);
|
||||||
/* Find the best access method from 's' to the current partial plan */
|
/* Find the best access method from 's' to the current partial plan */
|
||||||
best_access_path(join, s, remaining_tables, join->positions, idx,
|
best_access_path(join, s, remaining_tables, join->positions, idx,
|
||||||
disable_jbuf, record_count,
|
disable_jbuf, record_count,
|
||||||
@ -10955,7 +10955,7 @@ best_extension_by_limited_search(JOIN *join,
|
|||||||
Json_writer_object trace_one_table(thd);
|
Json_writer_object trace_one_table(thd);
|
||||||
JOIN_TAB **best_ref= join->best_ref + idx;
|
JOIN_TAB **best_ref= join->best_ref + idx;
|
||||||
if (unlikely(thd->trace_started()))
|
if (unlikely(thd->trace_started()))
|
||||||
trace_plan_prefix(join, idx, remaining_tables);
|
trace_plan_prefix(&trace_one_table, join, idx, remaining_tables);
|
||||||
|
|
||||||
Json_writer_array arr(thd, "get_costs_for_tables");
|
Json_writer_array arr(thd, "get_costs_for_tables");
|
||||||
|
|
||||||
@ -11022,7 +11022,7 @@ best_extension_by_limited_search(JOIN *join,
|
|||||||
|
|
||||||
if (unlikely(thd->trace_started()))
|
if (unlikely(thd->trace_started()))
|
||||||
{
|
{
|
||||||
trace_plan_prefix(join, idx, remaining_tables);
|
trace_plan_prefix(&trace_one_table, join, idx, remaining_tables);
|
||||||
trace_one_table.add_table_name(s);
|
trace_one_table.add_table_name(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user