Skip to content

Commit

Permalink
Counting hits for queries in query cache.
Browse files Browse the repository at this point in the history
Added hit_count field to Query_cache_query and methods to get and increment it.
The counter is incremented when query results are read from query cache.
  • Loading branch information
Peter-Sh authored and Sergey Vojtovich committed Aug 31, 2017
1 parent 5dd8e1b commit cf3a74e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sql/sql_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ inline void Query_cache_query::unlock_reading()
void Query_cache_query::init_n_lock()
{
DBUG_ENTER("Query_cache_query::init_n_lock");
res=0; wri = 0; len = 0; ready= 0;
res=0; wri = 0; len = 0; ready= 0; hit_count = 0;
mysql_rwlock_init(key_rwlock_query_cache_query_lock, &lock);
lock_writing();
DBUG_PRINT("qcache", ("inited & locked query for block 0x%lx",
Expand Down Expand Up @@ -2142,6 +2142,7 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d",
}
move_to_query_list_end(query_block);
hits++;
query->increment_hits();
unlock();

/*
Expand Down
3 changes: 3 additions & 0 deletions sql/sql_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ struct Query_cache_query
unsigned int last_pkt_nr;
uint8 tbls_type;
uint8 ready;
ulonglong hit_count;

Query_cache_query() {} /* Remove gcc warning */
inline void init_n_lock();
Expand All @@ -184,6 +185,8 @@ struct Query_cache_query
*/
inline void set_results_ready() { ready= 1; }
inline bool is_results_ready() { return ready; }
inline void increment_hits() { hit_count++; }
inline ulong hits() { return hit_count; }
void lock_writing();
void lock_reading();
bool try_lock_writing();
Expand Down

0 comments on commit cf3a74e

Please sign in to comment.