Commit 50d7eddc authored by Igor Babaev's avatar Igor Babaev

MDEV-24314 Unexpected error message when selecting from view that uses

           mergeable derived table

Do not check privileges for derived tables/CTEs and their fields.

Approved by Oleksandr Byelkin <sanja@mariadb.com>
parent 1eb59c30
......@@ -6767,5 +6767,40 @@ DROP PROCEDURE sp;
DROP VIEW v1;
DROP TABLE t1;
#
# MDEV-24314: create view with derived table without default database
#
drop database test;
create database db1;
create table db1.t1 (a int);
insert into db1.t1 values (3),(7),(1);
create view db1.v1 as select * from (select * from db1.t1) t;
show create view db1.v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `db1`.`v1` AS select `t`.`a` AS `a` from (select `db1`.`t1`.`a` AS `a` from `db1`.`t1`) `t` latin1 latin1_swedish_ci
select * from db1.v1;
a
3
7
1
drop view db1.v1;
prepare stmt from "
create view db1.v1 as select * from (select * from db1.t1) t;
";
execute stmt;
deallocate prepare stmt;
show create view db1.v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `db1`.`v1` AS select `t`.`a` AS `a` from (select `db1`.`t1`.`a` AS `a` from `db1`.`t1`) `t` latin1 latin1_swedish_ci
select * from db1.v1;
a
3
7
1
drop view db1.v1;
drop table db1.t1;
drop database db1;
create database test;
use test;
#
# End of 10.2 tests
#
......@@ -6491,6 +6491,36 @@ DROP PROCEDURE sp;
DROP VIEW v1;
DROP TABLE t1;
--echo #
--echo # MDEV-24314: create view with derived table without default database
--echo #
drop database test;
create database db1;
create table db1.t1 (a int);
insert into db1.t1 values (3),(7),(1);
create view db1.v1 as select * from (select * from db1.t1) t;
show create view db1.v1;
select * from db1.v1;
drop view db1.v1;
prepare stmt from "
create view db1.v1 as select * from (select * from db1.t1) t;
";
execute stmt;
deallocate prepare stmt;
show create view db1.v1;
select * from db1.v1;
drop view db1.v1;
drop table db1.t1;
drop database db1;
create database test;
use test;
--echo #
--echo # End of 10.2 tests
--echo #
......@@ -5795,6 +5795,7 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
#ifndef NO_EMBEDDED_ACCESS_CHECKS
/* Check if there are sufficient access rights to the found field. */
if (check_privileges &&
!table_list->is_derived() &&
check_column_grant_in_table_ref(thd, *actual_table, name, length))
fld= WRONG_GRANT;
else
......
......@@ -6639,6 +6639,9 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv,
bool check_single_table_access(THD *thd, ulong privilege, TABLE_LIST *tables,
bool no_errors)
{
if (tables->is_derived())
return 0;
Switch_to_definer_security_ctx backup_sctx(thd, tables);
const char *db_name;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment