Commit 99420dd9 authored by Konstantin Osipov's avatar Konstantin Osipov

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.
parent 9a65687b
...@@ -32,7 +32,7 @@ typedef struct st_net { ...@@ -32,7 +32,7 @@ typedef struct st_net {
my_bool unused2; my_bool unused2;
my_bool compress; my_bool compress;
my_bool unused3; my_bool unused3;
unsigned char *query_cache_query; unsigned char *unused;
unsigned int last_errno; unsigned int last_errno;
unsigned char error; unsigned char error;
my_bool unused4; my_bool unused4;
......
...@@ -264,10 +264,9 @@ typedef struct st_net { ...@@ -264,10 +264,9 @@ typedef struct st_net {
*/ */
#endif #endif
/* /*
'query_cache_query' should be accessed only via query cache Unused, please remove with the next incompatible ABI change.
functions and methods to maintain proper locking.
*/ */
unsigned char *query_cache_query; unsigned char *unused;
unsigned int last_errno; unsigned int last_errno;
unsigned char error; unsigned char error;
my_bool unused4; /* Please remove with the next incompatible ABI change. */ my_bool unused4; /* Please remove with the next incompatible ABI change. */
......
...@@ -905,6 +905,8 @@ struct Query_cache_query_flags ...@@ -905,6 +905,8 @@ struct Query_cache_query_flags
}; };
#define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags) #define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags)
#include "sql_cache.h" #include "sql_cache.h"
#define query_cache_abort(A) query_cache.abort(A)
#define query_cache_end_of_result(A) query_cache.end_of_result(A)
#define query_cache_store_query(A, B) query_cache.store_query(A, B) #define query_cache_store_query(A, B) query_cache.store_query(A, B)
#define query_cache_destroy() query_cache.destroy() #define query_cache_destroy() query_cache.destroy()
#define query_cache_result_size_limit(A) query_cache.result_size_limit(A) #define query_cache_result_size_limit(A) query_cache.result_size_limit(A)
......
...@@ -95,8 +95,8 @@ extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received; ...@@ -95,8 +95,8 @@ extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received;
#ifndef MYSQL_INSTANCE_MANAGER #ifndef MYSQL_INSTANCE_MANAGER
#ifdef HAVE_QUERY_CACHE #ifdef HAVE_QUERY_CACHE
#define USE_QUERY_CACHE #define USE_QUERY_CACHE
extern void query_cache_init_query(NET *net); extern void query_cache_insert(const char *packet, ulong length,
extern void query_cache_insert(NET *net, const char *packet, ulong length); unsigned pkt_nr);
#endif // HAVE_QUERY_CACHE #endif // HAVE_QUERY_CACHE
#define update_statistics(A) A #define update_statistics(A) A
#endif /* MYSQL_INSTANCE_MANGER */ #endif /* MYSQL_INSTANCE_MANGER */
...@@ -132,11 +132,7 @@ my_bool my_net_init(NET *net, Vio* vio) ...@@ -132,11 +132,7 @@ my_bool my_net_init(NET *net, Vio* vio)
net->compress=0; net->reading_or_writing=0; net->compress=0; net->reading_or_writing=0;
net->where_b = net->remain_in_buf=0; net->where_b = net->remain_in_buf=0;
net->last_errno=0; net->last_errno=0;
#ifdef USE_QUERY_CACHE net->unused= 0;
query_cache_init_query(net);
#else
net->query_cache_query= 0;
#endif
if (vio != 0) /* If real connection */ if (vio != 0) /* If real connection */
{ {
...@@ -586,7 +582,7 @@ net_real_write(NET *net,const uchar *packet, size_t len) ...@@ -586,7 +582,7 @@ net_real_write(NET *net,const uchar *packet, size_t len)
DBUG_ENTER("net_real_write"); DBUG_ENTER("net_real_write");
#if defined(MYSQL_SERVER) && defined(USE_QUERY_CACHE) #if defined(MYSQL_SERVER) && defined(USE_QUERY_CACHE)
query_cache_insert(net, (char*) packet, len); query_cache_insert((char*) packet, len, net->pkt_nr);
#endif #endif
if (net->error == 2) if (net->error == 2)
......
This diff is collapsed.
...@@ -64,6 +64,8 @@ struct Query_cache_table; ...@@ -64,6 +64,8 @@ struct Query_cache_table;
struct Query_cache_query; struct Query_cache_query;
struct Query_cache_result; struct Query_cache_result;
class Query_cache; class Query_cache;
struct Query_cache_tls;
struct st_lex;
/** /**
This class represents a node in the linked chain of queries This class represents a node in the linked chain of queries
...@@ -137,7 +139,7 @@ struct Query_cache_query ...@@ -137,7 +139,7 @@ struct Query_cache_query
ulonglong limit_found_rows; ulonglong limit_found_rows;
rw_lock_t lock; rw_lock_t lock;
Query_cache_block *res; Query_cache_block *res;
NET *wri; Query_cache_tls *wri;
ulong len; ulong len;
uint8 tbls_type; uint8 tbls_type;
unsigned int last_pkt_nr; unsigned int last_pkt_nr;
...@@ -149,8 +151,8 @@ struct Query_cache_query ...@@ -149,8 +151,8 @@ struct Query_cache_query
inline void found_rows(ulonglong rows) { limit_found_rows= rows; } inline void found_rows(ulonglong rows) { limit_found_rows= rows; }
inline Query_cache_block *result() { return res; } inline Query_cache_block *result() { return res; }
inline void result(Query_cache_block *p) { res= p; } inline void result(Query_cache_block *p) { res= p; }
inline NET *writer() { return wri; } inline Query_cache_tls *writer() { return wri; }
inline void writer(NET *p) { wri= p; } inline void writer(Query_cache_tls *p) { wri= p; }
inline uint8 tables_type() { return tbls_type; } inline uint8 tables_type() { return tbls_type; }
inline void tables_type(uint8 type) { tbls_type= type; } inline void tables_type(uint8 type) { tbls_type= type; }
inline ulong length() { return len; } inline ulong length() { return len; }
...@@ -407,7 +409,8 @@ class Query_cache ...@@ -407,7 +409,8 @@ class Query_cache
If query is cacheable return number tables in query If query is cacheable return number tables in query
(query without tables not cached) (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, LEX *lex, TABLE_LIST *tables_used,
uint8 *tables_type); uint8 *tables_type);
TABLE_COUNTER_TYPE process_and_count_tables(THD *thd, TABLE_COUNTER_TYPE process_and_count_tables(THD *thd,
...@@ -462,10 +465,13 @@ class Query_cache ...@@ -462,10 +465,13 @@ class Query_cache
void destroy(); void destroy();
friend void query_cache_init_query(NET *net); void insert(Query_cache_tls *query_cache_tls,
friend void query_cache_insert(NET *net, const char *packet, ulong length); const char *packet,
friend void query_cache_end_of_result(THD *thd); ulong length,
friend void query_cache_abort(NET *net); 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 The following functions are only used when debugging
...@@ -493,9 +499,4 @@ class Query_cache ...@@ -493,9 +499,4 @@ class Query_cache
extern Query_cache query_cache; extern Query_cache query_cache;
extern TYPELIB query_cache_type_typelib; 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 #endif
...@@ -501,9 +501,6 @@ THD::THD() ...@@ -501,9 +501,6 @@ THD::THD()
net.vio=0; net.vio=0;
#endif #endif
client_capabilities= 0; // minimalistic client client_capabilities= 0; // minimalistic client
#ifdef HAVE_QUERY_CACHE
query_cache_init_query(&net); // If error on boot
#endif
ull=0; ull=0;
system_thread= NON_SYSTEM_THREAD; system_thread= NON_SYSTEM_THREAD;
cleanup_done= abort_on_warning= no_warnings_for_error= 0; cleanup_done= abort_on_warning= no_warnings_for_error= 0;
...@@ -796,7 +793,7 @@ THD::raise_condition_no_handler(uint sql_errno, ...@@ -796,7 +793,7 @@ THD::raise_condition_no_handler(uint sql_errno,
MYSQL_ERROR *cond= NULL; MYSQL_ERROR *cond= NULL;
DBUG_ENTER("THD::raise_condition_no_handler"); DBUG_ENTER("THD::raise_condition_no_handler");
query_cache_abort(& net); query_cache_abort(&query_cache_tls);
/* FIXME: broken special case */ /* FIXME: broken special case */
if (no_warnings_for_error && (level == MYSQL_ERROR::WARN_LEVEL_ERROR)) if (no_warnings_for_error && (level == MYSQL_ERROR::WARN_LEVEL_ERROR))
......
...@@ -315,6 +315,27 @@ typedef enum enum_diag_condition_item_name ...@@ -315,6 +315,27 @@ typedef enum enum_diag_condition_item_name
*/ */
extern const LEX_STRING Diag_condition_item_names[]; extern const LEX_STRING Diag_condition_item_names[];
/**
Query_cache_tls -- query cache thread local data.
*/
class Query_cache_block;
struct Query_cache_tls
{
/*
'first_query_block' should be accessed only via query cache
functions and methods to maintain proper locking.
*/
Query_cache_block *first_query_block;
void set_first_query_block(Query_cache_block *first_query_block_arg)
{
first_query_block= first_query_block_arg;
}
Query_cache_tls() :first_query_block(NULL) {}
};
#include "sql_lex.h" /* Must be here */ #include "sql_lex.h" /* Must be here */
class Delayed_insert; class Delayed_insert;
...@@ -1239,6 +1260,9 @@ class THD :public Statement, ...@@ -1239,6 +1260,9 @@ class THD :public Statement,
fields then. fields then.
*/ */
struct st_mysql_stmt *current_stmt; struct st_mysql_stmt *current_stmt;
#endif
#ifdef HAVE_QUERY_CACHE
Query_cache_tls query_cache_tls;
#endif #endif
NET net; // client connection descriptor NET net; // client connection descriptor
Protocol *protocol; // Current protocol Protocol *protocol; // Current protocol
......
...@@ -6026,7 +6026,7 @@ void mysql_parse(THD *thd, const char *inBuf, uint length, ...@@ -6026,7 +6026,7 @@ void mysql_parse(THD *thd, const char *inBuf, uint length,
DBUG_PRINT("info",("Command aborted. Fatal_error: %d", DBUG_PRINT("info",("Command aborted. Fatal_error: %d",
thd->is_fatal_error)); thd->is_fatal_error));
query_cache_abort(&thd->net); query_cache_abort(&thd->query_cache_tls);
} }
if (thd->lex->sphead) if (thd->lex->sphead)
{ {
......
...@@ -9187,7 +9187,7 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value) ...@@ -9187,7 +9187,7 @@ remove_eq_conds(THD *thd, COND *cond, Item::cond_result *cond_value)
thd->substitute_null_with_insert_id)) thd->substitute_null_with_insert_id))
{ {
#ifdef HAVE_QUERY_CACHE #ifdef HAVE_QUERY_CACHE
query_cache_abort(&thd->net); query_cache_abort(&thd->query_cache_tls);
#endif #endif
COND *new_cond; COND *new_cond;
if ((new_cond= new Item_func_eq(args[0], if ((new_cond= new Item_func_eq(args[0],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment