@ -65,17 +65,44 @@ struct Query_cache_query;
struct Query_cache_result ;
class Query_cache ;
/**
@ brief This class represents a node in the linked chain of queries
belonging to one table .
@ note The root of this linked list is not a query - type block , but the table -
type block which all queries has in common .
*/
struct Query_cache_block_table
{
Query_cache_block_table ( ) { } /* Remove gcc warning */
TABLE_COUNTER_TYPE n ; / / numbr in table ( from 0 )
/**
This node holds a position in a static table list belonging
to the associated query ( base 0 ) .
*/
TABLE_COUNTER_TYPE n ;
/**
Pointers to the next and previous node , linking all queries with
a common table .
*/
Query_cache_block_table * next , * prev ;
/**
A pointer to the table - type block which all
linked queries has in common .
*/
Query_cache_table * parent ;
/**
A method to calculate the address of the query cache block
owning this node . The purpose of this calculation is to
make it easier to move the query cache block without having
to modify all the pointer addresses .
*/
inline Query_cache_block * block ( ) ;
} ;
struct Query_cache_block
{
Query_cache_block ( ) { } /* Remove gcc warning */
@ -151,6 +178,11 @@ struct Query_cache_table
/* data need by some engines */
ulonglong engine_data_buff ;
/**
The number of queries depending of this table .
*/
int32 m_cached_query_count ;
inline char * db ( ) { return ( char * ) data ( ) ; }
inline char * table ( ) { return tbl ; }
inline void table ( char * table_arg ) { tbl = table_arg ; }
@ -237,9 +269,14 @@ public:
ulong free_memory , queries_in_cache , hits , inserts , refused ,
free_memory_blocks , total_blocks , lowmem_prunes ;
private :
pthread_cond_t COND_flush_finished ;
bool flush_in_progress ;
pthread_cond_t COND_cache_status_changed ;
enum Cache_status { NO_FLUSH_IN_PROGRESS , FLUSH_IN_PROGRESS ,
TABLE_FLUSH_IN_PROGRESS } ;
Cache_status m_cache_status ;
void free_query_internal ( Query_cache_block * point ) ;
@ -253,7 +290,7 @@ protected:
2. query block ( for operation inside query ( query block / results ) )
Thread doing cache flush releases the mutex once it sets
flush_in_progres s flag , so other threads may bypass the cache as
m_cache_statu s flag , so other threads may bypass the cache as
if it is disabled , not waiting for reset to finish . The exception
is other threads that were going to do cache flush - - - they ' ll wait
till the end of a flush operation .
@ -270,6 +307,7 @@ protected:
/* options */
ulong min_allocation_unit , min_result_data_size ;
uint def_query_hash_size , def_table_hash_size ;
uint mem_bin_num , mem_bin_steps ; / / See at init_cache & find_bin
my_bool initialized ;
@ -295,10 +333,13 @@ protected:
ulong data_len ,
Query_cache_block * query_block ,
my_bool first_block ) ;
void invalidate_table ( TABLE_LIST * table ) ;
void invalidate_table ( TABLE * table ) ;
void invalidate_table ( uchar * key , uint32 key_length ) ;
void invalidate_table ( Query_cache_block * table_block ) ;
void invalidate_table ( THD * thd , TABLE_LIST * table ) ;
void invalidate_table ( THD * thd , TABLE * table ) ;
void invalidate_table ( THD * thd , uchar * key , uint32 key_length ) ;
void invalidate_table ( THD * thd , Query_cache_block * table_block ) ;
void invalidate_query_block_list ( THD * thd ,
Query_cache_block_table * list_root ) ;
TABLE_COUNTER_TYPE
register_tables_from_list ( TABLE_LIST * tables_used ,
TABLE_COUNTER_TYPE counter ,
@ -337,6 +378,8 @@ protected:
Query_cache_block * pprev ) ;
my_bool join_results ( ulong join_limit ) ;
void wait_while_table_flush_is_in_progress ( bool * interrupt ) ;
/*
Following function control structure_guard_mutex
by themself or don ' t need structure_guard_mutex
@ -347,8 +390,7 @@ protected:
Query_cache_block * write_block_data ( ulong data_len , uchar * data ,
ulong header_len ,
Query_cache_block : : block_type type ,
TABLE_COUNTER_TYPE ntab = 0 ,
my_bool under_guard = 0 ) ;
TABLE_COUNTER_TYPE ntab = 0 ) ;
my_bool append_result_data ( Query_cache_block * * result ,
ulong data_len , uchar * data ,
Query_cache_block * parent ) ;
@ -360,8 +402,7 @@ protected:
inline ulong get_min_first_result_data_size ( ) ;
inline ulong get_min_append_result_data_size ( ) ;
Query_cache_block * allocate_block ( ulong len , my_bool not_less ,
ulong min ,
my_bool under_guard = 0 ) ;
ulong min ) ;
/*
If query is cacheable return number tables in query
( query without tables not cached )
@ -424,6 +465,11 @@ protected:
friend void query_cache_end_of_result ( THD * thd ) ;
friend void query_cache_abort ( NET * net ) ;
bool is_flushing ( void )
{
return ( m_cache_status ! = Query_cache : : NO_FLUSH_IN_PROGRESS ) ;
}
/*
The following functions are only used when debugging
We don ' t protect these with ifndef DBUG_OFF to not have to recompile