From 486d42d812ffcb4fcfa5d3b219f3fd6eb10d052a Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Mon, 22 Apr 2024 20:39:31 +0300 Subject: [PATCH] MDEV-18478 ANALYZE for statement should show selectivity of ICP, part#3 Fix the previous patch: - Only enable handler_stats if thd->should_collect_handler_stats()==true. - Make handler_index_cond_check() work when handler_stats are not enabled. --- sql/handler.cc | 7 ++++--- sql/table.cc | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index f2310a1489d63..24b388a9e3053 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6995,7 +6995,6 @@ extern "C" check_result_t handler_index_cond_check(void* h_arg) check_result_t res; DEBUG_SYNC(thd, "handler_index_cond_check"); - DBUG_ASSERT(h->handler_stats); enum thd_kill_levels killed= thd_kill_level(thd); if (unlikely(killed != THD_IS_NOT_KILLED)) @@ -7009,13 +7008,15 @@ extern "C" check_result_t handler_index_cond_check(void* h_arg) if (unlikely(h->end_range) && h->compare_key2(h->end_range) > 0) return CHECK_OUT_OF_RANGE; h->increment_statistics(&SSV::ha_icp_attempts); - h->handler_stats->icp_attempts++; + if (unlikely(h->handler_stats)) + h->handler_stats->icp_attempts++; res= CHECK_NEG; if (h->pushed_idx_cond->val_int()) { res= CHECK_POS; h->fast_increment_statistics(&SSV::ha_icp_match); - h->handler_stats->icp_match++; + if (unlikely(h->handler_stats)) + h->handler_stats->icp_match++; } return res; } diff --git a/sql/table.cc b/sql/table.cc index 1bf1a81fbe87e..36621ee0b387c 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -5871,7 +5871,11 @@ void TABLE::init(THD *thd, TABLE_LIST *tl) (*f_ptr)->cond_selectivity= 1.0; } - file->ha_handler_stats_reset(); + /* enable and clear or disable engine query statistics */ + if (thd->should_collect_handler_stats()) + file->ha_handler_stats_reset(); + else + file->ha_handler_stats_disable(); notnull_cond= 0; DBUG_ASSERT(!file->keyread_enabled());