[Commits] 85145b9: MDEV-28846 Poor performance when rowid filter contains no elements
revision-id: 85145b9e605057f5053f9dd929468e25e9f823e5 (mariadb-10.4.23-83-g85145b9) parent(s): 6e7c6fcfd1f1ac131c423c1ba084d61abad10e8b author: Igor Babaev committer: Igor Babaev timestamp: 2022-06-23 23:53:19 -0700 message: MDEV-28846 Poor performance when rowid filter contains no elements This is a preliminary patch, no test cases are added. --- sql/rowid_filter.cc | 6 ++++-- sql/rowid_filter.h | 10 +++++++++- sql/sql_analyze_stmt.h | 12 ++++++++++-- sql/sql_select.cc | 2 ++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sql/rowid_filter.cc b/sql/rowid_filter.cc index 75f2ab7..bc72259 100644 --- a/sql/rowid_filter.cc +++ b/sql/rowid_filter.cc @@ -575,9 +575,10 @@ bool Range_rowid_filter::fill() if (quick->init() || quick->reset()) rc= 1; - while (!rc) + for ( ; ; ) { - rc= quick->get_next(); + if ((rc= quick->get_next())) + break; if (thd->killed) rc= 1; if (!rc) @@ -598,6 +599,7 @@ bool Range_rowid_filter::fill() file->pushed_idx_cond_keyno= pushed_idx_cond_keyno_save; file->in_range_check_pushed_down= in_range_check_pushed_down_save; tracker->report_container_buff_size(table->file->ref_length); + tracker->report_time_fill_container_ms(); if (rc != HA_ERR_END_OF_FILE) return 1; diff --git a/sql/rowid_filter.h b/sql/rowid_filter.h index 467b688..c02d128 100644 --- a/sql/rowid_filter.h +++ b/sql/rowid_filter.h @@ -192,6 +192,8 @@ class Rowid_filter_container : public Sql_alloc */ virtual bool check(void *ctxt, char *elem) = 0; + virtual bool is_empty() = 0; + virtual ~Rowid_filter_container() {} }; @@ -231,6 +233,8 @@ class Rowid_filter : public Sql_alloc virtual ~Rowid_filter() {} + bool is_empty() { return container->is_empty(); } + Rowid_filter_container *get_container() { return container; } void set_tracker(Rowid_filter_tracker *track_arg) { tracker= track_arg; } @@ -300,7 +304,7 @@ class Refpos_container_sorted_array : public Sql_alloc public: - Refpos_container_sorted_array(uint max_elems, uint elem_sz) + Refpos_container_sorted_array(uint max_elems, uint elem_sz) : max_elements(max_elems), elem_size(elem_sz), array(0) {} ~Refpos_container_sorted_array() @@ -339,6 +343,8 @@ class Refpos_container_sorted_array : public Sql_alloc my_qsort2(array->front(), array->elements()/elem_size, elem_size, (qsort2_cmp) cmp, cmp_arg); } + + bool is_empty() { return elements() == 0; } }; @@ -368,6 +374,8 @@ class Rowid_filter_sorted_array: public Rowid_filter_container bool add(void *ctxt, char *elem) { return refpos_container.add(elem); } bool check(void *ctxt, char *elem); + + bool is_empty() { return refpos_container.is_empty(); } }; /** diff --git a/sql/sql_analyze_stmt.h b/sql/sql_analyze_stmt.h index eec5282..17ebb9c 100644 --- a/sql/sql_analyze_stmt.h +++ b/sql/sql_analyze_stmt.h @@ -306,6 +306,9 @@ class Rowid_filter_tracker : public Sql_alloc /* Size of the rowid filter container buffer */ size_t container_buff_size; + /* Time spent to fill the rowid filter container */ + double time_fill_container_ms; + /* Count of elements that were used to fill the rowid filter container */ uint container_elements; @@ -314,7 +317,7 @@ class Rowid_filter_tracker : public Sql_alloc uint n_positive_checks; public: Rowid_filter_tracker(bool do_timing) : - time_tracker(do_timing), container_buff_size(0), + time_tracker(do_timing), container_buff_size(0), time_fill_container_ms(0), container_elements(0), n_checks(0), n_positive_checks(0) {} @@ -339,9 +342,14 @@ class Rowid_filter_tracker : public Sql_alloc return &time_tracker; } + void report_time_fill_container_ms() + { + time_fill_container_ms= time_tracker.get_time_ms(); + } + double get_time_fill_container_ms() { - return time_tracker.get_time_ms(); + return time_fill_container_ms; } void increment_checked_elements_count(bool was_checked) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 735e00d..7c2f081 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -20599,6 +20599,8 @@ sub_select(JOIN *join,JOIN_TAB *join_tab,bool end_of_records) DBUG_RETURN(NESTED_LOOP_ERROR); join_tab->build_range_rowid_filter_if_needed(); + if (join_tab->rowid_filter && join_tab->rowid_filter->is_empty()) + rc= NESTED_LOOP_NO_MORE_ROWS; join->return_tab= join_tab;
participants (1)
-
IgorBabaev