diff options
author | unknown <sanja@askmonty.org> | 2011-08-12 13:54:41 +0300 |
---|---|---|
committer | unknown <sanja@askmonty.org> | 2011-08-12 13:54:41 +0300 |
commit | 52e70226bccc005b88eca482bccdd91e63ed222b (patch) | |
tree | deab65fd07a3b39cd8cabe66a2d58771e860868c /sql/sql_expression_cache.cc | |
parent | fede2ee7f154c44a6b3e4d97db8f81c9d8a66e57 (diff) | |
download | mariadb-git-52e70226bccc005b88eca482bccdd91e63ed222b.tar.gz |
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.
Diffstat (limited to 'sql/sql_expression_cache.cc')
-rw-r--r-- | sql/sql_expression_cache.cc | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/sql/sql_expression_cache.cc b/sql/sql_expression_cache.cc index e88b136a684..4174f72f080 100644 --- a/sql/sql_expression_cache.cc +++ b/sql/sql_expression_cache.cc @@ -26,6 +26,11 @@ hit_rate = hit / (miss + hit); */ #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 @@ -45,6 +50,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 @param arg reference variable with current field number @@ -148,9 +164,7 @@ void Expression_cache_tmptable::init() DBUG_VOID_RETURN; error: - /* switch off cache */ - free_tmp_table(table_thd, cache_table); - cache_table= NULL; + disable_cache(); DBUG_VOID_RETURN; } @@ -162,7 +176,7 @@ Expression_cache_tmptable::~Expression_cache_tmptable() statistic_add(subquery_cache_hit, hit, &LOCK_status); 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) 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); } @@ -249,8 +271,7 @@ my_bool Expression_cache_tmptable::put_value(Item *value) if (hit_rate < EXPCACHE_MIN_HIT_RATE_FOR_MEM_TABLE) { DBUG_PRINT("info", ("hit rate is not so good to keep the cache")); - free_tmp_table(table_thd, cache_table); - cache_table= NULL; + disable_cache(); DBUG_RETURN(FALSE); } else if (hit_rate < EXPCACHE_MIN_HIT_RATE_FOR_DISK_TABLE) @@ -277,8 +298,7 @@ my_bool Expression_cache_tmptable::put_value(Item *value) DBUG_RETURN(FALSE); err: - free_tmp_table(table_thd, cache_table); - cache_table= NULL; + disable_cache(); DBUG_RETURN(TRUE); } |