From: Date: April 19 2006 12:13pm Subject: bk commit into 5.0 tree (svoj:1.2154) BUG#18160 List-Archive: http://lists.mysql.com/commits/5135 X-Bug: 18160 Message-Id: <20060419101357.57EFD1A8C@april.pils.ru> 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/19 15:13:50 svoj@april.(none) +6 -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/19 15:13:46 svoj@april.(none) +2 -3 Added size of the key to tree_delete() for accurate allocated memory counter. Note that this size is optional. If one doesn't need precise counter it is safe to pass 0 as key_size. mysql-test/t/heap_btree.test 1.15 06/04/19 15:13:46 svoj@april.(none) +10 -0 Testcase for BUG#18160. mysql-test/r/heap_btree.result 1.19 06/04/19 15:13:45 svoj@april.(none) +10 -0 Testcase for BUG#18160. myisam/myisamlog.c 1.32 06/04/19 15:13:45 svoj@april.(none) +1 -1 Added size of the key to tree_delete() for accurate allocated memory counter. include/my_tree.h 1.18 06/04/19 15:13:45 svoj@april.(none) +1 -1 Added size of the key to tree_delete() for accurate allocated memory counter. heap/hp_delete.c 1.16 06/04/19 15:13:45 svoj@april.(none) +2 -1 Added size of the key to tree_delete() 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.15/heap/hp_delete.c 2005-08-21 01:26:44 +05:00 +++ 1.16/heap/hp_delete.c 2006-04-19 15:13:45 +05:00 @@ -79,7 +79,8 @@ custom_arg.key_length= hp_rb_make_key(keyinfo, info->recbuf, record, recpos); custom_arg.search_flag= SEARCH_SAME; old_allocated= keyinfo->rb_tree.allocated; - res= tree_delete(&keyinfo->rb_tree, info->recbuf, &custom_arg); + res= tree_delete(&keyinfo->rb_tree, info->recbuf, custom_arg.key_length, + &custom_arg); info->s->index_length-= (old_allocated - keyinfo->rb_tree.allocated); return res; } --- 1.17/include/my_tree.h 2004-03-18 02:09:10 +04:00 +++ 1.18/include/my_tree.h 2006-04-19 15:13:45 +05:00 @@ -84,7 +84,7 @@ void *tree_search(TREE *tree, void *key, void *custom_arg); int tree_walk(TREE *tree,tree_walk_action action, void *argument, TREE_WALK visit); -int tree_delete(TREE *tree, void *key, void *custom_arg); +int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg); void *tree_search_key(TREE *tree, const void *key, TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos, enum ha_rkey_function flag, void *custom_arg); --- 1.31/myisam/myisamlog.c 2005-08-26 17:45:19 +05:00 +++ 1.32/myisam/myisamlog.c 2006-04-19 15:13:45 +05:00 @@ -475,7 +475,7 @@ { if (!curr_file_info->closed) files_open--; - VOID(tree_delete(&tree, (gptr) curr_file_info, tree.custom_arg)); + VOID(tree_delete(&tree, (gptr) curr_file_info, 0, tree.custom_arg)); } break; case MI_LOG_EXTRA: --- 1.28/mysys/tree.c 2005-06-24 22:34:50 +05:00 +++ 1.29/mysys/tree.c 2006-04-19 15:13:46 +05:00 @@ -271,7 +271,7 @@ return element; } -int tree_delete(TREE *tree, void *key, void *custom_arg) +int tree_delete(TREE *tree, void *key, uint key_size, void *custom_arg) { int cmp,remove_colour; TREE_ELEMENT *element,***parent, ***org_parent, *nod; @@ -326,8 +326,7 @@ rb_delete_fixup(tree,parent); 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; + tree->allocated-= sizeof(TREE_ELEMENT) + tree->size_of_element + key_size; 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-19 15:13:45 +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 +21 +UPDATE t1 SET val=1; +SELECT INDEX_LENGTH FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='t1'; +INDEX_LENGTH +21 +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-19 15:13:46 +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