[Commits] Rev 3138: Early check of subquery cache hit rate added to limit its performance impact in the worst case. in file:///home/bell/maria/bzr/work-maria-5.3-scache_impact/

sanja at askmonty.org sanja at askmonty.org
Mon Aug 1 08:17:31 EEST 2011


At file:///home/bell/maria/bzr/work-maria-5.3-scache_impact/

------------------------------------------------------------
revno: 3138
revision-id: sanja at askmonty.org-20110801051730-dvwdchx65w40kq9n
parent: knielsen at knielsen-hq.org-20110731205955-1c1um372lotakwfy
committer: sanja at askmonty.org
branch nick: work-maria-5.3-scache_impact
timestamp: Mon 2011-08-01 08:17:30 +0300
message:
  Early check of subquery cache hit rate added to limit its performance impact in the worst case.
-------------- next part --------------
=== modified file 'sql/sql_expression_cache.cc'
--- a/sql/sql_expression_cache.cc	2011-07-28 14:10:29 +0000
+++ b/sql/sql_expression_cache.cc	2011-08-01 05:17:30 +0000
@@ -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_EARLY_CHECK 200
 
 /*
   Expression cache is used only for caching subqueries now, so its statistic
@@ -162,6 +167,13 @@ Expression_cache_tmptable::~Expression_c
 }
 
 
+void Expression_cache_tmptable::disable_cache()
+{
+  free_tmp_table(table_thd, cache_table);
+  cache_table= NULL;
+}
+
+
 /**
   Check if a given set of parameters of the expression is in the cache
 
@@ -191,7 +203,14 @@ Expression_cache::result Expression_cach
     if (res)
     {
       subquery_cache_miss++;
-      miss++;
+      if (((++miss) == EXPCACHE_EARLY_CHECK) &&
+          ((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);
     }
 
@@ -246,8 +265,7 @@ my_bool Expression_cache_tmptable::put_v
       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)
@@ -274,8 +292,7 @@ my_bool Expression_cache_tmptable::put_v
   DBUG_RETURN(FALSE);
 
 err:
-  free_tmp_table(table_thd, cache_table);
-  cache_table= NULL;
+  disable_cache();
   DBUG_RETURN(TRUE);
 }
 

=== modified file 'sql/sql_expression_cache.h'
--- a/sql/sql_expression_cache.h	2011-07-28 14:10:29 +0000
+++ b/sql/sql_expression_cache.h	2011-08-01 05:17:30 +0000
@@ -70,6 +70,7 @@ public:
   void init();
 
 private:
+  void disable_cache();
 
   /* tmp table parameters */
   TMP_TABLE_PARAM cache_table_param;



More information about the commits mailing list