[Commits] Rev 2875: Fix problem of making on-disk cache table. in file:///home/bell/maria/bzr/work-maria-5.3-subquerycache/

sanja at askmonty.org sanja at askmonty.org
Wed Jan 5 21:37:57 EET 2011


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

------------------------------------------------------------
revno: 2875
revision-id: sanja at askmonty.org-20110105193756-aopzwmmobhb14ouy
parent: igor at askmonty.org-20101230021403-ly4ku1yq675l5d6b
committer: sanja at askmonty.org
branch nick: work-maria-5.3-subquerycache
timestamp: Wed 2011-01-05 21:37:56 +0200
message:
  Fix problem of making on-disk cache table.
  Removed 'uniques=1' which lead to creating unneeded unique index creation.
-------------- next part --------------
=== modified file 'sql/sql_expression_cache.cc'
--- a/sql/sql_expression_cache.cc	2010-11-02 09:47:36 +0000
+++ b/sql/sql_expression_cache.cc	2011-01-05 19:37:56 +0000
@@ -2,6 +2,9 @@
 #include "mysql_priv.h"
 #include "sql_select.h"
 
+/* hitrate over 50% is OK to leave built in-memory temporary table */
+#define EXPRASSION_TMPTABLE_ALLOWED_HITRATE 50
+
 /*
   Expression cache is used only for caching subqueries now, so its statistic
   variables we call subquery_cache*.
@@ -11,8 +14,8 @@ ulong subquery_cache_miss, subquery_cach
 Expression_cache_tmptable::Expression_cache_tmptable(THD *thd,
                                                  List<Item*> &dependants,
                                                  Item *value)
-  :cache_table(NULL), table_thd(thd), list(&dependants), val(value),
-   inited (0)
+  :hit(0), miss(0), frozen(0), cache_table(NULL), table_thd(thd),
+   list(&dependants), val(value), inited(0)
 {
   DBUG_ENTER("Expression_cache_tmptable::Expression_cache_tmptable");
   DBUG_VOID_RETURN;
@@ -123,7 +126,6 @@ void Expression_cache_tmptable::init()
     goto error;
   }
   cache_table->s->keys= 1;
-  cache_table->s->uniques= 1;
   ref.null_rejecting= 1;
   ref.disable_cache= FALSE;
   ref.has_record= 0;
@@ -195,10 +197,12 @@ Expression_cache::result Expression_cach
     if (res)
     {
       subquery_cache_miss++;
+      miss++;
       DBUG_RETURN(MISS);
     }
 
     subquery_cache_hit++;
+    hit++;
     *value= cached_result;
     DBUG_RETURN(Expression_cache::HIT);
   }
@@ -225,7 +229,7 @@ my_bool Expression_cache_tmptable::put_v
   DBUG_ENTER("Expression_cache_tmptable::put_value");
   DBUG_ASSERT(inited);
 
-  if (!cache_table)
+  if (!cache_table || frozen)
   {
     DBUG_PRINT("info", ("No table so behave as we successfully put value"));
     DBUG_RETURN(FALSE);
@@ -239,12 +243,22 @@ my_bool Expression_cache_tmptable::put_v
   if ((error= cache_table->file->ha_write_row(cache_table->record[0])))
   {
     /* create_myisam_from_heap will generate error if needed */
+    /*
+      TODO: add estimation if ondisk table is efficient
     if (cache_table->file->is_fatal_error(error, HA_CHECK_DUP) &&
         create_internal_tmp_table_from_heap(table_thd, cache_table,
                                             cache_table_param.start_recinfo,
                                             &cache_table_param.recinfo,
                                             error, 1))
       goto err;
+    */
+    if (cache_table->file->is_fatal_error(error, HA_CHECK_DUP))
+      goto err;
+    /* should we leave the table */
+    if ((((ulonglong)hit) * 100) / miss < EXPRASSION_TMPTABLE_ALLOWED_HITRATE)
+      goto err;                              // remove the temporary table
+    else
+      frozen= TRUE;                          // leave the temporary table
   }
   cache_table->status= 0; /* cache_table->record contains an existed record */
   ref.has_record= TRUE; /* the same as above */

=== modified file 'sql/sql_expression_cache.h'
--- a/sql/sql_expression_cache.h	2010-10-27 03:03:59 +0000
+++ b/sql/sql_expression_cache.h	2011-01-05 19:37:56 +0000
@@ -19,7 +19,7 @@ class Expression_cache :public Sql_alloc
 public:
   enum result {ERROR, HIT, MISS};
 
-  Expression_cache(){};
+  Expression_cache() {};
   virtual ~Expression_cache() {};
   /**
     Shall check the presence of expression value in the cache for a given
@@ -50,6 +50,8 @@ class Item_field;
 
 class Expression_cache_tmptable :public Expression_cache
 {
+  ulong hit, miss;
+  bool frozen;
 public:
   Expression_cache_tmptable(THD *thd, List<Item*> &dependants, Item *value);
   virtual ~Expression_cache_tmptable();



More information about the commits mailing list