From: Date: March 29 2006 1:51pm Subject: bk commit into 5.0 tree (pem:1.2103) BUG#17260 List-Archive: http://lists.mysql.com/commits/4270 X-Bug: 17260 Message-Id: <200603291151.k2TBpb3H018825@mail.mysql.com> Below is the list of changes that have just been committed into a local 5.0 repository of pem. When pem 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.2103 06/03/29 13:51:23 pem@stripped +2 -0 Fixed BUG#17260: Triggers: crash while updating million-row table We must set a mem_root/arena for the function each time the trigger is fired, and free it afterwards, otherwise the allocated memory accumulates in the calling statement's mem_root. To test this, we must attempt to make the machine run out of memory (with a trigger on a miljon row table for instance) which is not practical to have in the test suite, so a test case is not included in the patch. (Also fixed minor memory hogging in st_lex:st_lex()). sql/sql_trigger.cc 1.50 06/03/29 13:51:19 pem@stripped +14 -0 Set a temporary arena and mem_root for the function call in a trigger, and free it after each call; otherwise memory accumulates in the calling statement's mem_root. sql/sql_lex.cc 1.181 06/03/29 13:51:19 pem@stripped +1 -1 Fixed memory hogging in st_lex::st_lex(): Allocate a smaller hash table than the default. # 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: pem # Host: pem.mysql.com # Root: /extern/mysql/5.0/bug17260/mysql-5.0-runtime --- 1.180/sql/sql_lex.cc 2006-03-10 01:44:01 +01:00 +++ 1.181/sql/sql_lex.cc 2006-03-29 13:51:19 +02:00 @@ -1628,7 +1628,7 @@ st_lex::st_lex() :result(0), sql_command(SQLCOM_END), query_tables_own_last(0) { - hash_init(&sroutines, system_charset_info, 0, 0, 0, sp_sroutine_key, 0, 0); + hash_init(&sroutines, system_charset_info, 16, 0, 0, sp_sroutine_key, 0, 0); sroutines_list.empty(); sroutines_list_own_last= sroutines_list.next; sroutines_list_own_elements= 0; --- 1.49/sql/sql_trigger.cc 2006-03-27 23:01:48 +02:00 +++ 1.50/sql/sql_trigger.cc 2006-03-29 13:51:19 +02:00 @@ -1471,6 +1471,10 @@ { bool err_status= FALSE; sp_head *sp_trigger= bodies[event][time_type]; + /* Memory root/arena for the function call. */ + MEM_ROOT execute_mem_root; + Query_arena execute_arena(&execute_mem_root, Query_arena::INITIALIZED_FOR_SP), + backup_arena; if (sp_trigger) { @@ -1515,7 +1519,17 @@ #endif // NO_EMBEDDED_ACCESS_CHECKS thd->reset_sub_statement_state(&statement_state, SUB_STMT_TRIGGER); + + /* Set execute arena for the function call. */ + init_alloc_root(&execute_mem_root, MEM_ROOT_BLOCK_SIZE, 0); + thd->set_n_backup_active_arena(&execute_arena, &backup_arena); + err_status= sp_trigger->execute_function(thd, 0, 0, 0); + + /* Free the memory used by the function. */ + free_root(&execute_mem_root, MYF(0)); + thd->restore_active_arena(&execute_arena, &backup_arena); + thd->restore_sub_statement_state(&statement_state); #ifndef NO_EMBEDDED_ACCESS_CHECKS