From 99420dd913333cf7bb109e9c5d71d2daf66e3dca Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Tue, 13 Oct 2009 22:18:48 +0400 Subject: Introduce thd->query_cache_tls (thread local storage for query cache). We need more than one pointer in a thread to represent the query cache and net->query_cache_query can not be used any more (due to ABI compatibility issues and to different life time of NET and THD). This is a backport of the following patch from 6.0: ---------------------------------------------------------- revno: 2476.1157.2 committer: kostja@bodhi.(none) timestamp: Sat 2007-06-16 13:29:24 +0400 include/mysql.h.pp: Update the ABI (NET::query_cache_query is now unused). include/mysql_com.h: NET::query_cache_query is now unused. sql/mysql_priv.h: Update signatures of ex-functios now member functions. sql/sql_cache.cc: Introduce THD::query_cache_tls. sql/sql_cache.h: Introduce THD::query_cache_tls. sql/sql_class.cc: Introduce THD::query_cache_tls. sql/sql_class.h: Introduce THD::query_cache_tls. sql/sql_parse.cc: Use THD::query_cache_tls. sql/sql_select.cc: Use THD::query_cache_tls. --- sql/sql_cache.h | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'sql/sql_cache.h') diff --git a/sql/sql_cache.h b/sql/sql_cache.h index 777ddd39280..a1132adfa5a 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -64,6 +64,8 @@ struct Query_cache_table; struct Query_cache_query; struct Query_cache_result; class Query_cache; +struct Query_cache_tls; +struct st_lex; /** This class represents a node in the linked chain of queries @@ -137,7 +139,7 @@ struct Query_cache_query ulonglong limit_found_rows; rw_lock_t lock; Query_cache_block *res; - NET *wri; + Query_cache_tls *wri; ulong len; uint8 tbls_type; unsigned int last_pkt_nr; @@ -149,8 +151,8 @@ struct Query_cache_query inline void found_rows(ulonglong rows) { limit_found_rows= rows; } inline Query_cache_block *result() { return res; } inline void result(Query_cache_block *p) { res= p; } - inline NET *writer() { return wri; } - inline void writer(NET *p) { wri= p; } + inline Query_cache_tls *writer() { return wri; } + inline void writer(Query_cache_tls *p) { wri= p; } inline uint8 tables_type() { return tbls_type; } inline void tables_type(uint8 type) { tbls_type= type; } inline ulong length() { return len; } @@ -407,7 +409,8 @@ protected: If query is cacheable return number tables in query (query without tables not cached) */ - TABLE_COUNTER_TYPE is_cacheable(THD *thd, uint32 query_len, char *query, + TABLE_COUNTER_TYPE is_cacheable(THD *thd, size_t query_len, + const char *query, LEX *lex, TABLE_LIST *tables_used, uint8 *tables_type); TABLE_COUNTER_TYPE process_and_count_tables(THD *thd, @@ -462,10 +465,13 @@ protected: void destroy(); - friend void query_cache_init_query(NET *net); - friend void query_cache_insert(NET *net, const char *packet, ulong length); - friend void query_cache_end_of_result(THD *thd); - friend void query_cache_abort(NET *net); + void insert(Query_cache_tls *query_cache_tls, + const char *packet, + ulong length, + unsigned pkt_nr); + + void end_of_result(THD *thd); + void abort(Query_cache_tls *query_cache_tls); /* The following functions are only used when debugging @@ -493,9 +499,4 @@ protected: extern Query_cache query_cache; extern TYPELIB query_cache_type_typelib; -void query_cache_init_query(NET *net); -void query_cache_insert(NET *net, const char *packet, ulong length); -void query_cache_end_of_result(THD *thd); -void query_cache_abort(NET *net); - #endif -- cgit v1.2.1 From 595b8f92ae89eb2ef2d502ca80668a525ed2fa99 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Wed, 14 Oct 2009 15:14:58 +0400 Subject: Backport of: ---------------------------------------------------------- revno: 2630.22.8 committer: Konstantin Osipov branch nick: mysql-6.0-runtime timestamp: Sun 2008-08-10 18:49:52 +0400 message: Get rid of typedef struct for the most commonly used types: TABLE, TABLE_SHARE, LEX. This simplifies use of tags and forward declarations. --- sql/sql_cache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/sql_cache.h') diff --git a/sql/sql_cache.h b/sql/sql_cache.h index a1132adfa5a..5a5f936c188 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -65,7 +65,7 @@ struct Query_cache_query; struct Query_cache_result; class Query_cache; struct Query_cache_tls; -struct st_lex; +struct LEX; /** This class represents a node in the linked chain of queries -- cgit v1.2.1 From ddcdacb297ffd42f38743321f7861451e77ce142 Mon Sep 17 00:00:00 2001 From: Kristofer Pettersson Date: Thu, 29 Oct 2009 12:19:36 +0100 Subject: Bug#38551 query cache can still consume [very little] cpu time even when it is off. When the query cache is disabled, the server shouldn't attempt to take the query cache mutex. By using the command line option --query_cache_type=0, the user can disable (backport from mysql-pe) mysql-test/t/query_cache_disabled-master.opt: * added test case for bug38551 mysql-test/t/query_cache_disabled.test: * added test case for bug38551 sql/set_var.cc: * Added before-trigger to verify that query_cache_type wasn't turned off or on during runtime. sql/set_var.h: * Changed order on how the enumeration is processed. By first projecting the character representation of the variable to a temporary integer we can have one function instead of two to check if the value is valid. sql/share/errmsg-utf8.txt: * Added error message for query cache disabled state sql/sql_cache.cc: * If the query cache is disabled at start up, shorten the execution path and avoid grabbing the query cache mutex each time the invalidate interface methods are called. sql/sql_cache.h: * Added new methods to set the query cache into a disabled state. --- sql/sql_cache.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'sql/sql_cache.h') diff --git a/sql/sql_cache.h b/sql/sql_cache.h index 5a5f936c188..6b187ebd6c2 100644 --- a/sql/sql_cache.h +++ b/sql/sql_cache.h @@ -281,8 +281,11 @@ private: enum Cache_lock_status { UNLOCKED, LOCKED_NO_WAIT, LOCKED }; Cache_lock_status m_cache_lock_status; + bool m_query_cache_is_disabled; + void free_query_internal(Query_cache_block *point); void invalidate_table_internal(THD *thd, uchar *key, uint32 key_length); + void disable_query_cache(void) { m_query_cache_is_disabled= TRUE; } protected: /* @@ -426,6 +429,8 @@ protected: uint def_query_hash_size = QUERY_CACHE_DEF_QUERY_HASH_SIZE, uint def_table_hash_size = QUERY_CACHE_DEF_TABLE_HASH_SIZE); + bool is_disabled(void) { return m_query_cache_is_disabled; } + /* initialize cache (mutex) */ void init(); /* resize query cache (return real query size, 0 if disabled) */ -- cgit v1.2.1