From d29df5645bf0cdac2ff08a7da305e62edcd79604 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 25 Aug 2005 15:34:14 +0400 Subject: Fix Bug#11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO query" mysql-test/r/sp.result: update result mysql-test/t/sp.test: Add test for Bug #11333 "Stored Procedure: Memory blow up on repeated SELECT ... INTO query" sql/item.cc: we should call destructors for Items before reuse sql/item.h: Add new method and constructor for Item_string. sql/sp_head.cc: String allocation should be done on the system heap for now. --- sql/sp_head.cc | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'sql/sp_head.cc') diff --git a/sql/sp_head.cc b/sql/sp_head.cc index f119ef1ec22..0a3521e8855 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -249,10 +249,25 @@ sp_eval_func_item(THD *thd, Item **it_addr, enum enum_field_types type, DBUG_PRINT("info",("default result: %*s", s->length(), s->c_ptr_quick())); CREATE_ON_CALLERS_ARENA(it= new(reuse, &rsize) - Item_string(thd->strmake(s->ptr(), - s->length()), s->length(), - it->collation.collation), - use_callers_arena, &backup_current_arena); + Item_string(it->collation.collation), + use_callers_arena, &backup_current_arena); + /* + We have to use special constructor and allocate string + on system heap here. This is because usual Item_string + constructor would allocate memory in the callers arena. + This would lead to the memory leak in SP loops. + See Bug #11333 "Stored Procedure: Memory blow up on + repeated SELECT ... INTO query" for sample of such SP. + TODO: Usage of the system heap gives significant overhead, + however usual "reuse" mechanism does not work here, as + Item_string has no max size. That is, if we have a loop, which + has string variable with constantly increasing size, we would have + to allocate new pieces of memory again and again on each iteration. + In future we should probably reserve some area of memory for + not-very-large strings and reuse it. But for large strings + we would have to use system heap anyway. + */ + ((Item_string*) it)->set_str_with_copy(s->ptr(), s->length()); } break; } -- cgit v1.2.1