Skip to content

Commit a11a101

Browse files
DaveGosselin-MariaDBspetrunia
authored andcommitted
accrue statistics to correct handler
1 parent 0940a96 commit a11a101

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

sql/handler.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6995,6 +6995,7 @@ extern "C" check_result_t handler_index_cond_check(void* h_arg)
69956995
check_result_t res;
69966996

69976997
DEBUG_SYNC(thd, "handler_index_cond_check");
6998+
DBUG_ASSERT(h->handler_stats);
69986999

69997000
enum thd_kill_levels killed= thd_kill_level(thd);
70007001
if (unlikely(killed != THD_IS_NOT_KILLED))
@@ -7008,13 +7009,13 @@ extern "C" check_result_t handler_index_cond_check(void* h_arg)
70087009
if (unlikely(h->end_range) && h->compare_key2(h->end_range) > 0)
70097010
return CHECK_OUT_OF_RANGE;
70107011
h->increment_statistics(&SSV::ha_icp_attempts);
7011-
h->active_handler_stats.icp_attempts++;
7012+
h->handler_stats->icp_attempts++;
70127013
res= CHECK_NEG;
70137014
if (h->pushed_idx_cond->val_int())
70147015
{
70157016
res= CHECK_POS;
70167017
h->fast_increment_statistics(&SSV::ha_icp_match);
7017-
h->active_handler_stats.icp_match++;
7018+
h->handler_stats->icp_match++;
70187019
}
70197020
return res;
70207021
}

sql/handler.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3211,7 +3211,13 @@ class handler :public Sql_alloc
32113211

32123212
ha_rows estimation_rows_to_insert;
32133213
handler *lookup_handler;
3214-
/* Statistics for the query. Updated if handler_stats.in_use is set */
3214+
/*
3215+
Statistics for the query. Prefer to use the handler_stats pointer
3216+
below rather than this object directly as the clone() method will
3217+
modify how stats are accounted by adjusting the handler_stats
3218+
pointer. Referring to active_handler_stats directly will yield
3219+
surprising and possibly incorrect results.
3220+
*/
32153221
ha_handler_stats active_handler_stats;
32163222
void set_handler_stats();
32173223
public:

sql/sql_explain.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,13 +1938,13 @@ static void trace_engine_stats(handler *file, Json_writer *writer)
19381938

19391939
static void print_r_icp_filtered(handler *file, Json_writer *writer)
19401940
{
1941-
if (file && file->handler_stats && file->pushed_idx_cond)
1942-
{
1943-
ha_handler_stats *hs= file->handler_stats;
1944-
double r_icp_filtered = hs->icp_attempts ?
1945-
(double)(hs->icp_match) / (double)(hs->icp_attempts) : 1.0;
1946-
writer->add_member("r_icp_filtered").add_double(r_icp_filtered * 100);
1947-
}
1941+
if (!file || !file->handler_stats || !file->pushed_idx_cond)
1942+
return;
1943+
1944+
ha_handler_stats *hs= file->handler_stats;
1945+
double r_icp_filtered = hs->icp_attempts ?
1946+
(double)(hs->icp_match) / (double)(hs->icp_attempts) : 0.0;
1947+
writer->add_member("r_icp_filtered").add_double(r_icp_filtered * 100);
19481948
}
19491949

19501950
void Explain_table_access::print_explain_json(Explain_query *query,

0 commit comments

Comments
 (0)