Commit 9f59372e authored by unknown's avatar unknown

Early check of subquery cache hit rate added to limit its performance impact in the worst case.

sql/sql_expression_cache.cc:
  Early check of subquery cache hit rate added to limit its performance impact in the worst case.
  Disabling cache moved to method.
sql/sql_expression_cache.h:
  Disabling cache moved to method.
parent 21943b80
...@@ -26,6 +26,11 @@ ...@@ -26,6 +26,11 @@
hit_rate = hit / (miss + hit); hit_rate = hit / (miss + hit);
*/ */
#define EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE 0.2 #define EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE 0.2
/**
Number of cache miss to check hit ratio (maximum cache performance
impact in the case when the cache is not applicable)
*/
#define EXPCACHE_CHECK_HIT_RATIO_AFTER 200
/* /*
Expression cache is used only for caching subqueries now, so its statistic Expression cache is used only for caching subqueries now, so its statistic
...@@ -44,6 +49,17 @@ Expression_cache_tmptable::Expression_cache_tmptable(THD *thd, ...@@ -44,6 +49,17 @@ Expression_cache_tmptable::Expression_cache_tmptable(THD *thd,
}; };
/**
Disable cache
*/
void Expression_cache_tmptable::disable_cache()
{
free_tmp_table(table_thd, cache_table);
cache_table= NULL;
}
/** /**
Field enumerator for TABLE::add_tmp_key Field enumerator for TABLE::add_tmp_key
...@@ -148,9 +164,7 @@ void Expression_cache_tmptable::init() ...@@ -148,9 +164,7 @@ void Expression_cache_tmptable::init()
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
error: error:
/* switch off cache */ disable_cache();
free_tmp_table(table_thd, cache_table);
cache_table= NULL;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -162,7 +176,7 @@ Expression_cache_tmptable::~Expression_cache_tmptable() ...@@ -162,7 +176,7 @@ Expression_cache_tmptable::~Expression_cache_tmptable()
statistic_add(subquery_cache_hit, hit, &LOCK_status); statistic_add(subquery_cache_hit, hit, &LOCK_status);
if (cache_table) if (cache_table)
free_tmp_table(table_thd, cache_table); disable_cache();
} }
...@@ -195,7 +209,15 @@ Expression_cache::result Expression_cache_tmptable::check_value(Item **value) ...@@ -195,7 +209,15 @@ Expression_cache::result Expression_cache_tmptable::check_value(Item **value)
if (res) if (res)
{ {
miss++; if (((++miss) == EXPCACHE_CHECK_HIT_RATIO_AFTER) &&
((double)hit / ((double)hit + miss)) <
EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE)
{
DBUG_PRINT("info",
("Early check: hit rate is not so good to keep the cache"));
disable_cache();
}
DBUG_RETURN(MISS); DBUG_RETURN(MISS);
} }
...@@ -249,8 +271,7 @@ my_bool Expression_cache_tmptable::put_value(Item *value) ...@@ -249,8 +271,7 @@ my_bool Expression_cache_tmptable::put_value(Item *value)
if (hit_rate < EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE) if (hit_rate < EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE)
{ {
DBUG_PRINT("info", ("hit rate is not so good to keep the cache")); DBUG_PRINT("info", ("hit rate is not so good to keep the cache"));
free_tmp_table(table_thd, cache_table); disable_cache();
cache_table= NULL;
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
} }
else if (hit_rate < EXPCACHE_MIN_HIT_RATE_FOR_DISK_TABLE) else if (hit_rate < EXPCACHE_MIN_HIT_RATE_FOR_DISK_TABLE)
...@@ -277,8 +298,7 @@ my_bool Expression_cache_tmptable::put_value(Item *value) ...@@ -277,8 +298,7 @@ my_bool Expression_cache_tmptable::put_value(Item *value)
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
err: err:
free_tmp_table(table_thd, cache_table); disable_cache();
cache_table= NULL;
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
......
...@@ -70,6 +70,7 @@ class Expression_cache_tmptable :public Expression_cache ...@@ -70,6 +70,7 @@ class Expression_cache_tmptable :public Expression_cache
void init(); void init();
private: private:
void disable_cache();
/* tmp table parameters */ /* tmp table parameters */
TMP_TABLE_PARAM cache_table_param; TMP_TABLE_PARAM cache_table_param;
......
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