mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-22042 Server crash in Item_field::print on ANALYZE FORMAT=JSON
When processing a query with a recursive CTE a temporary table is used for each recursive reference of the CTE. As any temporary table it uses its own mem-root for table definition structures. Due to specifics of the current implementation of ANALYZE stmt command this mem-root can be freed only at the very of query processing. Such deallocation of mem-root memory happens in close_thread_tables(). The function looks through the list of the tmp tables rec_tables attached to the THD of the query and frees corresponding mem-roots. If the query uses a stored function then such list is created for each query of the function. When a new rec_list has to be created the old one has to be saved and then restored at the proper moment. The bug occurred because only one rec_list for the query containing CTE was created. As a result close_thread_tables() freed tmp mem-roots used for rec_tables prematurely destroying some data needed for the output produced by the ANALYZE command.
This commit is contained in:
@ -2536,3 +2536,42 @@ with recursive cte as
|
||||
select * from t1 as t;
|
||||
|
||||
drop table t1,t2;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-22042: ANALYZE of query using stored function and recursive CTE
|
||||
--echo #
|
||||
|
||||
create table t1 (a1 varchar(20),a2 varchar(20)) engine=myisam;
|
||||
insert into t1 values (1,1),(2,2),(3,3);
|
||||
|
||||
create table t2 (
|
||||
a2 varchar(20) primary key, b1 varchar(20), key (b1)
|
||||
) engine=myisam;
|
||||
insert into t2 values (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7);
|
||||
insert into t2 values (11,11),(12,12),(13,13),(14,14),(15,15),(16,16),(17,17);
|
||||
|
||||
delimiter $$;
|
||||
create function f1(id varchar(20)) returns varchar(50)
|
||||
begin
|
||||
declare res varchar (50);
|
||||
select a2 into res from t2 where a2=id and b1=1 limit 1;
|
||||
return res;
|
||||
end$$
|
||||
delimiter ;$$
|
||||
|
||||
let q=
|
||||
select fv
|
||||
from (select t1.a1, f1(t1.a2) fv from t1) dt
|
||||
where (dt.a1) in (with recursive cte as (select a2 from t2 where a2='2'
|
||||
union select tt2.a2 from t2 tt2 join cte on tt2.b1=cte.a2)
|
||||
select a2 from cte);
|
||||
|
||||
eval $q;
|
||||
eval explain $q;
|
||||
--source include/analyze-format.inc
|
||||
eval analyze format=json $q;
|
||||
|
||||
drop function f1;
|
||||
drop table t1,t2;
|
||||
|
||||
--echo End of 10.2 tests
|
||||
|
Reference in New Issue
Block a user