Commit a2190066 authored by Sergei Petrunia's avatar Sergei Petrunia

MDEV-22014: Rowid Filtering is not displayed well in the optimizer trace

- Print the rowid filters that are available for use with each table.
- Make print_best_access_for_table() print which filter it has picked.
- Make best_access_path() print the filter for considered ref accesses.
parent bdcecfa2
This diff is collapsed.
......@@ -217,8 +217,7 @@ explain select * from t1 where a=1 or b=1 {
"type": "index_merge",
"records": 2,
"cost": 4.1484,
"uses_join_buffering": false,
"filter_used": false
"uses_join_buffering": false
}
},
"rows_for_plan": 2,
......
......@@ -171,6 +171,16 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
}
}
},
{
"table": "t1",
"rowid_filters": [
{
"key": "key1",
"build_cost": 1.1801,
"rows": 1
}
]
},
{
"selectivity_for_indexes": [
{
......@@ -212,8 +222,7 @@ explain select * from t1 where pk1 != 0 and key1 = 1 {
"type": "ref",
"records": 1,
"cost": 2,
"uses_join_buffering": false,
"filter_used": false
"uses_join_buffering": false
}
},
"rows_for_plan": 1,
......
......@@ -103,8 +103,7 @@ select * from db1.t1 {
"type": "scan",
"records": 3,
"cost": 2.0051,
"uses_join_buffering": false,
"filter_used": false
"uses_join_buffering": false
}
},
"rows_for_plan": 3,
......@@ -227,8 +226,7 @@ select * from db1.v1 {
"type": "scan",
"records": 3,
"cost": 2.0051,
"uses_join_buffering": false,
"filter_used": false
"uses_join_buffering": false
}
},
"rows_for_plan": 3,
......
......@@ -24,6 +24,8 @@
#include "my_json_writer.h"
#include "sp_head.h"
#include "rowid_filter.h"
const char I_S_table_name[]= "OPTIMIZER_TRACE";
/**
......@@ -661,14 +663,17 @@ void print_best_access_for_table(THD *thd, POSITION *pos,
{
DBUG_ASSERT(thd->trace_started());
Json_writer_object trace_best_access(thd, "chosen_access_method");
trace_best_access.add("type", type == JT_ALL ? "scan" :
join_type_str[type]);
trace_best_access.add("records", pos->records_read);
trace_best_access.add("cost", pos->read_time);
trace_best_access.add("uses_join_buffering", pos->use_join_buffer);
trace_best_access.add("filter_used",
pos->range_rowid_filter_info != NULL);
Json_writer_object obj(thd, "chosen_access_method");
obj.add("type", type == JT_ALL ? "scan" : join_type_str[type]);
obj.add("records", pos->records_read);
obj.add("cost", pos->read_time);
obj.add("uses_join_buffering", pos->use_join_buffer);
if (pos->range_rowid_filter_info)
{
uint key_no= pos->range_rowid_filter_info->key_no;
obj.add("rowid_filter_key",
pos->table->table->key_info[key_no].name);
}
}
......
......@@ -20,6 +20,7 @@
#include "opt_range.h"
#include "rowid_filter.h"
#include "sql_select.h"
#include "opt_trace.h"
inline
......@@ -403,9 +404,37 @@ void TABLE::init_cost_info_for_usable_range_rowid_filters(THD *thd)
}
prune_range_rowid_filters();
if (unlikely(thd->trace_started()))
trace_range_rowid_filters(thd);
}
void TABLE::trace_range_rowid_filters(THD *thd) const
{
if (!range_rowid_filter_cost_info_elems)
return;
Range_rowid_filter_cost_info **p= range_rowid_filter_cost_info_ptr;
Range_rowid_filter_cost_info **end= p + range_rowid_filter_cost_info_elems;
Json_writer_object js_obj(thd);
js_obj.add_table_name(this);
Json_writer_array js_arr(thd, "rowid_filters");
for (; p < end; p++)
(*p)->trace_info(thd);
}
void Range_rowid_filter_cost_info::trace_info(THD *thd)
{
Json_writer_object js_obj(thd);
js_obj.add("key", table->key_info[key_no].name);
js_obj.add("build_cost", b);
js_obj.add("rows", est_elements);
}
/**
@brief
Choose the best range filter for the given access of the table
......
......@@ -452,6 +452,8 @@ class Range_rowid_filter_cost_info : public Sql_alloc
double get_a() { return a; }
void trace_info(THD *thd);
friend
void TABLE::prune_range_rowid_filters();
......
......@@ -7758,6 +7758,8 @@ best_access_path(JOIN *join,
filter->get_cmp_gain(rows);
tmp-= filter->get_adjusted_gain(rows) - filter->get_cmp_gain(rows);
DBUG_ASSERT(tmp >= 0);
trace_access_idx.add("rowid_filter_key",
s->table->key_info[filter->key_no].name);
}
}
trace_access_idx.add("rows", records).add("cost", tmp);
......
......@@ -1566,6 +1566,7 @@ struct TABLE
void init_cost_info_for_usable_range_rowid_filters(THD *thd);
void prune_range_rowid_filters();
void trace_range_rowid_filters(THD *thd) const;
Range_rowid_filter_cost_info *
best_range_rowid_filter_for_partial_join(uint access_key_no,
double records,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment