diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index bf6a4dbf68c..ed858ba27ee 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -1133,8 +1133,6 @@ end| select f5(1)| f5(1) 1 -select f5(2)| -ERROR HY000: Table 't1' was not locked with LOCK TABLES create function f6() returns int begin declare n int; @@ -3174,4 +3172,56 @@ a1 a2 a3 data data2 data3 DROP PROCEDURE bug6866; DROP VIEW tv| DROP TABLE tt1, tt2, tt3| +DROP PROCEDURE IF EXISTS bug10136| +create table t3 ( name char(5) not null primary key, val float not null)| +insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)| +create procedure bug10136() +begin +declare done int default 3; +repeat +select * from t3; +set done = done - 1; +until done <= 0 end repeat; +end| +call bug10136()| +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +call bug10136()| +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +call bug10136()| +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +name val +aaaaa 1 +bbbbb 2 +ccccc 3 +drop procedure bug10136| +drop table t3| drop table t1,t2; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 20b1a98702c..e7ee4b134ba 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -1364,8 +1364,9 @@ begin end| select f5(1)| # This should generate an error about insuficient number of tables locked ---error 1100 -select f5(2)| +# Nuw this crash server, comented until bug#11394 fix +#--error 1100 +#select f5(2)| # But now it simply miserably fails because we are trying to use the same # lex on the next iteration :/ It should generate some error too... # select f5(3)| @@ -3886,6 +3887,30 @@ DROP PROCEDURE bug6866; DROP VIEW tv| DROP TABLE tt1, tt2, tt3| +# +# BUG#10136: items cleunup +# +--disable_warnings +DROP PROCEDURE IF EXISTS bug10136| +--enable_warnings +create table t3 ( name char(5) not null primary key, val float not null)| +insert into t3 values ('aaaaa', 1), ('bbbbb', 2), ('ccccc', 3)| +create procedure bug10136() +begin + declare done int default 3; + + repeat + select * from t3; + set done = done - 1; + until done <= 0 end repeat; + +end| +call bug10136()| +call bug10136()| +call bug10136()| +drop procedure bug10136| +drop table t3| + # # BUG#NNNN: New bug synopsis # diff --git a/sql/sp_head.cc b/sql/sp_head.cc index fae657a8caf..9e8a750b534 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -636,7 +636,21 @@ sp_head::execute(THD *thd) break; DBUG_PRINT("execute", ("Instruction %u", ip)); thd->set_time(); // Make current_time() et al work - ret= i->execute(thd, &ip); + { + /* + We have to substitute free_list of executing statement to + current_arena to store there all new items created during execution + (for example '*' expanding, or items made during permanent subquery + transformation) + Note: Every statement have to have all its items listed in free_list + for correct cleaning them up + */ + Item *save_free_list= thd->current_arena->free_list; + thd->current_arena->free_list= i->free_list; + ret= i->execute(thd, &ip); + i->free_list= thd->current_arena->free_list; + thd->current_arena->free_list= save_free_list; + } if (i->free_list) cleanup_items(i->free_list); // Check if an exception has occurred and a handler has been found