[MDEV-30668] Set function aggregated in outer select used in view definition Created: 2023-02-17  Updated: 2023-03-20  Resolved: 2023-03-07

Status: Closed
Project: MariaDB Server
Component/s: Views
Affects Version/s: N/A
Fix Version/s: 10.11.3, 11.0.2, 10.4.29, 10.5.20, 10.6.13, 10.8.8, 10.9.6, 10.10.4

Type: Bug Priority: Blocker
Reporter: Sergei Golubchik Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Duplicate
is duplicated by MDEV-28570 Select from view fails if definition ... Closed
is duplicated by MDEV-28571 Select from view fails if definition ... Closed
Problem/Incident
is caused by MDEV-30586 DELETE with aggregation in subquery o... Closed

 Description   

$ ./mtr main.delete --view
Logging: ./mtr  main.delete --view
MariaDB Version 10.4.29-MariaDB-debug
==============================================================================
TEST                                      RESULT   TIME (ms) or COMMENT
--------------------------------------------------------------------------
main.delete                              [ fail ]
        Test ended at 2023-02-17 09:40:49
 
CURRENT_TEST: main.delete
mysqltest: At line 607: query 'select * from t1
where $c' failed: 1356: View 'test.mysqltest_tmp_v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
 
The result from queries just before the failure was:
< snip >
#
# MDEV-30586: DELETE with WHERE containing nested subquery
#             with set function aggregated in outer subquery
#
create table t1 (a int);
insert into t1 values (3), (7), (1);
create table t2 (b int);
insert into t2 values (2), (1), (4), (7);
create table t3 (a int, b int);
insert into t3 values (2,10), (7,30), (2,30), (1,10), (7,40);
select * from t1
where t1.a in (select t3.a from t3 group by t3.a
having t3.a > any (select t2.b from t2
where t2.b*10 < sum(t3.b)));
--------------------------------------------------------------------------
The servers were restarted 0 times
Spent 0.000 of 3 seconds executing testcases
 
Failure: Failed 1/1 tests, 0.00% were successful.
 
Failing test(s): main.delete



 Comments   
Comment by Igor Babaev [ 2023-02-17 ]

This bug is not caused by the fix of MDEV-30586. The test case added in the patch for MDEV-30586 demonstrates this bug with --view-protocol.

Comment by Igor Babaev [ 2023-02-26 ]

With the view protocol this query is executed:

select * from v;

where v is specified as follows:

create view v  as
select * from t1
  where t1.a in (select t3.a from t3 group by t3.a
                   having t3.a > any (select t2.b from t2
                                        where t2.b*10 < sum(t3.b)));

The query returns:

MariaDB [test]> select * from v;
ERROR 1356 (HY000): View 'test.v' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them

Note that if we use CTE with the same specification query as for the view we get the expected result

MariaDB [test]> with cte as 
    -> (select * from t1
    ->   where t1.a in (select t3.a from t3 group by t3.a
    ->                    having t3.a > any (select t2.b from t2
    ->                                         where t2.b*10 < sum(t3.b))))
    -> select * from cte;
+------+
| a    |
+------+
|    7 |
+------+
1 row in set (0.006 sec)

Comment by Oleksandr Byelkin [ 2023-03-02 ]

OK to push

Generated at Thu Feb 08 10:17:59 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.