[MDEV-4126] MySQL:68254 - wrong result with non-deterministic GROUP BY in subquery Created: 2013-02-02  Updated: 2022-12-02

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.0.1, 5.5.29, 5.3.12, 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10
Fix Version/s: 5.5, 10.3

Type: Bug Priority: Minor
Reporter: Elena Stepanova Assignee: Sergei Petrunia
Resolution: Unresolved Votes: 0
Labels: 11.0-sel, upstream


 Description   

The bug was originally filed by a user at bugs.mysql.com. It's reproducible on MySQL 5.6 as well as MariaDB 5.3-10.0.

See the original description, including the test case, and the suggested patch in http://bugs.mysql.com/bug.php?id=68254 (I don't know if I may copy-paste it).

The major complaint is that if table t1 has rows

a b
----
1 0
2 1
3 1
4 1

then, while a query

SELECT a from t1 group by b

returns

1
2

The query

SELECT x,y FROM t2 WHERE y IN (SELECT a FROM t1 GROUP BY b)

returns rows with y IN (1,2,3,4).

I've set it to Minor for now, because the query with GROUP BY is indeterministic according to MySQL documentation, so I don't see that much value in using it as a subquery; but it's still a bug since the subquery is supposed to return 2 values, not 4, even it can be any of (1,2), (1,3) or (1,4).

MySQL has verified the bug, although I don't know if they're going to fix it, and how.



 Comments   
Comment by Patryk Pomykalski [ 2013-02-26 ]

Strange, semijoin requirements have:

3. Subquery does not have GROUP BY or ORDER BY

in code:
!select_lex->group_list.elements && !join->order && // 3

but it still uses semijoin?

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