From: Date: December 1 2006 2:00pm Subject: bk commit into 4.1 tree (kroki:1.2551) BUG#23443 List-Archive: http://lists.mysql.com/commits/16303 X-Bug: 23443 Message-Id: <200612011300.kB1D08st017623@moonlight.intranet> Below is the list of changes that have just been committed into a local 4.1 repository of tomash. When tomash 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@stripped, 2006-12-01 16:00:05+03:00, kroki@stripped +3 -0 BUG#23443: user-defined variables can consume too much memory in the server The problem was that when memory was exhausted HEAP engine could crash (SQL user variables are stored in it). Alternatively, if SET was used, it could report an error "You may only use constant expressions with SET" instead of "Out of memory (Needed NNNNNN bytes)". The solution is: - pass MY_WME to (some) calls to my_malloc() to get correct message. - fix heap_write() so that the first key is skipped during cleanup on ENOMEM because it wasn't inserted and doesn't have to be deleted. No test case is provided because we can't test out-of-memory behaviour in our current test framework. heap/hp_block.c@stripped, 2006-12-01 16:00:02+03:00, kroki@stripped +1 -1 If allocation fails, write an error message. heap/hp_write.c@stripped, 2006-12-01 16:00:02+03:00, kroki@stripped +9 -3 On ENOMEM, skip the first key in cleanup, as it wasn't inserted yet. sql/item_func.cc@stripped, 2006-12-01 16:00:02+03:00, kroki@stripped +3 -2 Add MY_WME so that OOM error will be reported. # 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: kroki # Host: moonlight.intranet # Root: /home/tomash/src/mysql_ab/mysql-4.1-bug23443 --- 1.6/heap/hp_block.c 2006-12-01 16:00:10 +03:00 +++ 1.7/heap/hp_block.c 2006-12-01 16:00:10 +03:00 @@ -76,7 +76,7 @@ int hp_get_new_block(HP_BLOCK *block, ul and my_default_record_cache_size we get about 1/128 unused memory. */ *alloc_length=sizeof(HP_PTRS)*i+block->records_in_block* block->recbuffer; - if (!(root=(HP_PTRS*) my_malloc(*alloc_length,MYF(0)))) + if (!(root=(HP_PTRS*) my_malloc(*alloc_length,MYF(MY_WME)))) return 1; if (i == 0) --- 1.20/heap/hp_write.c 2006-12-01 16:00:10 +03:00 +++ 1.21/heap/hp_write.c 2006-12-01 16:00:10 +03:00 @@ -68,11 +68,17 @@ int heap_write(HP_INFO *info, const byte DBUG_RETURN(0); err: - DBUG_PRINT("info",("Duplicate key: %d", keydef - share->keydef)); + if (my_errno == HA_ERR_FOUND_DUPP_KEY) + DBUG_PRINT("info",("Duplicate key: %d", keydef - share->keydef)); info->errkey= keydef - share->keydef; - if (keydef->algorithm == HA_KEY_ALG_BTREE) + /* + We don't need to delete non-inserted key from rb-tree. Also, if + we got ENOMEM, the key wasn't inserted, so don't try to delete it + either. Otherwise for HASH index on HA_ERR_FOUND_DUPP_KEY the key + was inserted and we have to delete it. + */ + if (keydef->algorithm == HA_KEY_ALG_BTREE || my_errno == ENOMEM) { - /* we don't need to delete non-inserted key from rb-tree */ keydef--; } while (keydef >= share->keydef) --- 1.267/sql/item_func.cc 2006-12-01 16:00:10 +03:00 +++ 1.268/sql/item_func.cc 2006-12-01 16:00:10 +03:00 @@ -2468,8 +2468,9 @@ bool Item_func_set_user_var::update_hash char *pos= (char*) entry+ ALIGN_SIZE(sizeof(user_var_entry)); if (entry->value == pos) entry->value=0; - if (!(entry->value=(char*) my_realloc(entry->value, length, - MYF(MY_ALLOW_ZERO_PTR)))) + entry->value= (char*) my_realloc(entry->value, length, + MYF(MY_ALLOW_ZERO_PTR | MY_WME)); + if (!entry->value) goto err; } }