[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 09:34:55 EEST 2011


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

------------------------------------------------------------
revno: 3138
revision-id: sanja at askmonty.org-20110801063455-hach3u8hkplv868z
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 09:34:55 +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 06:34:55 +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
@@ -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;
 }
 
@@ -158,7 +172,7 @@ error:
 Expression_cache_tmptable::~Expression_cache_tmptable()
 {
   if (cache_table)
-    free_tmp_table(table_thd, cache_table);
+    disable_cache();
 }
 
 
@@ -191,7 +205,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 +267,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 +294,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 06:34:55 +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