[MDEV-3629] LP:879860 - Wrong result with correlated query in select list + aggregate Created: 2011-10-22  Updated: 2015-02-02  Resolved: 2012-10-04

Status: Closed
Project: MariaDB Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Philip Stoev (Inactive) Assignee: Igor Babaev
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug879860.xml    

 Description   

The following query:

SELECT ( SELECT MIN( t1.a ) FROM t1, t2 WHERE t2.a = t3.t1 ) FROM t3;

returns

1
1

even though the correct result should be

NULL
NULL

as there are no rows for which t2.a = t3.t1 is true

explain:

1 PRIMARY t3 ALL NULL NULL NULL NULL 2  
2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 1  
2 DEPENDENT SUBQUERY t2 system NULL NULL NULL NULL 1  

repeatable in maria-5.3, maria-5.2, mysql-5.5

test case:

CREATE TABLE t1 ( a int NOT NULL, PRIMARY KEY (a)) engine=myisam;
INSERT INTO t1 VALUES (1);

CREATE TABLE t2 ( a int NOT NULL ) engine=myisam;
INSERT INTO t2 VALUES (10);

CREATE TABLE t3 ( a int NOT NULL , t1 int) engine=myisam;
INSERT INTO t3 VALUES (19,1),(20,5);

SELECT ( SELECT MIN( t1.a ) FROM t1, t2 WHERE t2.a = t3.t1 ) FROM t3;



 Comments   
Comment by Rasmus Johansson (Inactive) [ 2012-02-20 ]

Launchpad bug id: 879860

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