Skip to content

Commit

Permalink
accrue statistics to correct handler
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveGosselin-MariaDB authored and spetrunia committed Apr 23, 2024
1 parent 0940a96 commit a11a101
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
5 changes: 3 additions & 2 deletions sql/handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6995,6 +6995,7 @@ 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))
Expand All @@ -7008,13 +7009,13 @@ 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->active_handler_stats.icp_attempts++;
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->active_handler_stats.icp_match++;
h->handler_stats->icp_match++;
}
return res;
}
Expand Down
8 changes: 7 additions & 1 deletion sql/handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3211,7 +3211,13 @@ class handler :public Sql_alloc

ha_rows estimation_rows_to_insert;
handler *lookup_handler;
/* Statistics for the query. Updated if handler_stats.in_use is set */
/*
Statistics for the query. Prefer to use the handler_stats pointer
below rather than this object directly as the clone() method will
modify how stats are accounted by adjusting the handler_stats
pointer. Referring to active_handler_stats directly will yield
surprising and possibly incorrect results.
*/
ha_handler_stats active_handler_stats;
void set_handler_stats();
public:
Expand Down
14 changes: 7 additions & 7 deletions sql/sql_explain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1938,13 +1938,13 @@ static void trace_engine_stats(handler *file, Json_writer *writer)

static void print_r_icp_filtered(handler *file, Json_writer *writer)
{
if (file && file->handler_stats && file->pushed_idx_cond)
{
ha_handler_stats *hs= file->handler_stats;
double r_icp_filtered = hs->icp_attempts ?
(double)(hs->icp_match) / (double)(hs->icp_attempts) : 1.0;
writer->add_member("r_icp_filtered").add_double(r_icp_filtered * 100);
}
if (!file || !file->handler_stats || !file->pushed_idx_cond)
return;

ha_handler_stats *hs= file->handler_stats;
double r_icp_filtered = hs->icp_attempts ?
(double)(hs->icp_match) / (double)(hs->icp_attempts) : 0.0;
writer->add_member("r_icp_filtered").add_double(r_icp_filtered * 100);
}

void Explain_table_access::print_explain_json(Explain_query *query,
Expand Down

0 comments on commit a11a101

Please sign in to comment.