1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

MDEV-28603 Invalid view when its definition uses TVC as single-value subquery

Subselect_single_value_engine cannot handle table value constructor used as
subquery. That's why any table value constructor TVC used as subquery is
converted into a select over derived table whose specification is TVC.
Currently the names  of the columns of the derived table DT are taken from
the first element of TVC and if the k-th component of the element happens
to be a subquery the text representation of this subquery serves as the
name of the k-th column of the derived table. References of all columns of
the derived table DT compose the select list of the result of the conversion.
If a definition of a view contained a table value constructor used as a
subquery and the view was registered after this conversion had been
applied we could register an invalid view definition if the first element
of TVC contained a subquery as its component: the name of this component
was taken from the original subquery, while the name of the corresponding
column of the derived table was taken from the text representation of the
subquery produced by the function SELECT_LEX::print() and these names were
usually differ from each other.
To avoid registration of such invalid views the function SELECT_LEX::print()
now prints the original TVC instead of the select in which this TVC has
been wrapped. Now the specification of registered view looks like as if no
conversions from TVC to selects were done.

Approved by Oleksandr Byelkin <sanja@mariadb.com>
This commit is contained in:
Igor Babaev
2023-02-27 10:51:22 -08:00
parent 839c7fcf38
commit 841e8877cc
9 changed files with 211 additions and 4 deletions

View File

@ -1736,6 +1736,80 @@ INSERT INTO t1 (VALUES (DEFAULT) UNION VALUES (DEFAULT));
INSERT INTO t1 (VALUES (IGNORE) UNION VALUES (IGNORE));
DROP TABLE t1;
--echo #
--echo # MDEV-28603: VIEW with table value constructor used as single-value
--echo # subquery contains subquery as its first element
--echo #
create table t1 (a int);
insert into t1 values (3), (7), (1);
create table t2 (b int);
insert into t2 values (1), (2);
let $q=
select (values ((select * from t1 where a > 5))) as m from t2;
eval create view v as $q;
eval $q;
eval select * from v;
eval with cte as ( $q ) select * from cte;
eval explain $q;
eval explain select * from v;
eval explain with cte as ( $q ) select * from cte;
eval prepare stmt from "$q";
execute stmt;
execute stmt;
deallocate prepare stmt;
eval prepare stmt from "select * from v";
execute stmt;
execute stmt;
deallocate prepare stmt;
eval prepare stmt from "with cte as ( $q ) select * from cte";
execute stmt;
execute stmt;
deallocate prepare stmt;
show create view v;
drop view v;
eval prepare stmt from "create view v as $q";
execute stmt;
show create view v;
select * from v;
drop view v;
execute stmt;
show create view v;
select * from v;
deallocate prepare stmt;
prepare stmt from "show create view v";
execute stmt;
execute stmt;
deallocate prepare stmt;
drop view v;
let $q=
select (values ((select * from t1 where a > 5
union
select * from t1 where a > 7))) as m from t2;
eval create view v as $q;
eval $q;
eval select * from v;
show create view v;
drop view v;
drop table t1,t2;
--echo #
--echo # End of 10.4 tests
--echo #