diff --git a/mysql-test/r/sp-big.result b/mysql-test/r/sp-big.result index 9765508859c..e12136eb36d 100644 --- a/mysql-test/r/sp-big.result +++ b/mysql-test/r/sp-big.result @@ -1,5 +1,3 @@ -drop procedure if exists test.longprocedure; -drop table if exists t1; create table t1 (a int); insert into t1 values (1),(2),(3); length @@ -60,3 +58,30 @@ f1 This is a test case for for Bug#9819 drop procedure p1; drop table t1, t2; +create table t1 ( +`id1` int unsigned not null default '0', +`id2` int unsigned not null default '0', +`link_type` int unsigned not null default '0', +`visibility` tinyint not null default '0', +`data` varchar(255) not null default '', +`time` int unsigned not null default '0', +`version` int unsigned not null default '0', +primary key (id1, link_type, visibility, id2) +) default collate=latin1_bin; +create procedure select_test() +begin +declare id1_cond int; +set id1_cond = 1; +while id1_cond <= 10000 do +select count(*) as cnt from (select id1 from t1 force index (primary) where id1 = id1_cond and link_type = 1 and visibility = 1 order by id2 desc) as t into @cnt; +set id1_cond = id1_cond + 1; +end while; +end// +insert t1 select seq, seq, 1, 1, seq, seq, seq from seq_1_to_2000; +set @before=unix_timestamp(); +call select_test(); +select unix_timestamp() - @before < 60; +unix_timestamp() - @before < 60 +1 +drop procedure select_test; +drop table t1; diff --git a/mysql-test/t/sp-big.test b/mysql-test/t/sp-big.test index 6541e546e43..4220541697e 100644 --- a/mysql-test/t/sp-big.test +++ b/mysql-test/t/sp-big.test @@ -1,11 +1,7 @@ # # Bug #11602: SP with very large body not handled well # - ---disable_warnings -drop procedure if exists test.longprocedure; -drop table if exists t1; ---enable_warnings +source include/have_sequence.inc; create table t1 (a int); insert into t1 values (1),(2),(3); @@ -85,3 +81,37 @@ select f1 from t1 limit 1; select f1 from t2 limit 1; drop procedure p1; drop table t1, t2; + +# +# Loops with many iterations +# (Item_equal must be created in the execution arena) +# +create table t1 ( + `id1` int unsigned not null default '0', + `id2` int unsigned not null default '0', + `link_type` int unsigned not null default '0', + `visibility` tinyint not null default '0', + `data` varchar(255) not null default '', + `time` int unsigned not null default '0', + `version` int unsigned not null default '0', + primary key (id1, link_type, visibility, id2) +) default collate=latin1_bin; + +delimiter //; +create procedure select_test() +begin + declare id1_cond int; + set id1_cond = 1; + while id1_cond <= 10000 do + select count(*) as cnt from (select id1 from t1 force index (primary) where id1 = id1_cond and link_type = 1 and visibility = 1 order by id2 desc) as t into @cnt; + set id1_cond = id1_cond + 1; + end while; +end// +delimiter ;// + +insert t1 select seq, seq, 1, 1, seq, seq, seq from seq_1_to_2000; +set @before=unix_timestamp(); +call select_test(); +select unix_timestamp() - @before < 60; +drop procedure select_test; +drop table t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 1781b7ccfcb..0527eef4fde 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -14677,8 +14677,6 @@ static COND* substitute_for_best_equal_field(THD *thd, JOIN_TAB *context_tab, Item_equal *item_equal; COND *org_cond= cond; // Return this in case of fatal error - Query_arena_stmt on_stmt_arena(thd); - if (cond->type() == Item::COND_ITEM) { List *cond_list= ((Item_cond*) cond)->argument_list(); @@ -15800,8 +15798,6 @@ optimize_cond(JOIN *join, COND *conds, THD *thd= join->thd; DBUG_ENTER("optimize_cond"); - Query_arena_stmt on_stmt_arena(thd); - if (!conds) { *cond_value= Item::COND_TRUE;