[MDEV-3552] LP:834758 - Wrong result with innner join, LooseScan, two-column IN() predicate Created: 2011-08-26  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: Sergei Petrunia
Resolution: Fixed Votes: 0
Labels: Launchpad

Attachments: XML File LPexportBug834758.xml    

 Description   

The following query:

SELECT *
FROM t1, t2
WHERE (t2.a , t1.b) IN (
SELECT a , b
FROM t3
);

returns the matching row twice:

-------+

b a

-------+

5 6
5 6

-------+

whereas the correct result is:

-------+

b a

-------+

5 6

-------+

explain:
----------------------------------------------------------------------------------------+

id select_type table type possible_keys key key_len ref rows Extra

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

1 PRIMARY t1 ALL NULL NULL NULL NULL 2  
1 PRIMARY t3 ALL b NULL NULL NULL 5 Using where; LooseScan
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t3.a 1 Using index

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

minimal optimizer_switch: semijoin=on,loosescan=on

full 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=on,materialization=off,in_to_exists=on,semijoin=on,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-08-23 15:51:47 +0300
build-date: 2011-08-26 17:20:27 +0300
revno: 3166
branch-nick: maria-5.3

test case:

CREATE TABLE t1 (b int) ;
INSERT INTO t1 VALUES (1),(5);

CREATE TABLE t2 (a int, PRIMARY KEY (a)) ;
INSERT INTO t2 VALUES (6),(10);

CREATE TABLE t3 (a int, b int, KEY (b)) ;
INSERT INTO t3 VALUES (6,5),(6,2),(8,0),(9,1),(6,5);

SET SESSION optimizer_switch='loosescan=on';

SELECT *
FROM t1, t2
WHERE (t2.a , t1.b) IN (
SELECT a , b
FROM t3
);



 Comments   
Comment by Sergei Petrunia [ 2011-09-05 ]

Re: Wrong result with innner join, LooseScan, two-column IN() predicate
The query plan of

1 PRIMARY t1 ALL NULL NULL NULL NULL 2  
1 PRIMARY t3 ALL b NULL NULL NULL 5 Using where; LooseScan
1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t3.a 1 Using index

is invalid, as LooseScan cannot be used together with "ALL" access method. LooseScan relies on table access method to produce duplicates grouped together, which is possible when access methods produce records in certain order. "ALL" is a full table scan, which does not guarantee any particular order.

Comment by Rasmus Johansson (Inactive) [ 2011-12-13 ]

Launchpad bug id: 834758

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