diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2020-03-29 13:31:52 +0300 |
---|---|---|
committer | Sergei Petrunia <psergey@askmonty.org> | 2020-03-29 13:31:52 +0300 |
commit | 5c7121f199ea418b2056e08372f6d313b0d8ef85 (patch) | |
tree | 95469a7b666e578e40246d1d36fa54a089777eff /sql | |
parent | 6297a1026db4032ab7b7e28788d0b5b9a1f32aa3 (diff) | |
download | mariadb-git-bb-10.5-mdev22014.tar.gz |
MDEV-22014: Rowid Filtering is not displayed well in the optimizer tracebb-10.5-mdev22014
- 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.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/opt_trace.cc | 21 | ||||
-rw-r--r-- | sql/rowid_filter.cc | 29 | ||||
-rw-r--r-- | sql/rowid_filter.h | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 2 | ||||
-rw-r--r-- | sql/table.h | 1 |
5 files changed, 47 insertions, 8 deletions
diff --git a/sql/opt_trace.cc b/sql/opt_trace.cc index a8676eec411..ddec6d5ed2d 100644 --- a/sql/opt_trace.cc +++ b/sql/opt_trace.cc @@ -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"; /** @@ -664,14 +666,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); + } } diff --git a/sql/rowid_filter.cc b/sql/rowid_filter.cc index 865f22b431a..6ab9e40de32 100644 --- a/sql/rowid_filter.cc +++ b/sql/rowid_filter.cc @@ -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 diff --git a/sql/rowid_filter.h b/sql/rowid_filter.h index a9930dcbca8..467b6884ca6 100644 --- a/sql/rowid_filter.h +++ b/sql/rowid_filter.h @@ -452,6 +452,8 @@ public: double get_a() { return a; } + void trace_info(THD *thd); + friend void TABLE::prune_range_rowid_filters(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 35b5665d1d0..d8d984404cd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -7756,6 +7756,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); diff --git a/sql/table.h b/sql/table.h index 9430ceb5fe3..13eaee869ce 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1579,6 +1579,7 @@ public: 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, |