Skip to content
Permalink
Browse files
MDEV-25766 Unused CTE lead to a crash in find_field_in_tables/find_or…
…der_in_list

Do not assume that subquery Item always present.
  • Loading branch information
sanja-byelkin committed Feb 10, 2022
1 parent ad1fb06 commit 0168d1e
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
@@ -2184,4 +2184,37 @@ select * from t1;
a
7
drop table t1,t2;
#
# MDEV-25766: Unused CTE lead to a crash in
# find_field_in_tables/find_order_in_list
#
create table t1 (f1 INTEGER);
create view v1 as
select
subq_0.c4 as c2,
subq_0.c4 as c4
from
(select
ref_0.f1 as c4
from
t1 as ref_0
where (select 1)
) as subq_0
order by c2, c4 desc;
WITH
unused_with AS (select
subq_0.c4 as c6
from
(select
11 as c4
from
v1 as ref_0
) as subq_0,
v1 as ref_2
)
select 1 ;
1
1
drop view v1;
drop table t1;
# End of 10.2 tests
@@ -1624,4 +1624,40 @@ select * from t1;

drop table t1,t2;

--echo #
--echo # MDEV-25766: Unused CTE lead to a crash in
--echo # find_field_in_tables/find_order_in_list
--echo #

create table t1 (f1 INTEGER);

create view v1 as
select
subq_0.c4 as c2,
subq_0.c4 as c4
from
(select
ref_0.f1 as c4
from
t1 as ref_0
where (select 1)
) as subq_0
order by c2, c4 desc;

WITH
unused_with AS (select
subq_0.c4 as c6
from
(select
11 as c4
from
v1 as ref_0
) as subq_0,
v1 as ref_2
)
select 1 ;

drop view v1;
drop table t1;

--echo # End of 10.2 tests
@@ -6011,9 +6011,10 @@ find_field_in_tables(THD *thd, Item_ident *item,
sl=sl->outer_select())
{
Item *subs= sl->master_unit()->item;
if (subs->type() == Item::SUBSELECT_ITEM &&
((Item_subselect*)subs)->substype() == Item_subselect::IN_SUBS &&
((Item_in_subselect*)subs)->test_strategy(SUBS_SEMI_JOIN))
if (!subs ||
(subs->type() == Item::SUBSELECT_ITEM &&
((Item_subselect*)subs)->substype() == Item_subselect::IN_SUBS &&
((Item_in_subselect*)subs)->test_strategy(SUBS_SEMI_JOIN)))
{
continue;
}

0 comments on commit 0168d1e

Please sign in to comment.