mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 10:14:19 +01:00
MDEV-14629: failing assertion when a user-defined variable is defined by the recursive CTE
During the user-defined variable defined by the recursive CTE handling procedure check_dependencies_in_with_clauses that checks dependencies between the tables that are defined in the CTE and find recursive definitions wasn't called.
This commit is contained in:
parent
06f0b23a78
commit
079c359971
3 changed files with 101 additions and 0 deletions
|
@ -2897,3 +2897,50 @@ n
|
|||
1
|
||||
2
|
||||
3
|
||||
#
|
||||
# mdev-14629: a user-defined variable is defined by the recursive CTE
|
||||
#
|
||||
set @var=
|
||||
(
|
||||
with recursive cte_tab(a) as (
|
||||
select 1
|
||||
union
|
||||
select a+1 from cte_tab
|
||||
where a<3)
|
||||
select count(*) from cte_tab
|
||||
);
|
||||
select @var;
|
||||
@var
|
||||
3
|
||||
create table t1(a int, b int);
|
||||
insert into t1 values (3,8),(1,5),(5,7),(7,4),(4,3);
|
||||
set @var=
|
||||
(
|
||||
with recursive summ(a,s) as (
|
||||
select 1, 0 union
|
||||
select t1.b, t1.b+summ.s from summ, t1
|
||||
where summ.a=t1.a)
|
||||
select s from summ
|
||||
order by a desc
|
||||
limit 1
|
||||
);
|
||||
select @var;
|
||||
@var
|
||||
27
|
||||
set @var=
|
||||
(
|
||||
with recursive
|
||||
cte_1 as (
|
||||
select 1
|
||||
union
|
||||
select * from cte_2),
|
||||
cte_2 as (
|
||||
select * from cte_1
|
||||
union
|
||||
select a from t1, cte_2
|
||||
where t1.a=cte_2.a)
|
||||
select * from cte_2
|
||||
limit 1
|
||||
);
|
||||
ERROR HY000: Unacceptable mutual recursion with anchored table 'cte_1'
|
||||
drop table t1;
|
||||
|
|
|
@ -1947,3 +1947,54 @@ cte2 as (
|
|||
)
|
||||
SELECT *
|
||||
FROM cte1;
|
||||
|
||||
--echo #
|
||||
--echo # mdev-14629: a user-defined variable is defined by the recursive CTE
|
||||
--echo #
|
||||
|
||||
set @var=
|
||||
(
|
||||
with recursive cte_tab(a) as (
|
||||
select 1
|
||||
union
|
||||
select a+1 from cte_tab
|
||||
where a<3)
|
||||
select count(*) from cte_tab
|
||||
);
|
||||
|
||||
select @var;
|
||||
|
||||
create table t1(a int, b int);
|
||||
insert into t1 values (3,8),(1,5),(5,7),(7,4),(4,3);
|
||||
|
||||
set @var=
|
||||
(
|
||||
with recursive summ(a,s) as (
|
||||
select 1, 0 union
|
||||
select t1.b, t1.b+summ.s from summ, t1
|
||||
where summ.a=t1.a)
|
||||
select s from summ
|
||||
order by a desc
|
||||
limit 1
|
||||
);
|
||||
|
||||
select @var;
|
||||
|
||||
--ERROR ER_UNACCEPTABLE_MUTUAL_RECURSION
|
||||
set @var=
|
||||
(
|
||||
with recursive
|
||||
cte_1 as (
|
||||
select 1
|
||||
union
|
||||
select * from cte_2),
|
||||
cte_2 as (
|
||||
select * from cte_1
|
||||
union
|
||||
select a from t1, cte_2
|
||||
where t1.a=cte_2.a)
|
||||
select * from cte_2
|
||||
limit 1
|
||||
);
|
||||
|
||||
drop table t1;
|
||||
|
|
|
@ -4818,6 +4818,9 @@ end_with_restore_list:
|
|||
{
|
||||
List<set_var_base> *lex_var_list= &lex->var_list;
|
||||
|
||||
if (check_dependencies_in_with_clauses(thd->lex->with_clauses_list))
|
||||
goto error;
|
||||
|
||||
if ((check_table_access(thd, SELECT_ACL, all_tables, FALSE, UINT_MAX, FALSE)
|
||||
|| open_and_lock_tables(thd, all_tables, TRUE, 0)))
|
||||
goto error;
|
||||
|
|
Loading…
Add table
Reference in a new issue