Skip to content

Commit

Permalink
Revert "MDEV-14786 Server crashes in Item_cond::transform on 2nd exec…
Browse files Browse the repository at this point in the history
…ution of SP querying from a view [fixes tempesta-tech#436]"

This reverts commit 7069071

And add a test to show that optimization steps that
a) are repeated for every execution
b) create new items
cannot be done on the statement arena
  • Loading branch information
vuvova committed Jan 16, 2018
1 parent edb6375 commit 1ea2b29
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
29 changes: 27 additions & 2 deletions mysql-test/r/sp-big.result
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
40 changes: 35 additions & 5 deletions mysql-test/t/sp-big.test
Original file line number Diff line number Diff line change
@@ -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);
Expand Down Expand Up @@ -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;
4 changes: 0 additions & 4 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item> *cond_list= ((Item_cond*) cond)->argument_list();
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1ea2b29

Please sign in to comment.