[MDEV-29224] Wrong result with aggregate function in uncorrelated SELECT subquery in view definition Created: 2022-08-01  Updated: 2023-03-07  Resolved: 2023-03-07

Status: Closed
Project: MariaDB Server
Component/s: Views
Affects Version/s: 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9
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: Major
Reporter: Lena Startseva Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: view-protocol

Issue Links:
Duplicate
duplicates MDEV-30706 Different results of selects from vie... Closed
PartOf
is part of MDEV-27691 make working view-protocol Open

 Description   

Expected that "select from table" and "select from view" give the same result:
Test:

CREATE TABLE t1 (f1 INT);
INSERT INTO t1 VALUES (1),(2);
 
CREATE TABLE t2 (f2 int);
INSERT INTO t2 VALUES (3);
 
SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
CREATE VIEW v1 AS SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
SELECT * FROM v1;
 
DROP VIEW v1;
DROP TABLES t1,t2;

Actual result:

SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
( SELECT MAX(f1) FROM t2 )
2
CREATE VIEW v1 AS SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
SELECT * FROM v1;
( SELECT MAX(f1) FROM t2 )
1
2

Expected result:

SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
( SELECT MAX(f1) FROM t2 )
2
CREATE VIEW v1 AS SELECT ( SELECT MAX(f1) FROM t2 ) FROM t1;
SELECT * FROM v1;
( SELECT MAX(f1) FROM t2 )
2



 Comments   
Comment by Igor Babaev [ 2023-03-07 ]

The reported test case has been added to the patch for MDEV-30706

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