[Commits] Rev 3153: 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
Fri Aug 12 13:52:35 EEST 2011


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

------------------------------------------------------------
revno: 3153
revision-id: sanja at askmonty.org-20110812105235-ubp9rbionp1sla9y
parent: sanja at askmonty.org-20110812082350-kdhvaffgpxkq00oi
committer: sanja at askmonty.org
branch nick: work-maria-5.3-scache_impact
timestamp: Fri 2011-08-12 13:52:35 +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-08-12 08:23:50 +0000
+++ b/sql/sql_expression_cache.cc	2011-08-12 10:52:35 +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_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_ca
 
 
 /**
+  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_c
   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_cach
 
     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_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)
@@ -277,8 +298,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-12 10:52:35 +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