28 typedef ulonglong sql_mode_t;
38 #define QUERY_CACHE_MIN_ALLOCATION_UNIT 512
41 #define QUERY_CACHE_DEF_QUERY_HASH_SIZE 1024
42 #define QUERY_CACHE_DEF_TABLE_HASH_SIZE 1024
45 #define QUERY_CACHE_MIN_RESULT_DATA_SIZE 1024*4
51 #define QUERY_CACHE_MIN_ESTIMATED_QUERIES_NUMBER 3
56 #define QUERY_CACHE_MEM_BIN_FIRST_STEP_PWR2 4
57 #define QUERY_CACHE_MEM_BIN_STEP_PWR2 2
58 #define QUERY_CACHE_MEM_BIN_PARTS_INC 1
59 #define QUERY_CACHE_MEM_BIN_PARTS_MUL 1.2
60 #define QUERY_CACHE_MEM_BIN_SPC_LIM_PWR2 3
64 #define QUERY_CACHE_MEM_BIN_TRY 5
67 #define QUERY_CACHE_PACK_ITERATION 2
68 #define QUERY_CACHE_PACK_LIMIT (512*1024L)
70 #define TABLE_COUNTER_TYPE uint
82 typedef my_bool (*qc_engine_callback)(THD *thd,
char *table_key,
84 ulonglong *engine_data);
101 TABLE_COUNTER_TYPE
n;
127 enum block_type {FREE, QUERY, RESULT, RES_CONT, RES_BEG,
128 RES_INCOMPLETE,
TABLE, INCOMPLETE};
140 TABLE_COUNTER_TYPE n_tables;
142 inline my_bool is_free(
void) {
return type == FREE; }
143 void init(ulong length);
145 inline uint headers_len();
146 inline uchar* data(
void);
155 ulonglong limit_found_rows;
161 unsigned int last_pkt_nr;
164 inline void init_n_lock();
165 void unlock_n_destroy();
166 inline ulonglong found_rows() {
return limit_found_rows; }
167 inline void found_rows(ulonglong rows) { limit_found_rows= rows; }
172 inline uint8 tables_type() {
return tbls_type; }
173 inline void tables_type(uint8
type) { tbls_type=
type; }
174 inline ulong length() {
return len; }
175 inline ulong add(ulong packet_len) {
return(len+= packet_len); }
176 inline void length(ulong length_arg) { len= length_arg; }
177 inline uchar*
query()
183 my_bool try_lock_writing();
184 void unlock_writing();
185 void unlock_reading();
196 qc_engine_callback callback_func;
198 ulonglong engine_data_buff;
205 inline char *db() {
return (
char *) data(); }
206 inline char *table() {
return tbl; }
207 inline void table(
char *table_arg) { tbl= table_arg; }
208 inline uint32 key_length() {
return key_len; }
209 inline void key_length(uint32 len) { key_len= len; }
210 inline uint8 type() {
return table_type; }
211 inline void type(uint8 t) { table_type= t; }
212 inline qc_engine_callback callback() {
return callback_func; }
213 inline void callback(qc_engine_callback fn){ callback_func= fn; }
214 inline ulonglong engine_data() {
return engine_data_buff; }
215 inline void engine_data(ulonglong data_arg){ engine_data_buff= data_arg; }
218 return (uchar*)(((uchar*)
this)+
230 return (uchar*)(((uchar*)
this)+
241 uchar *query_cache_query_get_key(
const uchar *
record,
size_t *length,
243 uchar *query_cache_table_get_key(
const uchar *
record,
size_t *length,
246 extern "C" void query_cache_invalidate_by_MyISAM_filename(
const char* filename);
258 inline void init(ulong size_arg)
274 inline void init(ulong size_arg, uint idx_arg, ulong increment_arg)
278 increment = increment_arg;
286 ulong query_cache_size, query_cache_limit;
288 ulong free_memory, queries_in_cache, hits, inserts, refused,
289 free_memory_blocks, total_blocks, lowmem_prunes;
294 my_thread_id m_cache_lock_thread_id;
297 enum Cache_lock_status { UNLOCKED, LOCKED_NO_WAIT, LOCKED };
298 Cache_lock_status m_cache_lock_status;
300 bool m_query_cache_is_disabled;
303 void invalidate_table_internal(THD *thd, uchar *key, uint32 key_length);
304 void disable_query_cache(
void) { m_query_cache_is_disabled= TRUE; }
329 HASH queries, tables;
331 ulong min_allocation_unit, min_result_data_size;
332 uint def_query_hash_size, def_table_hash_size;
334 uint mem_bin_num, mem_bin_steps;
348 static uint filename_2_table_key (
char *key,
const char *filename,
353 my_bool free_old_query();
358 my_bool first_block);
360 void invalidate_table(THD *thd,
TABLE *table);
361 void invalidate_table(THD *thd, uchar *key, uint32 key_length);
363 void invalidate_query_block_list(THD *thd,
367 register_tables_from_list(
TABLE_LIST *tables_used,
368 TABLE_COUNTER_TYPE counter,
372 TABLE_COUNTER_TYPE tables);
373 my_bool insert_table(uint key_len,
const char *key,
375 uint32 db_length, uint8 cache_type,
376 qc_engine_callback callback,
377 ulonglong engine_data);
391 uint find_bin(ulong
size);
402 my_bool join_results(ulong join_limit);
409 void make_disabled();
413 Query_cache_block::block_type
type,
414 TABLE_COUNTER_TYPE ntab = 0);
416 ulong data_len, uchar* data,
419 ulong data_len, uchar* data,
421 Query_cache_block::block_type
422 type=Query_cache_block::RESULT);
423 inline ulong get_min_first_result_data_size();
424 inline ulong get_min_append_result_data_size();
431 TABLE_COUNTER_TYPE is_cacheable(THD *thd,
size_t query_len,
435 TABLE_COUNTER_TYPE process_and_count_tables(THD *thd,
439 static my_bool ask_handler_allowance(THD *thd,
TABLE_LIST *tables_used);
443 ulong min_allocation_unit = QUERY_CACHE_MIN_ALLOCATION_UNIT,
444 ulong min_result_data_size = QUERY_CACHE_MIN_RESULT_DATA_SIZE,
445 uint def_query_hash_size = QUERY_CACHE_DEF_QUERY_HASH_SIZE,
446 uint def_table_hash_size = QUERY_CACHE_DEF_TABLE_HASH_SIZE);
448 bool is_disabled(
void) {
return m_query_cache_is_disabled; }
453 ulong resize(ulong query_cache_size);
455 inline void result_size_limit(ulong
limit){query_cache_limit=
limit;}
457 ulong set_min_res_unit(ulong size);
460 void store_query(THD *thd,
TABLE_LIST *used_tables);
466 int send_result_to_client(THD *thd,
char *query, uint query_length);
469 void invalidate(THD* thd,
TABLE_LIST *tables_used,
470 my_bool using_transactions);
472 void invalidate_locked_for_write(
TABLE_LIST *tables_used);
473 void invalidate(THD* thd,
TABLE *table, my_bool using_transactions);
474 void invalidate(THD *thd,
const char *key, uint32 key_length,
475 my_bool using_transactions);
478 void invalidate(
char *db);
481 void invalidate_by_MyISAM_filename(
const char *filename);
484 void pack(ulong join_limit = QUERY_CACHE_PACK_LIMIT,
485 uint iteration_limit = QUERY_CACHE_PACK_ITERATION);
494 void end_of_result(THD *thd);
502 void wreck(uint line,
const char *
message);
507 my_bool check_integrity(
bool not_locked);
515 bool try_lock(
bool use_timeout= FALSE);
517 void lock_and_suspend(
void);
521 #ifdef HAVE_QUERY_CACHE
522 struct Query_cache_query_flags
524 unsigned int client_long_flag:1;
525 unsigned int client_protocol_41:1;
526 unsigned int protocol_type:2;
527 unsigned int more_results_exists:1;
528 unsigned int in_trans:1;
529 unsigned int autocommit:1;
531 uint character_set_client_num;
532 uint character_set_results_num;
533 uint collation_connection_num;
537 ulong max_sort_length;
538 ulong group_concat_max_len;
539 ulong default_week_format;
540 ulong div_precision_increment;
543 #define QUERY_CACHE_FLAGS_SIZE sizeof(Query_cache_query_flags)
544 #include "sql_cache.h"
545 #define query_cache_abort(A) query_cache.abort(A)
546 #define query_cache_end_of_result(A) query_cache.end_of_result(A)
547 #define query_cache_store_query(A, B) query_cache.store_query(A, B)
548 #define query_cache_destroy() query_cache.destroy()
549 #define query_cache_result_size_limit(A) query_cache.result_size_limit(A)
550 #define query_cache_init() query_cache.init()
551 #define query_cache_resize(A) query_cache.resize(A)
552 #define query_cache_set_min_res_unit(A) query_cache.set_min_res_unit(A)
553 #define query_cache_invalidate3(A, B, C) query_cache.invalidate(A, B, C)
554 #define query_cache_invalidate1(A) query_cache.invalidate(A)
555 #define query_cache_send_result_to_client(A, B, C) \
556 query_cache.send_result_to_client(A, B, C)
557 #define query_cache_invalidate_by_MyISAM_filename_ref \
558 &query_cache_invalidate_by_MyISAM_filename
560 #define query_cache_maybe_disabled(T) \
561 (T->variables.query_cache_type == 0 || query_cache.query_cache_size == 0)
562 #define query_cache_is_cacheable_query(L) \
563 (((L)->sql_command == SQLCOM_SELECT) && (L)->safe_to_cache_query && \
566 #define QUERY_CACHE_FLAGS_SIZE 0
567 #define query_cache_store_query(A, B)
568 #define query_cache_destroy()
569 #define query_cache_result_size_limit(A)
570 #define query_cache_init()
571 #define query_cache_resize(A)
572 #define query_cache_set_min_res_unit(A)
573 #define query_cache_invalidate3(A, B, C)
574 #define query_cache_invalidate1(A)
575 #define query_cache_send_result_to_client(A, B, C) 0
576 #define query_cache_invalidate_by_MyISAM_filename_ref NULL
578 #define query_cache_abort(A)
579 #define query_cache_end_of_result(A)
580 #define query_cache_invalidate_by_MyISAM_filename_ref NULL
581 #define query_cache_maybe_disabled(T) 1
582 #define query_cache_is_cacheable_query(L) 0