MDEV-24019 Assertion is hit for query using recursive CTE with no default DB

When the query using a recursive CTE whose definition contained wildcard
symbols in the recursive part was processed at the prepare stage an
assertion was hit if the query was executed without any default database
set. The failure happened when the function insert_fields() tried to check
column privileges for the temporary table created for a recursive
reference to the CTE. No acl checks are needed for any CTE. That's why this
check should be blocked as well. The patch formulates a stricter condition
at which this check is to be blocked that covers the case when a query
using recursive CTEs is executed with no default database set.

Approved by Oleksandr Byelkin <sanja@mariadb.com>
This commit is contained in:
Igor Babaev 2020-12-08 11:13:36 -08:00
commit a3f7f2334a
3 changed files with 90 additions and 24 deletions

View file

@ -4191,5 +4191,49 @@ a b c
deallocate prepare stmt;
drop table t1;
#
# MDEV-24019: query with recursive CTE when no default database is set
#
drop database test;
with recursive a as
(select 1 from dual union select * from a as r)
select * from a;
1
1
create database db1;
create table db1.t1 (a int);
insert into db1.t1 values (3), (7), (1);
with recursive cte as
(select * from db1.t1 union select * from (select * from cte) as t)
select * from cte;
a
3
7
1
explain with recursive cte as
(select * from db1.t1 union select * from (select * from cte) as t)
select * from cte;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> ALL NULL NULL NULL NULL 3
2 DERIVED t1 ALL NULL NULL NULL NULL 3
3 RECURSIVE UNION <derived2> ALL NULL NULL NULL NULL 3
NULL UNION RESULT <union2,3> ALL NULL NULL NULL NULL NULL
prepare stmt from "with recursive cte as
(select * from db1.t1 union select * from (select * from cte) as t)
select * from cte";
execute stmt;
a
3
7
1
execute stmt;
a
3
7
1
deallocate prepare stmt;
drop database db1;
create database test;
use test;
#
# End of 10.2 tests
#

View file

@ -2690,6 +2690,41 @@ deallocate prepare stmt;
drop table t1;
--echo #
--echo # MDEV-24019: query with recursive CTE when no default database is set
--echo #
drop database test;
let $q=
with recursive a as
(select 1 from dual union select * from a as r)
select * from a;
eval $q;
create database db1;
create table db1.t1 (a int);
insert into db1.t1 values (3), (7), (1);
let $q=
with recursive cte as
(select * from db1.t1 union select * from (select * from cte) as t)
select * from cte;
eval $q;
eval explain $q;
eval prepare stmt from "$q";
execute stmt;
execute stmt;
deallocate prepare stmt;
drop database db1;
create database test;
use test;
--echo #
--echo # End of 10.2 tests
--echo #