List:Commits« Previous MessageNext Message »
From:Sergey Vojtovich Date:April 13 2006 9:37pm
Subject:bk commit into 5.0 tree (svoj:1.2154) BUG#18160
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of svoj. When svoj does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2154 06/04/14 00:37:04 svoj@april.(none) +4 -0
  BUG#18160 - Memory-/HEAP Table endless growing indexes
  
  Updating data in HEAP table with BTREE index results in wrong index_length
  counter value, which keeps growing after each update.
  
  When inserting new record into tree counter is incremented by:
  sizeof(TREE_ELEMENT) + key_size + tree->size_of_element
  But when deleting element from tree it doesn't decrement counter by key_size:
  sizeof(TREE_ELEMENT) + tree->size_of_element
  
  This fix makes accurate allocated memory counter for tree. That is
  decrease counter by key_size when deleting tree element.

  mysys/tree.c
    1.29 06/04/14 00:36:59 svoj@april.(none) +4 -3
    Accurate allocated memory counter:
    - store size of the key in element->key_size
    - decrease tree->allocated counter by element->key_size when deleting tree
      element.

  mysql-test/t/heap_btree.test
    1.15 06/04/14 00:36:59 svoj@april.(none) +10 -0
    Testcase for BUG#18160.

  mysql-test/r/heap_btree.result
    1.19 06/04/14 00:36:59 svoj@april.(none) +10 -0
    Testcase for BUG#18160.

  include/my_tree.h
    1.18 06/04/14 00:36:59 svoj@april.(none) +2 -0
    Added size of the key to TREE_ELEMENT for accurate allocated memory counter.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	svoj
# Host:	april.(none)
# Root:	/home/svoj/devel/mysql/BUG18160/mysql-5.0

--- 1.17/include/my_tree.h	2004-03-18 02:09:10 +04:00
+++ 1.18/include/my_tree.h	2006-04-14 00:36:59 +05:00
@@ -44,11 +44,13 @@
 typedef struct st_tree_element {
   struct st_tree_element *left,*right;
   unsigned long count;
+  uint key_size;
   uchar    colour;			/* black is marked as 1 */
 } TREE_ELEMENT;
 #else
 typedef struct st_tree_element {
   struct st_tree_element *left,*right;
+  uint key_size;
   uint32 count:31,
 	 colour:1;			/* black is marked as 1 */
 } TREE_ELEMENT;

--- 1.28/mysys/tree.c	2005-06-24 22:34:50 +05:00
+++ 1.29/mysys/tree.c	2006-04-14 00:36:59 +05:00
@@ -232,7 +232,6 @@
       return tree_insert(tree, key, key_size, custom_arg);
     }
 
-    key_size+=tree->size_of_element;
     if (tree->with_delete)
       element=(TREE_ELEMENT *) my_malloc(alloc_size, MYF(MY_WME));
     else
@@ -241,6 +240,8 @@
       return(NULL);
     **parent=element;
     element->left=element->right= &tree->null_element;
+    element->key_size= key_size;
+    key_size+= tree->size_of_element;
     if (!tree->offset_to_key)
     {
       if (key_size == sizeof(void*))		 /* no length, save pointer */
@@ -324,10 +325,10 @@
   }
   if (remove_colour == BLACK)
     rb_delete_fixup(tree,parent);
+  tree->allocated-= sizeof(TREE_ELEMENT) + tree->size_of_element +
+                    element->key_size;
   if (tree->free)
     (*tree->free)(ELEMENT_KEY(tree,element), free_free, tree->custom_arg);
-  /* This doesn't include key_size, but better than nothing */
-  tree->allocated-= sizeof(TREE_ELEMENT)+tree->size_of_element;
   my_free((gptr) element,MYF(0));
   tree->elements_in_tree--;
   return 0;

--- 1.18/mysql-test/r/heap_btree.result	2005-04-12 15:04:38 +05:00
+++ 1.19/mysql-test/r/heap_btree.result	2006-04-14 00:36:59 +05:00
@@ -246,3 +246,13 @@
 SELECT * from t1;
 a
 DROP TABLE t1;
+CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
+INSERT INTO t1 VALUES(0);
+SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND
TABLE_NAME='t1';
+INDEX_LENGTH
+25
+UPDATE t1 SET val=1;
+SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND
TABLE_NAME='t1';
+INDEX_LENGTH
+25
+DROP TABLE t1;

--- 1.14/mysql-test/t/heap_btree.test	2005-07-28 18:12:34 +05:00
+++ 1.15/mysql-test/t/heap_btree.test	2006-04-14 00:36:59 +05:00
@@ -164,4 +164,14 @@
 SELECT * from t1;
 DROP TABLE t1;
 
+#
+# BUG#18160 - Memory-/HEAP Table endless growing indexes
+#
+CREATE TABLE t1(val INT, KEY USING BTREE(val)) ENGINE=memory;
+INSERT INTO t1 VALUES(0);
+SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND
TABLE_NAME='t1';
+UPDATE t1 SET val=1;
+SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND
TABLE_NAME='t1';
+DROP TABLE t1;
+
 # End of 4.1 tests
Thread
bk commit into 5.0 tree (svoj:1.2154) BUG#18160Sergey Vojtovich13 Apr