2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2001-2006 MySQL AB
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
|
|
|
|
|
|
#ifndef _SQL_CACHE_H
|
|
|
|
#define _SQL_CACHE_H
|
|
|
|
|
|
|
|
/* Query cache */
|
|
|
|
|
|
|
|
/*
|
|
|
|
Can't create new free memory block if unused memory in block less
|
|
|
|
then QUERY_CACHE_MIN_ALLOCATION_UNIT.
|
|
|
|
if QUERY_CACHE_MIN_ALLOCATION_UNIT == 0 then
|
|
|
|
QUERY_CACHE_MIN_ALLOCATION_UNIT choosed automaticaly
|
|
|
|
*/
|
2002-01-12 14:40:52 +01:00
|
|
|
#define QUERY_CACHE_MIN_ALLOCATION_UNIT 512
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
/* inittial size of hashes */
|
|
|
|
#define QUERY_CACHE_DEF_QUERY_HASH_SIZE 1024
|
|
|
|
#define QUERY_CACHE_DEF_TABLE_HASH_SIZE 1024
|
|
|
|
|
|
|
|
/* minimal result data size when data allocated */
|
2002-01-12 14:40:52 +01:00
|
|
|
#define QUERY_CACHE_MIN_RESULT_DATA_SIZE 1024*4
|
|
|
|
|
|
|
|
/*
|
|
|
|
start estimation of first result block size only when number of queries
|
|
|
|
bigger then:
|
|
|
|
*/
|
|
|
|
#define QUERY_CACHE_MIN_ESTIMATED_QUERIES_NUMBER 3
|
|
|
|
|
|
|
|
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
/* memory bins size spacing (see at Query_cache::init_cache (sql_cache.cc)) */
|
|
|
|
#define QUERY_CACHE_MEM_BIN_FIRST_STEP_PWR2 4
|
|
|
|
#define QUERY_CACHE_MEM_BIN_STEP_PWR2 2
|
|
|
|
#define QUERY_CACHE_MEM_BIN_PARTS_INC 1
|
|
|
|
#define QUERY_CACHE_MEM_BIN_PARTS_MUL 1.2
|
|
|
|
#define QUERY_CACHE_MEM_BIN_SPC_LIM_PWR2 3
|
|
|
|
|
2001-12-17 02:02:58 +01:00
|
|
|
/* how many free blocks check when finding most suitable before other 'end'
|
|
|
|
of list of free blocks */
|
|
|
|
#define QUERY_CACHE_MEM_BIN_TRY 5
|
|
|
|
|
2001-12-02 13:34:01 +01:00
|
|
|
/* packing parameters */
|
|
|
|
#define QUERY_CACHE_PACK_ITERATION 2
|
|
|
|
#define QUERY_CACHE_PACK_LIMIT (512*1024L)
|
|
|
|
|
2003-07-30 13:59:56 +02:00
|
|
|
#define TABLE_COUNTER_TYPE uint
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
struct Query_cache_block;
|
|
|
|
struct Query_cache_block_table;
|
|
|
|
struct Query_cache_table;
|
|
|
|
struct Query_cache_query;
|
|
|
|
struct Query_cache_result;
|
|
|
|
class Query_cache;
|
|
|
|
|
|
|
|
|
|
|
|
struct Query_cache_block_table
|
|
|
|
{
|
2006-02-25 16:46:30 +01:00
|
|
|
Query_cache_block_table() {} /* Remove gcc warning */
|
2001-12-02 13:34:01 +01:00
|
|
|
TABLE_COUNTER_TYPE n; // numbr in table (from 0)
|
|
|
|
Query_cache_block_table *next, *prev;
|
|
|
|
Query_cache_table *parent;
|
2001-12-05 12:03:00 +01:00
|
|
|
inline Query_cache_block *block();
|
2001-12-02 13:34:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Query_cache_block
|
|
|
|
{
|
2006-02-25 16:46:30 +01:00
|
|
|
Query_cache_block() {} /* Remove gcc warning */
|
2001-12-02 13:34:01 +01:00
|
|
|
enum block_type {FREE, QUERY, RESULT, RES_CONT, RES_BEG,
|
|
|
|
RES_INCOMPLETE, TABLE, INCOMPLETE};
|
|
|
|
|
|
|
|
ulong length; // length of all block
|
|
|
|
ulong used; // length of data
|
|
|
|
/*
|
|
|
|
Not used **pprev, **prev because really needed access to pervious block:
|
|
|
|
*pprev to join free blocks
|
|
|
|
*prev to access to opposite side of list in cyclic sorted list
|
|
|
|
*/
|
2001-12-05 12:03:00 +01:00
|
|
|
Query_cache_block *pnext,*pprev, // physical next/previous block
|
|
|
|
*next,*prev; // logical next/previous block
|
2001-12-02 13:34:01 +01:00
|
|
|
block_type type;
|
|
|
|
TABLE_COUNTER_TYPE n_tables; // number of tables in query
|
|
|
|
|
|
|
|
inline my_bool is_free(void) { return type == FREE; }
|
|
|
|
void init(ulong length);
|
|
|
|
void destroy();
|
|
|
|
inline uint headers_len();
|
|
|
|
inline gptr data(void);
|
2001-12-05 12:03:00 +01:00
|
|
|
inline Query_cache_query *query();
|
|
|
|
inline Query_cache_table *table();
|
|
|
|
inline Query_cache_result *result();
|
|
|
|
inline Query_cache_block_table *table(TABLE_COUNTER_TYPE n);
|
2001-12-02 13:34:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Query_cache_query
|
|
|
|
{
|
|
|
|
ulonglong limit_found_rows;
|
2002-06-30 11:08:58 +02:00
|
|
|
rw_lock_t lock;
|
2001-12-05 12:03:00 +01:00
|
|
|
Query_cache_block *res;
|
|
|
|
NET *wri;
|
2001-12-02 13:34:01 +01:00
|
|
|
ulong len;
|
2002-11-03 09:15:14 +01:00
|
|
|
uint8 tbls_type;
|
2004-09-17 15:40:38 +02:00
|
|
|
unsigned int last_pkt_nr;
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
inline void init_n_lock();
|
|
|
|
void unlock_n_destroy();
|
|
|
|
inline ulonglong found_rows() { return limit_found_rows; }
|
2002-11-03 09:15:14 +01:00
|
|
|
inline void found_rows(ulonglong rows) { limit_found_rows= rows; }
|
2001-12-05 12:03:00 +01:00
|
|
|
inline Query_cache_block *result() { return res; }
|
2002-11-03 09:15:14 +01:00
|
|
|
inline void result(Query_cache_block *p) { res= p; }
|
2001-12-05 12:03:00 +01:00
|
|
|
inline NET *writer() { return wri; }
|
2002-11-03 09:15:14 +01:00
|
|
|
inline void writer(NET *p) { wri= p; }
|
|
|
|
inline uint8 tables_type() { return tbls_type; }
|
|
|
|
inline void tables_type(uint8 type) { tbls_type= type; }
|
2001-12-02 13:34:01 +01:00
|
|
|
inline ulong length() { return len; }
|
2002-11-03 09:15:14 +01:00
|
|
|
inline ulong add(ulong packet_len) { return(len+= packet_len); }
|
2006-12-14 23:51:37 +01:00
|
|
|
inline void length(ulong length_arg) { len= length_arg; }
|
2001-12-02 13:34:01 +01:00
|
|
|
inline gptr query()
|
|
|
|
{
|
|
|
|
return (gptr)(((byte*)this)+
|
|
|
|
ALIGN_SIZE(sizeof(Query_cache_query)));
|
|
|
|
}
|
|
|
|
void lock_writing();
|
|
|
|
void lock_reading();
|
|
|
|
my_bool try_lock_writing();
|
|
|
|
void unlock_writing();
|
|
|
|
void unlock_reading();
|
2001-12-05 12:03:00 +01:00
|
|
|
static byte *cache_key(const byte *record, uint *length, my_bool not_used);
|
2001-12-02 13:34:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct Query_cache_table
|
|
|
|
{
|
2006-02-25 16:46:30 +01:00
|
|
|
Query_cache_table() {} /* Remove gcc warning */
|
2001-12-05 12:03:00 +01:00
|
|
|
char *tbl;
|
2004-10-27 18:52:41 +02:00
|
|
|
uint32 key_len;
|
2002-11-03 09:15:14 +01:00
|
|
|
uint8 table_type;
|
sql/ha_innodb.cc
enabled query cache for ndb
modified engine interface somewhat
sql/ha_innodb.h
enabled query cache for ndb
modified engine interface somewhat
sql/ha_ndbcluster.cc
enabled query cache for ndb
modified engine interface somewhat
ndb will only allow caching and retrieval if running autocommit
- return false, but do not invalidate
commit count is used as engine data, i.e.
- store commit count before store of cache
- allow retrieval if commit count has not changed on a table
- invalidate if commit count has changed
sql/ha_ndbcluster.h
enabled query cache for ndb
modified engine interface somewhat
sql/handler.cc
enabled query cache for ndb
modified engine interface somewhat
sql/handler.h
enabled query cache for ndb
modified engine interface somewhat
new virtual handler method cached_table_registration called on each table before alowing store in query cache
- return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed
- sets ulonglong (engine_data) that is stored in query cache for each table
- sets callback to be called for each table before usage of cached query, callback = 0 -> no check later
sql/mysql_priv.h
enabled query cache for ndb
modified engine interface somewhat
callcack prototype for callback to engine before query cache retrieval
sql/sql_cache.cc
enabled query cache for ndb
modified engine interface somewhat
if callback is set on table in cache, do callback to check if allowed to use cache
if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table
+ changes to store and pass callback and engine_data around
sql/sql_cache.h
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
sql/table.h
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
sql/ha_innodb.cc:
enabled query cache for ndb
modified engine interface somewhat
sql/ha_innodb.h:
enabled query cache for ndb
modified engine interface somewhat
sql/ha_ndbcluster.cc:
enabled query cache for ndb
modified engine interface somewhat
ndb will only allow caching and retrieval if running autocommit
- return false, but do not invalidate
commit count is used as engine data, i.e.
- store commit count before store of cache
- allow retrieval if commit count has not changed on a table
- invalidate if commit count has changed
sql/ha_ndbcluster.h:
enabled query cache for ndb
modified engine interface somewhat
sql/handler.cc:
enabled query cache for ndb
modified engine interface somewhat
sql/handler.h:
enabled query cache for ndb
modified engine interface somewhat
new virtual handler method cached_table_registration called on each table before alowing store in query cache
- return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed
- sets ulonglong (engine_data) that is stored in query cache for each table
- sets callback to be called for each table before usage of cached query, callback = 0 -> no check later
sql/mysql_priv.h:
enabled query cache for ndb
modified engine interface somewhat
callcack prototype for callback to engine before query cache retrieval
sql/sql_cache.cc:
enabled query cache for ndb
modified engine interface somewhat
if callback is set on table in cache, do callback to check if allowed to use cache
if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table
+ changes to store and pass callback and engine_data around
sql/sql_cache.h:
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
sql/table.h:
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
2004-11-24 12:56:51 +01:00
|
|
|
/* unique for every engine reference */
|
|
|
|
qc_engine_callback callback_func;
|
|
|
|
/* data need by some engines */
|
|
|
|
ulonglong engine_data_buff;
|
2001-12-02 13:34:01 +01:00
|
|
|
|
2001-12-05 12:03:00 +01:00
|
|
|
inline char *db() { return (char *) data(); }
|
|
|
|
inline char *table() { return tbl; }
|
2006-12-14 23:51:37 +01:00
|
|
|
inline void table(char *table_arg) { tbl= table_arg; }
|
2004-10-27 18:52:41 +02:00
|
|
|
inline uint32 key_length() { return key_len; }
|
|
|
|
inline void key_length(uint32 len) { key_len= len; }
|
2002-11-03 09:15:14 +01:00
|
|
|
inline uint8 type() { return table_type; }
|
|
|
|
inline void type(uint8 t) { table_type= t; }
|
sql/ha_innodb.cc
enabled query cache for ndb
modified engine interface somewhat
sql/ha_innodb.h
enabled query cache for ndb
modified engine interface somewhat
sql/ha_ndbcluster.cc
enabled query cache for ndb
modified engine interface somewhat
ndb will only allow caching and retrieval if running autocommit
- return false, but do not invalidate
commit count is used as engine data, i.e.
- store commit count before store of cache
- allow retrieval if commit count has not changed on a table
- invalidate if commit count has changed
sql/ha_ndbcluster.h
enabled query cache for ndb
modified engine interface somewhat
sql/handler.cc
enabled query cache for ndb
modified engine interface somewhat
sql/handler.h
enabled query cache for ndb
modified engine interface somewhat
new virtual handler method cached_table_registration called on each table before alowing store in query cache
- return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed
- sets ulonglong (engine_data) that is stored in query cache for each table
- sets callback to be called for each table before usage of cached query, callback = 0 -> no check later
sql/mysql_priv.h
enabled query cache for ndb
modified engine interface somewhat
callcack prototype for callback to engine before query cache retrieval
sql/sql_cache.cc
enabled query cache for ndb
modified engine interface somewhat
if callback is set on table in cache, do callback to check if allowed to use cache
if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table
+ changes to store and pass callback and engine_data around
sql/sql_cache.h
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
sql/table.h
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
sql/ha_innodb.cc:
enabled query cache for ndb
modified engine interface somewhat
sql/ha_innodb.h:
enabled query cache for ndb
modified engine interface somewhat
sql/ha_ndbcluster.cc:
enabled query cache for ndb
modified engine interface somewhat
ndb will only allow caching and retrieval if running autocommit
- return false, but do not invalidate
commit count is used as engine data, i.e.
- store commit count before store of cache
- allow retrieval if commit count has not changed on a table
- invalidate if commit count has changed
sql/ha_ndbcluster.h:
enabled query cache for ndb
modified engine interface somewhat
sql/handler.cc:
enabled query cache for ndb
modified engine interface somewhat
sql/handler.h:
enabled query cache for ndb
modified engine interface somewhat
new virtual handler method cached_table_registration called on each table before alowing store in query cache
- return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed
- sets ulonglong (engine_data) that is stored in query cache for each table
- sets callback to be called for each table before usage of cached query, callback = 0 -> no check later
sql/mysql_priv.h:
enabled query cache for ndb
modified engine interface somewhat
callcack prototype for callback to engine before query cache retrieval
sql/sql_cache.cc:
enabled query cache for ndb
modified engine interface somewhat
if callback is set on table in cache, do callback to check if allowed to use cache
if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table
+ changes to store and pass callback and engine_data around
sql/sql_cache.h:
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
sql/table.h:
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
2004-11-24 12:56:51 +01:00
|
|
|
inline qc_engine_callback callback() { return callback_func; }
|
|
|
|
inline void callback(qc_engine_callback fn){ callback_func= fn; }
|
|
|
|
inline ulonglong engine_data() { return engine_data_buff; }
|
2006-12-14 23:51:37 +01:00
|
|
|
inline void engine_data(ulonglong data_arg){ engine_data_buff= data_arg; }
|
2001-12-02 13:34:01 +01:00
|
|
|
inline gptr data()
|
|
|
|
{
|
|
|
|
return (gptr)(((byte*)this)+
|
|
|
|
ALIGN_SIZE(sizeof(Query_cache_table)));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Query_cache_result
|
|
|
|
{
|
2006-02-25 16:46:30 +01:00
|
|
|
Query_cache_result() {} /* Remove gcc warning */
|
2001-12-02 13:34:01 +01:00
|
|
|
Query_cache_block *query;
|
|
|
|
|
2001-12-05 12:03:00 +01:00
|
|
|
inline gptr data()
|
|
|
|
{
|
|
|
|
return (gptr)(((byte*) this)+
|
|
|
|
ALIGN_SIZE(sizeof(Query_cache_result)));
|
|
|
|
}
|
2001-12-02 13:34:01 +01:00
|
|
|
/* data_continue (if not whole packet contained by this block) */
|
2001-12-05 12:03:00 +01:00
|
|
|
inline Query_cache_block *parent() { return query; }
|
2001-12-02 13:34:01 +01:00
|
|
|
inline void parent (Query_cache_block *p) { query=p; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2002-09-24 16:11:59 +02:00
|
|
|
extern "C"
|
|
|
|
{
|
2001-12-05 12:03:00 +01:00
|
|
|
byte *query_cache_query_get_key(const byte *record, uint *length,
|
|
|
|
my_bool not_used);
|
|
|
|
byte *query_cache_table_get_key(const byte *record, uint *length,
|
|
|
|
my_bool not_used);
|
2001-12-02 13:34:01 +01:00
|
|
|
}
|
2002-11-07 02:54:00 +01:00
|
|
|
extern "C" void query_cache_invalidate_by_MyISAM_filename(const char* filename);
|
2002-09-24 16:11:59 +02:00
|
|
|
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
struct Query_cache_memory_bin
|
|
|
|
{
|
2006-02-25 16:46:30 +01:00
|
|
|
Query_cache_memory_bin() {} /* Remove gcc warning */
|
2001-12-02 13:34:01 +01:00
|
|
|
#ifndef DBUG_OFF
|
|
|
|
ulong size;
|
|
|
|
#endif
|
|
|
|
uint number;
|
2001-12-05 12:03:00 +01:00
|
|
|
Query_cache_block *free_blocks;
|
2001-12-02 13:34:01 +01:00
|
|
|
|
2002-07-23 17:31:22 +02:00
|
|
|
inline void init(ulong size_arg)
|
2001-12-02 13:34:01 +01:00
|
|
|
{
|
|
|
|
#ifndef DBUG_OFF
|
2002-07-23 17:31:22 +02:00
|
|
|
size = size_arg;
|
2001-12-02 13:34:01 +01:00
|
|
|
#endif
|
|
|
|
number = 0;
|
|
|
|
free_blocks = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Query_cache_memory_bin_step
|
|
|
|
{
|
2006-02-25 16:46:30 +01:00
|
|
|
Query_cache_memory_bin_step() {} /* Remove gcc warning */
|
2001-12-02 13:34:01 +01:00
|
|
|
ulong size;
|
|
|
|
ulong increment;
|
|
|
|
uint idx;
|
2002-07-23 17:31:22 +02:00
|
|
|
inline void init(ulong size_arg, uint idx_arg, ulong increment_arg)
|
2001-12-02 13:34:01 +01:00
|
|
|
{
|
2002-07-23 17:31:22 +02:00
|
|
|
size = size_arg;
|
|
|
|
idx = idx_arg;
|
|
|
|
increment = increment_arg;
|
2001-12-02 13:34:01 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Query_cache
|
|
|
|
{
|
|
|
|
public:
|
2001-12-05 12:03:00 +01:00
|
|
|
/* Info */
|
|
|
|
ulong query_cache_size, query_cache_limit;
|
|
|
|
/* statistics */
|
2001-12-09 23:08:24 +01:00
|
|
|
ulong free_memory, queries_in_cache, hits, inserts, refused,
|
2002-11-17 19:41:25 +01:00
|
|
|
free_memory_blocks, total_blocks, lowmem_prunes;
|
2001-12-02 13:34:01 +01:00
|
|
|
|
BUG#21051: RESET QUERY CACHE very slow when query_cache_type=0
There were two problems: RESET QUERY CACHE took a long time to complete
and other threads were blocked during this time.
The patch does three things:
1 fixes a bug with improper use of test-lock-test_again technique.
AKA Double-Checked Locking is applicable here only in few places.
2 Somewhat improves performance of RESET QUERY CACHE.
Do my_hash_reset() instead of deleting elements one by one. Note
however that the slowdown also happens when inserting into sorted
list of free blocks, should be rewritten using balanced tree.
3 Makes RESET QUERY CACHE non-blocking.
The patch adjusts the locking protocol of the query cache in the
following way: it introduces a flag flush_in_progress, which is
set when Query_cache::flush_cache() is in progress. This call
sets the flag on enter, and then releases the lock. Every other
call is able to acquire the lock, but does nothing if
flush_in_progress is set (as if the query cache is disabled).
The only exception is the concurrent calls to
Query_cache::flush_cache(), that are blocked until the flush is
over. When leaving Query_cache::flush_cache(), the lock is
acquired and the flag is reset, and one thread waiting on
Query_cache::flush_cache() (if any) is notified that it may
proceed.
include/mysql_com.h:
Add comment for NET::query_cache_query.
sql/net_serv.cc:
Use query_cache_init_query() for initialization of
NET::query_cache_query if query cache is used.
Do not access net->query_cache_query without a lock.
sql/sql_cache.cc:
Fix bug with accessing query_cache_size, Query_cache_query::wri and
thd->net.query_cache_query before acquiring the lock---leave
double-check locking only in safe places.
Wherever we check that cache is usable (query_cache_size > 0) we now
also check that flush_in_progress is false, i.e. we are not in the
middle of cache flush.
Add Query_cache::not_in_flush_or_wait() method and use it in
Query_cache::flush_cache(), so that threads doing cache flush will
wait it to finish, while other threads will bypass the cache as if
it is disabled.
Extract Query_cache::free_query_internal() from Query_cache::free_query(),
which does not removes elements from the hash, and use it together with
my_hash_reset() in Query_cache::flush_cache().
sql/sql_cache.h:
Add declarations for new members and methods.
Make is_cacheable() a static method.
Add query_cache_init_query() function.
sql/sql_class.cc:
Use query_cache_init_query() for initialization of
NET::query_cache_query.
2006-08-22 09:47:52 +02:00
|
|
|
private:
|
|
|
|
pthread_cond_t COND_flush_finished;
|
|
|
|
bool flush_in_progress;
|
|
|
|
|
|
|
|
void free_query_internal(Query_cache_block *point);
|
|
|
|
|
2001-12-05 12:03:00 +01:00
|
|
|
protected:
|
2001-12-02 13:34:01 +01:00
|
|
|
/*
|
2001-12-05 12:03:00 +01:00
|
|
|
The following mutex is locked when searching or changing global
|
|
|
|
query, tables lists or hashes. When we are operating inside the
|
|
|
|
query structure we locked an internal query block mutex.
|
|
|
|
LOCK SEQUENCE (to prevent deadlocks):
|
2001-12-02 13:34:01 +01:00
|
|
|
1. structure_guard_mutex
|
2002-01-12 14:40:52 +01:00
|
|
|
2. query block (for operation inside query (query block/results))
|
BUG#21051: RESET QUERY CACHE very slow when query_cache_type=0
There were two problems: RESET QUERY CACHE took a long time to complete
and other threads were blocked during this time.
The patch does three things:
1 fixes a bug with improper use of test-lock-test_again technique.
AKA Double-Checked Locking is applicable here only in few places.
2 Somewhat improves performance of RESET QUERY CACHE.
Do my_hash_reset() instead of deleting elements one by one. Note
however that the slowdown also happens when inserting into sorted
list of free blocks, should be rewritten using balanced tree.
3 Makes RESET QUERY CACHE non-blocking.
The patch adjusts the locking protocol of the query cache in the
following way: it introduces a flag flush_in_progress, which is
set when Query_cache::flush_cache() is in progress. This call
sets the flag on enter, and then releases the lock. Every other
call is able to acquire the lock, but does nothing if
flush_in_progress is set (as if the query cache is disabled).
The only exception is the concurrent calls to
Query_cache::flush_cache(), that are blocked until the flush is
over. When leaving Query_cache::flush_cache(), the lock is
acquired and the flag is reset, and one thread waiting on
Query_cache::flush_cache() (if any) is notified that it may
proceed.
include/mysql_com.h:
Add comment for NET::query_cache_query.
sql/net_serv.cc:
Use query_cache_init_query() for initialization of
NET::query_cache_query if query cache is used.
Do not access net->query_cache_query without a lock.
sql/sql_cache.cc:
Fix bug with accessing query_cache_size, Query_cache_query::wri and
thd->net.query_cache_query before acquiring the lock---leave
double-check locking only in safe places.
Wherever we check that cache is usable (query_cache_size > 0) we now
also check that flush_in_progress is false, i.e. we are not in the
middle of cache flush.
Add Query_cache::not_in_flush_or_wait() method and use it in
Query_cache::flush_cache(), so that threads doing cache flush will
wait it to finish, while other threads will bypass the cache as if
it is disabled.
Extract Query_cache::free_query_internal() from Query_cache::free_query(),
which does not removes elements from the hash, and use it together with
my_hash_reset() in Query_cache::flush_cache().
sql/sql_cache.h:
Add declarations for new members and methods.
Make is_cacheable() a static method.
Add query_cache_init_query() function.
sql/sql_class.cc:
Use query_cache_init_query() for initialization of
NET::query_cache_query.
2006-08-22 09:47:52 +02:00
|
|
|
|
|
|
|
Thread doing cache flush releases the mutex once it sets
|
|
|
|
flush_in_progress 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.
|
2001-12-02 13:34:01 +01:00
|
|
|
*/
|
|
|
|
pthread_mutex_t structure_guard_mutex;
|
2001-12-05 12:03:00 +01:00
|
|
|
byte *cache; // cache memory
|
|
|
|
Query_cache_block *first_block; // physical location block list
|
|
|
|
Query_cache_block *queries_blocks; // query list (LIFO)
|
2002-03-15 22:57:31 +01:00
|
|
|
Query_cache_block *tables_blocks;
|
2001-12-02 13:34:01 +01:00
|
|
|
|
2001-12-05 12:03:00 +01:00
|
|
|
Query_cache_memory_bin *bins; // free block lists
|
|
|
|
Query_cache_memory_bin_step *steps; // bins spacing info
|
2001-12-02 13:34:01 +01:00
|
|
|
HASH queries, tables;
|
2001-12-05 12:03:00 +01:00
|
|
|
/* options */
|
|
|
|
ulong min_allocation_unit, min_result_data_size;
|
|
|
|
uint def_query_hash_size, def_table_hash_size;
|
2001-12-06 00:05:30 +01:00
|
|
|
uint mem_bin_num, mem_bin_steps; // See at init_cache & find_bin
|
|
|
|
|
|
|
|
my_bool initialized;
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
/* Exclude/include from cyclic double linked list */
|
2001-12-05 12:03:00 +01:00
|
|
|
static void double_linked_list_exclude(Query_cache_block *point,
|
|
|
|
Query_cache_block **list_pointer);
|
|
|
|
static void double_linked_list_simple_include(Query_cache_block *point,
|
|
|
|
Query_cache_block **
|
|
|
|
list_pointer);
|
2001-12-02 13:34:01 +01:00
|
|
|
static void double_linked_list_join(Query_cache_block *head_tail,
|
|
|
|
Query_cache_block *tail_head);
|
|
|
|
|
|
|
|
/* Table key generation */
|
2002-03-15 22:57:31 +01:00
|
|
|
static uint filename_2_table_key (char *key, const char *filename,
|
|
|
|
uint32 *db_langth);
|
2001-12-02 13:34:01 +01:00
|
|
|
|
2001-12-05 12:03:00 +01:00
|
|
|
/* The following functions require that structure_guard_mutex is locked */
|
2001-12-02 13:34:01 +01:00
|
|
|
void flush_cache();
|
|
|
|
my_bool free_old_query();
|
2001-12-05 12:03:00 +01:00
|
|
|
void free_query(Query_cache_block *point);
|
|
|
|
my_bool allocate_data_chain(Query_cache_block **result_block,
|
2001-12-02 13:34:01 +01:00
|
|
|
ulong data_len,
|
2002-01-12 14:40:52 +01:00
|
|
|
Query_cache_block *query_block,
|
|
|
|
my_bool first_block);
|
2001-12-02 13:34:01 +01:00
|
|
|
void invalidate_table(TABLE_LIST *table);
|
|
|
|
void invalidate_table(TABLE *table);
|
2002-03-15 22:57:31 +01:00
|
|
|
void invalidate_table(byte *key, uint32 key_length);
|
2001-12-02 13:34:01 +01:00
|
|
|
void invalidate_table(Query_cache_block *table_block);
|
2005-01-27 13:21:37 +01:00
|
|
|
TABLE_COUNTER_TYPE
|
|
|
|
register_tables_from_list(TABLE_LIST *tables_used,
|
|
|
|
TABLE_COUNTER_TYPE counter,
|
|
|
|
Query_cache_block_table *block_table);
|
2001-12-05 12:03:00 +01:00
|
|
|
my_bool register_all_tables(Query_cache_block *block,
|
|
|
|
TABLE_LIST *tables_used,
|
2001-12-02 13:34:01 +01:00
|
|
|
TABLE_COUNTER_TYPE tables);
|
2001-12-05 12:03:00 +01:00
|
|
|
my_bool insert_table(uint key_len, char *key,
|
|
|
|
Query_cache_block_table *node,
|
sql/ha_innodb.cc
enabled query cache for ndb
modified engine interface somewhat
sql/ha_innodb.h
enabled query cache for ndb
modified engine interface somewhat
sql/ha_ndbcluster.cc
enabled query cache for ndb
modified engine interface somewhat
ndb will only allow caching and retrieval if running autocommit
- return false, but do not invalidate
commit count is used as engine data, i.e.
- store commit count before store of cache
- allow retrieval if commit count has not changed on a table
- invalidate if commit count has changed
sql/ha_ndbcluster.h
enabled query cache for ndb
modified engine interface somewhat
sql/handler.cc
enabled query cache for ndb
modified engine interface somewhat
sql/handler.h
enabled query cache for ndb
modified engine interface somewhat
new virtual handler method cached_table_registration called on each table before alowing store in query cache
- return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed
- sets ulonglong (engine_data) that is stored in query cache for each table
- sets callback to be called for each table before usage of cached query, callback = 0 -> no check later
sql/mysql_priv.h
enabled query cache for ndb
modified engine interface somewhat
callcack prototype for callback to engine before query cache retrieval
sql/sql_cache.cc
enabled query cache for ndb
modified engine interface somewhat
if callback is set on table in cache, do callback to check if allowed to use cache
if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table
+ changes to store and pass callback and engine_data around
sql/sql_cache.h
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
sql/table.h
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
sql/ha_innodb.cc:
enabled query cache for ndb
modified engine interface somewhat
sql/ha_innodb.h:
enabled query cache for ndb
modified engine interface somewhat
sql/ha_ndbcluster.cc:
enabled query cache for ndb
modified engine interface somewhat
ndb will only allow caching and retrieval if running autocommit
- return false, but do not invalidate
commit count is used as engine data, i.e.
- store commit count before store of cache
- allow retrieval if commit count has not changed on a table
- invalidate if commit count has changed
sql/ha_ndbcluster.h:
enabled query cache for ndb
modified engine interface somewhat
sql/handler.cc:
enabled query cache for ndb
modified engine interface somewhat
sql/handler.h:
enabled query cache for ndb
modified engine interface somewhat
new virtual handler method cached_table_registration called on each table before alowing store in query cache
- return TRUE - ok to cache, FALSE - not allowed to cache, invalidate queries if engine_data below has changed
- sets ulonglong (engine_data) that is stored in query cache for each table
- sets callback to be called for each table before usage of cached query, callback = 0 -> no check later
sql/mysql_priv.h:
enabled query cache for ndb
modified engine interface somewhat
callcack prototype for callback to engine before query cache retrieval
sql/sql_cache.cc:
enabled query cache for ndb
modified engine interface somewhat
if callback is set on table in cache, do callback to check if allowed to use cache
if not allowed to use cache, check if engine_data has changed, if so, invalidate all queries with that table
+ changes to store and pass callback and engine_data around
sql/sql_cache.h:
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
sql/table.h:
enabled query cache for ndb
modified engine interface somewhat
changes to store callback and engine_data
2004-11-24 12:56:51 +01:00
|
|
|
uint32 db_length, uint8 cache_type,
|
|
|
|
qc_engine_callback callback,
|
|
|
|
ulonglong engine_data);
|
2001-12-05 12:03:00 +01:00
|
|
|
void unlink_table(Query_cache_block_table *node);
|
|
|
|
Query_cache_block *get_free_block (ulong len, my_bool not_less,
|
2001-12-02 13:34:01 +01:00
|
|
|
ulong min);
|
2001-12-05 12:03:00 +01:00
|
|
|
void free_memory_block(Query_cache_block *point);
|
2001-12-02 13:34:01 +01:00
|
|
|
void split_block(Query_cache_block *block, ulong len);
|
2001-12-05 12:03:00 +01:00
|
|
|
Query_cache_block *join_free_blocks(Query_cache_block *first_block,
|
|
|
|
Query_cache_block *block_in_list);
|
|
|
|
my_bool append_next_free_block(Query_cache_block *block,
|
2001-12-02 13:34:01 +01:00
|
|
|
ulong add_size);
|
2001-12-05 12:03:00 +01:00
|
|
|
void exclude_from_free_memory_list(Query_cache_block *free_block);
|
|
|
|
void insert_into_free_memory_list(Query_cache_block *new_block);
|
|
|
|
my_bool move_by_type(byte **border, Query_cache_block **before,
|
|
|
|
ulong *gap, Query_cache_block *i);
|
2001-12-02 13:34:01 +01:00
|
|
|
uint find_bin(ulong size);
|
2001-12-05 12:03:00 +01:00
|
|
|
void move_to_query_list_end(Query_cache_block *block);
|
|
|
|
void insert_into_free_memory_sorted_list(Query_cache_block *new_block,
|
|
|
|
Query_cache_block **list);
|
2001-12-02 13:34:01 +01:00
|
|
|
void pack_cache();
|
2001-12-05 12:03:00 +01:00
|
|
|
void relink(Query_cache_block *oblock,
|
|
|
|
Query_cache_block *nblock,
|
|
|
|
Query_cache_block *next,
|
|
|
|
Query_cache_block *prev,
|
|
|
|
Query_cache_block *pnext,
|
|
|
|
Query_cache_block *pprev);
|
2001-12-02 13:34:01 +01:00
|
|
|
my_bool join_results(ulong join_limit);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Following function control structure_guard_mutex
|
|
|
|
by themself or don't need structure_guard_mutex
|
|
|
|
*/
|
|
|
|
ulong init_cache();
|
|
|
|
void make_disabled();
|
2005-09-06 10:16:53 +02:00
|
|
|
void free_cache();
|
2001-12-05 12:03:00 +01:00
|
|
|
Query_cache_block *write_block_data(ulong data_len, gptr data,
|
2001-12-02 13:34:01 +01:00
|
|
|
ulong header_len,
|
|
|
|
Query_cache_block::block_type type,
|
|
|
|
TABLE_COUNTER_TYPE ntab = 0,
|
|
|
|
my_bool under_guard=0);
|
2001-12-05 12:03:00 +01:00
|
|
|
my_bool append_result_data(Query_cache_block **result,
|
2001-12-02 13:34:01 +01:00
|
|
|
ulong data_len, gptr data,
|
2001-12-05 12:03:00 +01:00
|
|
|
Query_cache_block *parent);
|
|
|
|
my_bool write_result_data(Query_cache_block **result,
|
2001-12-02 13:34:01 +01:00
|
|
|
ulong data_len, gptr data,
|
2001-12-05 12:03:00 +01:00
|
|
|
Query_cache_block *parent,
|
2001-12-02 13:34:01 +01:00
|
|
|
Query_cache_block::block_type
|
|
|
|
type=Query_cache_block::RESULT);
|
2002-01-12 14:40:52 +01:00
|
|
|
inline ulong get_min_first_result_data_size();
|
|
|
|
inline ulong get_min_append_result_data_size();
|
2001-12-05 12:03:00 +01:00
|
|
|
Query_cache_block *allocate_block(ulong len, my_bool not_less,
|
2001-12-02 13:34:01 +01:00
|
|
|
ulong min,
|
|
|
|
my_bool under_guard=0);
|
|
|
|
/*
|
2001-12-05 12:03:00 +01:00
|
|
|
If query is cacheable return number tables in query
|
2001-12-02 13:34:01 +01:00
|
|
|
(query without tables not cached)
|
|
|
|
*/
|
2001-12-05 12:03:00 +01:00
|
|
|
TABLE_COUNTER_TYPE is_cacheable(THD *thd, uint32 query_len, char *query,
|
2007-08-17 16:55:20 +02:00
|
|
|
LEX *lex, TABLE_LIST *tables_used,
|
|
|
|
uint8 *tables_type);
|
|
|
|
TABLE_COUNTER_TYPE process_and_count_tables(THD *thd,
|
|
|
|
TABLE_LIST *tables_used,
|
|
|
|
uint8 *tables_type);
|
2003-08-12 22:45:04 +02:00
|
|
|
|
|
|
|
static my_bool ask_handler_allowance(THD *thd, TABLE_LIST *tables_used);
|
2001-12-02 13:34:01 +01:00
|
|
|
public:
|
|
|
|
|
|
|
|
Query_cache(ulong query_cache_limit = ULONG_MAX,
|
|
|
|
ulong min_allocation_unit = QUERY_CACHE_MIN_ALLOCATION_UNIT,
|
|
|
|
ulong min_result_data_size = QUERY_CACHE_MIN_RESULT_DATA_SIZE,
|
|
|
|
uint def_query_hash_size = QUERY_CACHE_DEF_QUERY_HASH_SIZE,
|
2001-12-05 12:03:00 +01:00
|
|
|
uint def_table_hash_size = QUERY_CACHE_DEF_TABLE_HASH_SIZE);
|
2001-12-02 13:34:01 +01:00
|
|
|
|
2005-09-06 10:16:53 +02:00
|
|
|
/* initialize cache (mutex) */
|
|
|
|
void init();
|
2001-12-02 13:34:01 +01:00
|
|
|
/* resize query cache (return real query size, 0 if disabled) */
|
|
|
|
ulong resize(ulong query_cache_size);
|
2003-03-02 20:39:03 +01:00
|
|
|
/* set limit on result size */
|
2001-12-02 13:34:01 +01:00
|
|
|
inline void result_size_limit(ulong limit){query_cache_limit=limit;}
|
2003-03-02 20:39:03 +01:00
|
|
|
/* set minimal result data allocation unit size */
|
|
|
|
ulong set_min_res_unit(ulong size);
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
/* register query in cache */
|
|
|
|
void store_query(THD *thd, TABLE_LIST *used_tables);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Check if the query is in the cache and if this is true send the
|
|
|
|
data to client.
|
|
|
|
*/
|
2001-12-22 14:13:31 +01:00
|
|
|
int send_result_to_client(THD *thd, char *query, uint query_length);
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
/* Remove all queries that uses any of the listed following tables */
|
2002-03-15 22:57:31 +01:00
|
|
|
void invalidate(THD* thd, TABLE_LIST *tables_used,
|
|
|
|
my_bool using_transactions);
|
|
|
|
void invalidate(CHANGED_TABLE_LIST *tables_used);
|
2004-03-04 17:32:55 +01:00
|
|
|
void invalidate_locked_for_write(TABLE_LIST *tables_used);
|
2002-03-15 22:57:31 +01:00
|
|
|
void invalidate(THD* thd, TABLE *table, my_bool using_transactions);
|
2002-09-19 09:36:19 +02:00
|
|
|
void invalidate(THD *thd, const char *key, uint32 key_length,
|
|
|
|
my_bool using_transactions);
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
/* Remove all queries that uses any of the tables in following database */
|
2001-12-05 12:03:00 +01:00
|
|
|
void invalidate(char *db);
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
/* Remove all queries that uses any of the listed following table */
|
2001-12-05 12:03:00 +01:00
|
|
|
void invalidate_by_MyISAM_filename(const char *filename);
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
void flush();
|
|
|
|
void pack(ulong join_limit = QUERY_CACHE_PACK_LIMIT,
|
|
|
|
uint iteration_limit = QUERY_CACHE_PACK_ITERATION);
|
|
|
|
|
|
|
|
void destroy();
|
|
|
|
|
BUG#21051: RESET QUERY CACHE very slow when query_cache_type=0
There were two problems: RESET QUERY CACHE took a long time to complete
and other threads were blocked during this time.
The patch does three things:
1 fixes a bug with improper use of test-lock-test_again technique.
AKA Double-Checked Locking is applicable here only in few places.
2 Somewhat improves performance of RESET QUERY CACHE.
Do my_hash_reset() instead of deleting elements one by one. Note
however that the slowdown also happens when inserting into sorted
list of free blocks, should be rewritten using balanced tree.
3 Makes RESET QUERY CACHE non-blocking.
The patch adjusts the locking protocol of the query cache in the
following way: it introduces a flag flush_in_progress, which is
set when Query_cache::flush_cache() is in progress. This call
sets the flag on enter, and then releases the lock. Every other
call is able to acquire the lock, but does nothing if
flush_in_progress is set (as if the query cache is disabled).
The only exception is the concurrent calls to
Query_cache::flush_cache(), that are blocked until the flush is
over. When leaving Query_cache::flush_cache(), the lock is
acquired and the flag is reset, and one thread waiting on
Query_cache::flush_cache() (if any) is notified that it may
proceed.
include/mysql_com.h:
Add comment for NET::query_cache_query.
sql/net_serv.cc:
Use query_cache_init_query() for initialization of
NET::query_cache_query if query cache is used.
Do not access net->query_cache_query without a lock.
sql/sql_cache.cc:
Fix bug with accessing query_cache_size, Query_cache_query::wri and
thd->net.query_cache_query before acquiring the lock---leave
double-check locking only in safe places.
Wherever we check that cache is usable (query_cache_size > 0) we now
also check that flush_in_progress is false, i.e. we are not in the
middle of cache flush.
Add Query_cache::not_in_flush_or_wait() method and use it in
Query_cache::flush_cache(), so that threads doing cache flush will
wait it to finish, while other threads will bypass the cache as if
it is disabled.
Extract Query_cache::free_query_internal() from Query_cache::free_query(),
which does not removes elements from the hash, and use it together with
my_hash_reset() in Query_cache::flush_cache().
sql/sql_cache.h:
Add declarations for new members and methods.
Make is_cacheable() a static method.
Add query_cache_init_query() function.
sql/sql_class.cc:
Use query_cache_init_query() for initialization of
NET::query_cache_query.
2006-08-22 09:47:52 +02:00
|
|
|
friend void query_cache_init_query(NET *net);
|
2001-12-22 14:13:31 +01:00
|
|
|
friend void query_cache_insert(NET *net, const char *packet, ulong length);
|
2003-12-01 14:19:10 +01:00
|
|
|
friend void query_cache_end_of_result(THD *thd);
|
2001-12-22 14:13:31 +01:00
|
|
|
friend void query_cache_abort(NET *net);
|
|
|
|
|
|
|
|
/*
|
|
|
|
The following functions are only used when debugging
|
2005-11-22 23:50:37 +01:00
|
|
|
We don't protect these with ifndef DBUG_OFF to not have to recompile
|
2001-12-22 14:13:31 +01:00
|
|
|
everything if we want to add checks of the cache at some places.
|
|
|
|
*/
|
2001-12-05 12:03:00 +01:00
|
|
|
void wreck(uint line, const char *message);
|
2001-12-02 13:34:01 +01:00
|
|
|
void bins_dump();
|
|
|
|
void cache_dump();
|
|
|
|
void queries_dump();
|
|
|
|
void tables_dump();
|
2002-01-03 18:04:01 +01:00
|
|
|
my_bool check_integrity(bool not_locked);
|
2001-12-13 01:31:19 +01:00
|
|
|
my_bool in_list(Query_cache_block * root, Query_cache_block * point,
|
|
|
|
const char *name);
|
2002-01-05 21:51:42 +01:00
|
|
|
my_bool in_table_list(Query_cache_block_table * root,
|
|
|
|
Query_cache_block_table * point,
|
|
|
|
const char *name);
|
2001-12-13 01:31:19 +01:00
|
|
|
my_bool in_blocks(Query_cache_block * point);
|
2001-12-02 13:34:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extern Query_cache query_cache;
|
2002-07-23 17:31:22 +02:00
|
|
|
extern TYPELIB query_cache_type_typelib;
|
BUG#21051: RESET QUERY CACHE very slow when query_cache_type=0
There were two problems: RESET QUERY CACHE took a long time to complete
and other threads were blocked during this time.
The patch does three things:
1 fixes a bug with improper use of test-lock-test_again technique.
AKA Double-Checked Locking is applicable here only in few places.
2 Somewhat improves performance of RESET QUERY CACHE.
Do my_hash_reset() instead of deleting elements one by one. Note
however that the slowdown also happens when inserting into sorted
list of free blocks, should be rewritten using balanced tree.
3 Makes RESET QUERY CACHE non-blocking.
The patch adjusts the locking protocol of the query cache in the
following way: it introduces a flag flush_in_progress, which is
set when Query_cache::flush_cache() is in progress. This call
sets the flag on enter, and then releases the lock. Every other
call is able to acquire the lock, but does nothing if
flush_in_progress is set (as if the query cache is disabled).
The only exception is the concurrent calls to
Query_cache::flush_cache(), that are blocked until the flush is
over. When leaving Query_cache::flush_cache(), the lock is
acquired and the flag is reset, and one thread waiting on
Query_cache::flush_cache() (if any) is notified that it may
proceed.
include/mysql_com.h:
Add comment for NET::query_cache_query.
sql/net_serv.cc:
Use query_cache_init_query() for initialization of
NET::query_cache_query if query cache is used.
Do not access net->query_cache_query without a lock.
sql/sql_cache.cc:
Fix bug with accessing query_cache_size, Query_cache_query::wri and
thd->net.query_cache_query before acquiring the lock---leave
double-check locking only in safe places.
Wherever we check that cache is usable (query_cache_size > 0) we now
also check that flush_in_progress is false, i.e. we are not in the
middle of cache flush.
Add Query_cache::not_in_flush_or_wait() method and use it in
Query_cache::flush_cache(), so that threads doing cache flush will
wait it to finish, while other threads will bypass the cache as if
it is disabled.
Extract Query_cache::free_query_internal() from Query_cache::free_query(),
which does not removes elements from the hash, and use it together with
my_hash_reset() in Query_cache::flush_cache().
sql/sql_cache.h:
Add declarations for new members and methods.
Make is_cacheable() a static method.
Add query_cache_init_query() function.
sql/sql_class.cc:
Use query_cache_init_query() for initialization of
NET::query_cache_query.
2006-08-22 09:47:52 +02:00
|
|
|
void query_cache_init_query(NET *net);
|
|
|
|
void query_cache_insert(NET *net, const char *packet, ulong length);
|
2003-12-01 14:19:10 +01:00
|
|
|
void query_cache_end_of_result(THD *thd);
|
2002-01-02 20:29:41 +01:00
|
|
|
void query_cache_abort(NET *net);
|
2001-12-02 13:34:01 +01:00
|
|
|
|
|
|
|
#endif
|