Commit b2f27a15 authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

made variable query_cache_min_res_unit from QUERY_CACHE_MIN_RESULT_DATA_SIZE (SCRUM)

parent b381cb04
...@@ -497,6 +497,65 @@ drop table t1; ...@@ -497,6 +497,65 @@ drop table t1;
show status like "Qcache_queries_in_cache"; show status like "Qcache_queries_in_cache";
Variable_name Value Variable_name Value
Qcache_queries_in_cache 0 Qcache_queries_in_cache 0
show global variables like "query_cache_min_res_unit";
Variable_name Value
query_cache_min_res_unit 4096
set GLOBAL query_cache_min_res_unit=1001;
show global variables like "query_cache_min_res_unit";
Variable_name Value
query_cache_min_res_unit 1008
create table t1 (a int not null);
insert into t1 values (1),(2),(3);
create table t2 (a int not null);
insert into t2 values (1),(2),(3);
select * from t1;
a
1
2
3
select * from t1;
a
1
2
3
select * from t2;
a
1
2
3
select * from t2;
a
1
2
3
show status like "Qcache_hits";
Variable_name Value
Qcache_hits 11
show status like "Qcache_queries_in_cache";
Variable_name Value
Qcache_queries_in_cache 2
drop table t1;
select a from t2;
a
1
2
3
select a from t2;
a
1
2
3
show status like "Qcache_hits";
Variable_name Value
Qcache_hits 12
show status like "Qcache_queries_in_cache";
Variable_name Value
Qcache_queries_in_cache 2
drop table t2;
set GLOBAL query_cache_min_res_unit=default;
show global variables like "query_cache_min_res_unit";
Variable_name Value
query_cache_min_res_unit 4096
set GLOBAL query_cache_size=1000; set GLOBAL query_cache_size=1000;
show global variables like "query_cache_size"; show global variables like "query_cache_size";
Variable_name Value Variable_name Value
......
...@@ -342,6 +342,31 @@ show status like "Qcache_queries_in_cache"; ...@@ -342,6 +342,31 @@ show status like "Qcache_queries_in_cache";
drop table t1; drop table t1;
show status like "Qcache_queries_in_cache"; show status like "Qcache_queries_in_cache";
#
# Test of min result data unit size changing
#
show global variables like "query_cache_min_res_unit";
set GLOBAL query_cache_min_res_unit=1001;
show global variables like "query_cache_min_res_unit";
create table t1 (a int not null);
insert into t1 values (1),(2),(3);
create table t2 (a int not null);
insert into t2 values (1),(2),(3);
select * from t1;
select * from t1;
select * from t2;
select * from t2;
show status like "Qcache_hits";
show status like "Qcache_queries_in_cache";
drop table t1;
select a from t2;
select a from t2;
show status like "Qcache_hits";
show status like "Qcache_queries_in_cache";
drop table t2;
set GLOBAL query_cache_min_res_unit=default;
show global variables like "query_cache_min_res_unit";
# #
# Test of query cache resizing # Test of query cache resizing
# #
......
...@@ -307,6 +307,7 @@ typedef compare_func_creator (*chooser_compare_func_creator)(bool invert); ...@@ -307,6 +307,7 @@ typedef compare_func_creator (*chooser_compare_func_creator)(bool invert);
#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)
#define query_cache_resize(A) query_cache.resize(A) #define query_cache_resize(A) query_cache.resize(A)
#define query_cache_set_min_res_unit(A) query_cache.set_min_res_unit(A)
#define query_cache_invalidate3(A, B, C) query_cache.invalidate(A, B, C) #define query_cache_invalidate3(A, B, C) query_cache.invalidate(A, B, C)
#define query_cache_invalidate1(A) query_cache.invalidate(A) #define query_cache_invalidate1(A) query_cache.invalidate(A)
#define query_cache_send_result_to_client(A, B, C) \ #define query_cache_send_result_to_client(A, B, C) \
...@@ -318,6 +319,7 @@ typedef compare_func_creator (*chooser_compare_func_creator)(bool invert); ...@@ -318,6 +319,7 @@ typedef compare_func_creator (*chooser_compare_func_creator)(bool invert);
#define query_cache_destroy() #define query_cache_destroy()
#define query_cache_result_size_limit(A) #define query_cache_result_size_limit(A)
#define query_cache_resize(A) #define query_cache_resize(A)
#define query_cache_set_min_res_unit(A)
#define query_cache_invalidate3(A, B, C) #define query_cache_invalidate3(A, B, C)
#define query_cache_invalidate1(A) #define query_cache_invalidate1(A)
#define query_cache_send_result_to_client(A, B, C) 0 #define query_cache_send_result_to_client(A, B, C) 0
...@@ -699,7 +701,8 @@ extern ulong filesort_rows, filesort_range_count, filesort_scan_count; ...@@ -699,7 +701,8 @@ extern ulong filesort_rows, filesort_range_count, filesort_scan_count;
extern ulong filesort_merge_passes; extern ulong filesort_merge_passes;
extern ulong select_range_check_count, select_range_count, select_scan_count; extern ulong select_range_check_count, select_range_count, select_scan_count;
extern ulong select_full_range_join_count,select_full_join_count; extern ulong select_full_range_join_count,select_full_join_count;
extern ulong slave_open_temp_tables, query_cache_size; extern ulong slave_open_temp_tables;
extern ulong query_cache_size, query_cache_min_res_unit;
extern ulong thd_startup_options, slow_launch_threads, slow_launch_time; extern ulong thd_startup_options, slow_launch_threads, slow_launch_time;
extern ulong server_id, concurrency; extern ulong server_id, concurrency;
extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count; extern ulong ha_read_count, ha_write_count, ha_delete_count, ha_update_count;
......
...@@ -363,7 +363,8 @@ ulong slave_net_timeout; ...@@ -363,7 +363,8 @@ ulong slave_net_timeout;
ulong thread_cache_size=0, binlog_cache_size=0, max_binlog_cache_size=0; ulong thread_cache_size=0, binlog_cache_size=0, max_binlog_cache_size=0;
ulong query_cache_size=0; ulong query_cache_size=0;
#ifdef HAVE_QUERY_CACHE #ifdef HAVE_QUERY_CACHE
ulong query_cache_limit=0; ulong query_cache_limit= 0;
ulong query_cache_min_res_unit= QUERY_CACHE_MIN_RESULT_DATA_SIZE;
Query_cache query_cache; Query_cache query_cache;
#endif #endif
arg_cmp_func Arg_comparator::comparator_matrix[4][2] = arg_cmp_func Arg_comparator::comparator_matrix[4][2] =
...@@ -2148,6 +2149,7 @@ static int init_server_components() ...@@ -2148,6 +2149,7 @@ static int init_server_components()
table_cache_init(); table_cache_init();
hostname_cache_init(); hostname_cache_init();
query_cache_result_size_limit(query_cache_limit); query_cache_result_size_limit(query_cache_limit);
query_cache_set_min_res_unit(query_cache_min_res_unit);
query_cache_resize(query_cache_size); query_cache_resize(query_cache_size);
randominit(&sql_rand,(ulong) start_time,(ulong) start_time/2); randominit(&sql_rand,(ulong) start_time,(ulong) start_time/2);
reset_floating_point_exceptions(); reset_floating_point_exceptions();
...@@ -3443,7 +3445,7 @@ enum options ...@@ -3443,7 +3445,7 @@ enum options
OPT_NET_BUFFER_LENGTH, OPT_NET_RETRY_COUNT, OPT_NET_BUFFER_LENGTH, OPT_NET_RETRY_COUNT,
OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT, OPT_NET_READ_TIMEOUT, OPT_NET_WRITE_TIMEOUT,
OPT_OPEN_FILES_LIMIT, OPT_OPEN_FILES_LIMIT,
OPT_QUERY_CACHE_LIMIT, OPT_QUERY_CACHE_SIZE, OPT_QUERY_CACHE_LIMIT, OPT_QUERY_CACHE_MIN_RES_UNIT, OPT_QUERY_CACHE_SIZE,
OPT_QUERY_CACHE_TYPE, OPT_RECORD_BUFFER, OPT_QUERY_CACHE_TYPE, OPT_RECORD_BUFFER,
OPT_RECORD_RND_BUFFER, OPT_RELAY_LOG_SPACE_LIMIT, OPT_RECORD_RND_BUFFER, OPT_RELAY_LOG_SPACE_LIMIT,
OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME, OPT_SLAVE_NET_TIMEOUT, OPT_SLAVE_COMPRESSED_PROTOCOL, OPT_SLOW_LAUNCH_TIME,
...@@ -4206,6 +4208,11 @@ struct my_option my_long_options[] = ...@@ -4206,6 +4208,11 @@ struct my_option my_long_options[] =
"Don't cache results that are bigger than this.", "Don't cache results that are bigger than this.",
(gptr*) &query_cache_limit, (gptr*) &query_cache_limit, 0, GET_ULONG, (gptr*) &query_cache_limit, (gptr*) &query_cache_limit, 0, GET_ULONG,
REQUIRED_ARG, 1024*1024L, 0, (longlong) ULONG_MAX, 0, 1, 0}, REQUIRED_ARG, 1024*1024L, 0, (longlong) ULONG_MAX, 0, 1, 0},
{"query_cache_min_res_unit", OPT_QUERY_CACHE_MIN_RES_UNIT,
"minimal size of unit in wich space for results is allocated (last unit will be trimed after writing all result data.",
(gptr*) &query_cache_min_res_unit, (gptr*) &query_cache_min_res_unit,
0, GET_ULONG, REQUIRED_ARG, QUERY_CACHE_MIN_RESULT_DATA_SIZE,
0, (longlong) ULONG_MAX, 0, 1, 0},
#endif /*HAVE_QUERY_CACHE*/ #endif /*HAVE_QUERY_CACHE*/
{"query_cache_size", OPT_QUERY_CACHE_SIZE, {"query_cache_size", OPT_QUERY_CACHE_SIZE,
"The memory allocated to store results from old queries.", "The memory allocated to store results from old queries.",
......
...@@ -85,6 +85,7 @@ static void fix_net_write_timeout(THD *thd, enum_var_type type); ...@@ -85,6 +85,7 @@ static void fix_net_write_timeout(THD *thd, enum_var_type type);
static void fix_net_retry_count(THD *thd, enum_var_type type); static void fix_net_retry_count(THD *thd, enum_var_type type);
static void fix_max_join_size(THD *thd, enum_var_type type); static void fix_max_join_size(THD *thd, enum_var_type type);
static void fix_query_cache_size(THD *thd, enum_var_type type); static void fix_query_cache_size(THD *thd, enum_var_type type);
static void fix_query_cache_min_res_unit(THD *thd, enum_var_type type);
static void fix_key_buffer_size(THD *thd, enum_var_type type); static void fix_key_buffer_size(THD *thd, enum_var_type type);
static byte *get_error_count(THD *thd); static byte *get_error_count(THD *thd);
static byte *get_warning_count(THD *thd); static byte *get_warning_count(THD *thd);
...@@ -204,6 +205,9 @@ sys_var_long_ptr sys_query_cache_size("query_cache_size", ...@@ -204,6 +205,9 @@ sys_var_long_ptr sys_query_cache_size("query_cache_size",
#ifdef HAVE_QUERY_CACHE #ifdef HAVE_QUERY_CACHE
sys_var_long_ptr sys_query_cache_limit("query_cache_limit", sys_var_long_ptr sys_query_cache_limit("query_cache_limit",
&query_cache.query_cache_limit); &query_cache.query_cache_limit);
sys_var_long_ptr sys_query_cache_min_res_unit("query_cache_min_res_unit",
&query_cache_min_res_unit,
fix_query_cache_min_res_unit);
sys_var_thd_enum sys_query_cache_type("query_cache_type", sys_var_thd_enum sys_query_cache_type("query_cache_type",
&SV::query_cache_type, &SV::query_cache_type,
&query_cache_type_typelib); &query_cache_type_typelib);
...@@ -384,6 +388,7 @@ sys_var *sys_variables[]= ...@@ -384,6 +388,7 @@ sys_var *sys_variables[]=
&sys_query_cache_size, &sys_query_cache_size,
#ifdef HAVE_QUERY_CACHE #ifdef HAVE_QUERY_CACHE
&sys_query_cache_limit, &sys_query_cache_limit,
&sys_query_cache_min_res_unit,
&sys_query_cache_type, &sys_query_cache_type,
#endif /* HAVE_QUERY_CACHE */ #endif /* HAVE_QUERY_CACHE */
&sys_quote_show_create, &sys_quote_show_create,
...@@ -546,6 +551,8 @@ struct show_var_st init_vars[]= { ...@@ -546,6 +551,8 @@ struct show_var_st init_vars[]= {
{sys_rpl_recovery_rank.name,(char*) &sys_rpl_recovery_rank, SHOW_SYS}, {sys_rpl_recovery_rank.name,(char*) &sys_rpl_recovery_rank, SHOW_SYS},
#ifdef HAVE_QUERY_CACHE #ifdef HAVE_QUERY_CACHE
{sys_query_cache_limit.name,(char*) &sys_query_cache_limit, SHOW_SYS}, {sys_query_cache_limit.name,(char*) &sys_query_cache_limit, SHOW_SYS},
{sys_query_cache_min_res_unit.name, (char*) &sys_query_cache_min_res_unit,
SHOW_SYS},
{sys_query_cache_size.name, (char*) &sys_query_cache_size, SHOW_SYS}, {sys_query_cache_size.name, (char*) &sys_query_cache_size, SHOW_SYS},
{sys_query_cache_type.name, (char*) &sys_query_cache_type, SHOW_SYS}, {sys_query_cache_type.name, (char*) &sys_query_cache_type, SHOW_SYS},
#endif /* HAVE_QUERY_CACHE */ #endif /* HAVE_QUERY_CACHE */
...@@ -696,6 +703,15 @@ static void fix_query_cache_size(THD *thd, enum_var_type type) ...@@ -696,6 +703,15 @@ static void fix_query_cache_size(THD *thd, enum_var_type type)
} }
#ifdef HAVE_QUERY_CACHE
static void fix_query_cache_min_res_unit(THD *thd, enum_var_type type)
{
query_cache_min_res_unit=
query_cache.set_min_res_unit(query_cache_min_res_unit);
}
#endif
static void fix_key_buffer_size(THD *thd, enum_var_type type) static void fix_key_buffer_size(THD *thd, enum_var_type type)
{ {
ha_resize_key_cache(); ha_resize_key_cache();
......
...@@ -743,6 +743,14 @@ ulong Query_cache::resize(ulong query_cache_size_arg) ...@@ -743,6 +743,14 @@ ulong Query_cache::resize(ulong query_cache_size_arg)
} }
ulong Query_cache::set_min_res_unit(ulong size)
{
if (size < min_allocation_unit)
size= min_allocation_unit;
return (min_result_data_size= ALIGN_SIZE(size));
}
void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used) void Query_cache::store_query(THD *thd, TABLE_LIST *tables_used)
{ {
TABLE_COUNTER_TYPE local_tables; TABLE_COUNTER_TYPE local_tables;
......
...@@ -345,7 +345,10 @@ class Query_cache ...@@ -345,7 +345,10 @@ class Query_cache
/* resize query cache (return real query size, 0 if disabled) */ /* resize query cache (return real query size, 0 if disabled) */
ulong resize(ulong query_cache_size); ulong resize(ulong query_cache_size);
/* set limit on result size */
inline void result_size_limit(ulong limit){query_cache_limit=limit;} inline void result_size_limit(ulong limit){query_cache_limit=limit;}
/* set minimal result data allocation unit size */
ulong set_min_res_unit(ulong size);
/* register query in cache */ /* register query in cache */
void store_query(THD *thd, TABLE_LIST *used_tables); void store_query(THD *thd, TABLE_LIST *used_tables);
......
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