Below is the list of changes that have just been committed into a local
5.0 repository of thek. When thek does a push these changes
will be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2008-03-10 12:07:16+01:00, thek@adventure.(none) +4 -0
Bug#30087 Set query_cache_size, if the value is too small, get a unclear warning
This bugs clarifies a warning message issued when the query cache data
size becomes smaller than the minium allowed size.
mysql-test/r/query_cache.result@stripped, 2008-03-10 12:07:14+01:00, thek@adventure.(none) +4 -4
New warning message when a too small value has been set for query cache
size.
sql/set_var.cc@stripped, 2008-03-10 12:07:14+01:00, thek@adventure.(none) +11 -2
If the query cache data size becomes smaller than the minium allocation
unit, issue a warning indicating that the size should be made bigger.
sql/sql_cache.cc@stripped, 2008-03-10 12:07:14+01:00, thek@adventure.(none) +43 -9
If the query cache data size becomes smaller than the minium allocation
unit, issue a warning indicating that the size should be made bigger.
Changed interface method Query_cache::resize to return an error code.
Added interface method Query_cache::get_query_cache_size().
Changed method Query_cache::init_cache() to return an error code.
sql/sql_cache.h@stripped, 2008-03-10 12:07:14+01:00, thek@adventure.(none) +17 -2
If the query cache data size becomes smaller than the minium allocation
unit, issue a warning indicating that the size should be made bigger.
Changed interface method Query_cache::resize to return an error code.
Added interface method Query_cache::get_query_cache_size().
Changed method Query_cache::init_cache() to return an error code.
diff -Nrup a/mysql-test/r/query_cache.result b/mysql-test/r/query_cache.result
--- a/mysql-test/r/query_cache.result 2007-08-21 17:47:03 +02:00
+++ b/mysql-test/r/query_cache.result 2008-03-10 12:07:14 +01:00
@@ -564,7 +564,7 @@ select * from t1;
a
set GLOBAL query_cache_size=1024;
Warnings:
-Warning 1282 Query cache failed to set size 1024; new query cache size is 0
+Warning 1282 Memory size 1024 is too small for cache to be efficient. New size is 0
show global variables like "query_cache_size";
Variable_name Value
query_cache_size 0
@@ -572,7 +572,7 @@ select * from t1;
a
set GLOBAL query_cache_size=10240;
Warnings:
-Warning 1282 Query cache failed to set size 10240; new query cache size is 0
+Warning 1282 Memory size 10240 is too small for cache to be efficient. New size is 0
show global variables like "query_cache_size";
Variable_name Value
query_cache_size 0
@@ -580,7 +580,7 @@ select * from t1;
a
set GLOBAL query_cache_size=20480;
Warnings:
-Warning 1282 Query cache failed to set size 20480; new query cache size is 0
+Warning 1282 Memory size 20480 is too small for cache to be efficient. New size is 0
show global variables like "query_cache_size";
Variable_name Value
query_cache_size 0
@@ -588,7 +588,7 @@ select * from t1;
a
set GLOBAL query_cache_size=40960;
Warnings:
-Warning 1282 Query cache failed to set size 40960; new query cache size is 0
+Warning 1282 Memory size 40960 is too small for cache to be efficient. New size is 0
show global variables like "query_cache_size";
Variable_name Value
query_cache_size 0
diff -Nrup a/sql/set_var.cc b/sql/set_var.cc
--- a/sql/set_var.cc 2008-01-10 12:01:24 +01:00
+++ b/sql/set_var.cc 2008-03-10 12:07:14 +01:00
@@ -1344,11 +1344,20 @@ static void fix_query_cache_size(THD *th
{
#ifdef HAVE_QUERY_CACHE
ulong requested= query_cache_size;
- query_cache.resize(query_cache_size);
- if (requested != query_cache_size)
+ int error_code= query_cache.resize(query_cache_size);
+ query_cache_size= query_cache.get_query_cache_size();
+ if (!error_code)
+ return;
+ if (error_code == 1)
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
ER_WARN_QC_RESIZE, ER(ER_WARN_QC_RESIZE),
requested, query_cache_size);
+ if (error_code == 2)
+ push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+ ER_WARN_QC_RESIZE, "Memory size %lu is too small for"
+ " cache to be efficient. New size is %lu",
+ requested,
+ query_cache_size);
#endif
}
diff -Nrup a/sql/sql_cache.cc b/sql/sql_cache.cc
--- a/sql/sql_cache.cc 2007-10-01 12:44:28 +02:00
+++ b/sql/sql_cache.cc 2008-03-10 12:07:14 +01:00
@@ -806,7 +806,16 @@ Query_cache::Query_cache(ulong query_cac
}
-ulong Query_cache::resize(ulong query_cache_size_arg)
+/**
+ Clears the cache and resizes the cache memory block.
+
+ @return Error code
+ @retval 0 Success
+ @retval 1 Not enough memory
+ @retval 2 Too small size for the cache to be efficient
+*/
+
+int Query_cache::resize(ulong query_cache_size_arg)
{
DBUG_ENTER("Query_cache::resize");
DBUG_PRINT("qcache", ("from %lu to %lu",query_cache_size,
@@ -815,9 +824,13 @@ ulong Query_cache::resize(ulong query_ca
STRUCT_LOCK(&structure_guard_mutex);
free_cache();
query_cache_size= query_cache_size_arg;
- ::query_cache_size= init_cache();
+ int error_code= init_cache();
+
+ /* Don't issue a warning if the query cache was explicitly disabled */
+ if (query_cache_size_arg == 0)
+ error_code= 0;
STRUCT_UNLOCK(&structure_guard_mutex);
- DBUG_RETURN(::query_cache_size);
+ DBUG_RETURN(error_code);
}
@@ -1614,19 +1627,33 @@ void Query_cache::init()
}
-ulong Query_cache::init_cache()
+/**
+ Initializes the query cache and allocates memory.
+
+ @returns Error code
+ @retval 0 Success
+ @retval 1 Not enough memory
+ @retval 2 Size too small to be efficient
+*/
+
+int Query_cache::init_cache()
{
uint mem_bin_count, num, step;
ulong mem_bin_size, prev_size, inc;
ulong additional_data_size, max_mem_bin_size, approx_additional_data_size;
int align;
+ int error_code= 0;
DBUG_ENTER("Query_cache::init_cache");
approx_additional_data_size = (sizeof(Query_cache) +
sizeof(gptr)*(def_query_hash_size+
def_table_hash_size));
if (query_cache_size < approx_additional_data_size)
+ {
+ /* Size too small to be efficient */
+ error_code= 2;
goto err;
+ }
query_cache_size-= approx_additional_data_size;
align= query_cache_size % ALIGN_SIZE(1);
@@ -1651,7 +1678,7 @@ ulong Query_cache::init_cache()
if (mem_bin_size <= min_allocation_unit)
{
DBUG_PRINT("qcache", ("too small query cache => query cache disabled"));
- // TODO here (and above) should be warning in 4.1
+ error_code= 2;
goto err;
}
while (mem_bin_size > min_allocation_unit)
@@ -1676,12 +1703,18 @@ ulong Query_cache::init_cache()
ALIGN_SIZE(sizeof(Query_cache_memory_bin_step))));
if (query_cache_size < additional_data_size)
+ {
+ error_code= 2;
goto err;
+ }
query_cache_size -= additional_data_size;
if (!(cache= (byte *)
my_malloc_lock(query_cache_size+additional_data_size, MYF(0))))
+ {
+ error_code= 1;
goto err;
+ }
DBUG_PRINT("qcache", ("cache length %lu, min unit %lu, %u bins",
query_cache_size, min_allocation_unit, mem_bin_num));
@@ -1777,15 +1810,15 @@ ulong Query_cache::init_cache()
queries_in_cache = 0;
queries_blocks = 0;
- DBUG_RETURN(query_cache_size +
- additional_data_size + approx_additional_data_size);
+ total_query_cache_size= query_cache_size + additional_data_size +
+ approx_additional_data_size;
+ DBUG_RETURN(total_query_cache_size);
err:
make_disabled();
- DBUG_RETURN(0);
+ DBUG_RETURN(error_code);
}
-
/* Disable the use of the query cache */
void Query_cache::make_disabled()
@@ -1800,6 +1833,7 @@ void Query_cache::make_disabled()
mem_bin_num= mem_bin_steps= 0;
queries_in_cache= 0;
first_block= 0;
+ total_query_cache_size= 0;
DBUG_VOID_RETURN;
}
diff -Nrup a/sql/sql_cache.h b/sql/sql_cache.h
--- a/sql/sql_cache.h 2007-08-17 16:55:19 +02:00
+++ b/sql/sql_cache.h 2008-03-10 12:07:14 +01:00
@@ -235,11 +235,15 @@ class Query_cache
public:
/* Info */
ulong query_cache_size, query_cache_limit;
+
/* statistics */
ulong free_memory, queries_in_cache, hits, inserts, refused,
free_memory_blocks, total_blocks, lowmem_prunes;
private:
+ /** Total amount of allocated memory by the query cache */
+ ulong total_query_cache_size;
+
pthread_cond_t COND_flush_finished;
bool flush_in_progress;
@@ -343,7 +347,7 @@ protected:
Following function control structure_guard_mutex
by themself or don't need structure_guard_mutex
*/
- ulong init_cache();
+ int init_cache();
void make_disabled();
void free_cache();
Query_cache_block *write_block_data(ulong data_len, gptr data,
@@ -387,7 +391,7 @@ protected:
/* initialize cache (mutex) */
void init();
/* resize query cache (return real query size, 0 if disabled) */
- ulong resize(ulong query_cache_size);
+ int resize(ulong query_cache_size);
/* set limit on result size */
inline void result_size_limit(ulong limit){query_cache_limit=limit;}
/* set minimal result data allocation unit size */
@@ -395,6 +399,17 @@ protected:
/* register query in cache */
void store_query(THD *thd, TABLE_LIST *used_tables);
+
+
+ /**
+ Returns the total size of the total amount of allocated memory by the
+ query cache.
+ */
+
+ inline ulong get_query_cache_size()
+ {
+ return total_query_cache_size;
+ }
/*
Check if the query is in the cache and if this is true send the