Bug #34842 Incorrect minimum value for query_cache_min_res_unit
Submitted: 26 Feb 2008 13:20 Modified: 20 Mar 2008 19:31
Reporter: Rizwan Maredia Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Query Cache Severity:S4 (Feature request)
Version:5.1.22, 5.1.23 OS:Windows
Assigned to: Chuck Bell CPU Architecture:Any
Tags: minimum value, query_cache_min_res_unit

[26 Feb 2008 13:20] Rizwan Maredia
Description:
Minimum value according to documentation is 0 but in fact it is 512.

How to repeat:
Following code snippet shows how to reproduce the bug (using mysql test environment).

Sample Code: 
SET @@global.query_cache_min_res_unit = 0;
SELECT @@global.query_cache_min_res_unit;
 
Output: 
SET @@global.query_cache_min_res_unit = 0;
SELECT @@global.query_cache_min_res_unit;
@@global.query_cache_min_res_unit
512

Expected Output: 
SET @@global.query_cache_min_res_unit = 0;
SELECT @@global.query_cache_min_res_unit;
@@global.query_cache_min_res_unit
0

Suggested fix:
Either 512 should be documented as a minimum value or 0 should work as minimum value.
[29 Feb 2008 9:13] Valeriy Kravchuk
Thank you for a problem report.
[3 Mar 2008 20:08] Chuck Bell
The default setting is 512. This is confirmed in the code and by observation.

This code sets the minimal value for the variable in question:

@line# 936 in sql_cache.cc
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));
}

min_allocation_unit is set to 512 in this code:

@line# 425 in sql_cache.h
  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,
	      uint def_table_hash_size = QUERY_CACHE_DEF_TABLE_HASH_SIZE);

...where QUERY_CACHE_MIN_ALLOCATION_UNIT is defined in this code:

@line#27 in sql_cache.h
#define QUERY_CACHE_MIN_ALLOCATION_UNIT		512

By way of observation, the code above generates this result:

mysql> SELECT @@global.query_cache_min_res_unit;
+-----------------------------------+
| @@global.query_cache_min_res_unit |
+-----------------------------------+
|                              4096 |
+-----------------------------------+
1 row in set (0.00 sec)

mysql> SET @@global.query_cache_min_res_unit = 0;
Query OK, 0 rows affected (11.15 sec)

mysql> SELECT @@global.query_cache_min_res_unit;
+-----------------------------------+
| @@global.query_cache_min_res_unit |
+-----------------------------------+
|                               512 |
+-----------------------------------+
1 row in set (0.00 sec)

mysql>
[4 Mar 2008 18:35] Lars Thalmann
Ok to close after documentation is updated to correct value.
[20 Mar 2008 19:31] Paul DuBois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.

Updated the minimum value from 0 to 512.

Also updated the default from 1024 (which was incorrect) to 4096.