[MDEV-3713] LP:849739 - Wrong result with double GROUP BY and subquery Created: 2011-09-14  Updated: 2012-10-04  Resolved: 2012-10-04

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

Type: Bug
Reporter: Philip Stoev (Inactive) Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug849739.xml    

 Description   

The following query:

SELECT * FROM t2 WHERE (a, b) IN (
SELECT a , b FROM t1
WHERE a IS NOT NULL
GROUP BY a , b
) ;

returns only 1 row whereas it has to return the full set of 20 rows. Repeatable in maria-5.3 with both in_to_exists and materialization. Repeatable in mysql-5.5. See also previous GROUP BY bugs filed on LP.

Explain:

MariaDB [test]> explain SELECT * FROM t2 WHERE (a, b) IN ( SELECT a , b FROM t1 WHERE a IS NOT NULL GROUP BY a , b );
-------------------------------------------------------------------------------------------------------------------------+

id select_type table type possible_keys key key_len ref rows Extra

-------------------------------------------------------------------------------------------------------------------------+

1 PRIMARY t2 ALL NULL NULL NULL NULL 20 Using where
2 DEPENDENT SUBQUERY t1 range PRIMARY PRIMARY 4 NULL 21 Using where; Using index for group-by; Using temporary

-------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

test case:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 ( a integer NOT NULL, PRIMARY KEY (a)) ENGINE=MyISAM;
INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20);

DROP TABLE IF EXISTS t2;
CREATE TABLE t2 ( a integer, b integer );
INSERT INTO t2 VALUES (1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9),(10,10),(11,11),(12,12),(13,13),(14,14),(15,15),(16,16),(17,17),(18,18),(19,19),(20,20);
SELECT * FROM t2 WHERE (a, b) IN (
SELECT a , b FROM t1
WHERE a IS NOT NULL
GROUP BY a , b
) ;

optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,index_condition_pushdown=off,derived_merge=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=on,in_to_exists=off,semijoin=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=off,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=off,semijoin_with_cache=off,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=off,table_elimination=on

bzr version-info
revision-id: <email address hidden>
date: 2011-09-10 18:01:27 +0300
build-date: 2011-09-14 10:06:03 +0300
revno: 3183
branch-nick: maria-5.3



 Comments   
Comment by Elena Stepanova [ 2012-03-22 ]

Re: Wrong result with double GROUP BY and subquery
The bug was fixed in 5.3.3-rc.

Comment by Rasmus Johansson (Inactive) [ 2012-03-22 ]

Launchpad bug id: 849739

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