[MDEV-3548] LP:869012 - Wrong result with semijoin + materialization + AND in WHERE Created: 2011-10-06  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 LPexportBug869012.xml    

 Description   

The following query:

SELECT *
FROM t1 , t2
WHERE ( t1.f4 ) IN ( SELECT f4 FROM t3 )
AND t2.f4 != t1.f3 ;

returns no rows when executed with semijoin+materialization, even though the correct result is:

x x g
x x g

as those rows do match the WHERE predicate.

Explain:

1 PRIMARY t2 ALL NULL NULL NULL NULL 1  
1 PRIMARY <subquery2> ALL distinct_key NULL NULL NULL 1 Using where
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where; Using join buffer (flat, BNL join)
2 SUBQUERY t3 ALL NULL NULL NULL NULL 1  

minimal optimizer switch:semijoin=on,materialization=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=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,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-10-06 01:21:15 +0400
build-date: 2011-10-06 12:19:12 +0300
revno: 3213
branch-nick: maria-5.3

test case:

--source include/have_innodb.inc
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (f3 varchar(1) , f4 varchar(1) ) engine=InnoDB;
INSERT IGNORE INTO t1 VALUES ('x','x'),('x','x');

DROP TABLE IF EXISTS t2;
CREATE TABLE t2 ( f4 varchar(1) ) ;
INSERT IGNORE INTO t2 VALUES ('g');

DROP TABLE IF EXISTS t3;
CREATE TABLE t3 (f4 varchar(1) ) Engine=InnoDB;
INSERT IGNORE INTO t3 VALUES ('x');

SET SESSION optimizer_switch='semijoin=on,materialization=on';
SELECT *
FROM t1 , t2
WHERE ( t1.f4 ) IN ( SELECT f4 FROM t3 )
AND t2.f4 != t1.f3 ;



 Comments   
Comment by Sergei Petrunia [ 2011-10-11 ]

Re: Wrong result with semijoin + materialization + AND in WHERE
The bug can only be repeated after

ALTER TABLE t2 engine=innodb;

Comment by Sergei Petrunia [ 2011-10-11 ]

Re: Wrong result with semijoin + materialization + AND in WHERE
This bug has most likely been introduced by this change:

revno: 3053.1.1
revision-id: psergey@askmonty.org-20110621215728-6tkzlruy8iiv1nxf
parent: timour@askmonty.org-20110621200101-9jh217r9zk71qhz1
committer: Sergey Petrunya <psergey@askmonty.org>
branch nick: 5.3-sj1
timestamp: Wed 2011-06-22 01:57:28 +0400
message:
Make semi-joins work with outer joins part #1:

  • Make make_outerjoin_info() correctly process semi-join nests
  • Make make_join_select() attach conditions to the right places.
Comment by Rasmus Johansson (Inactive) [ 2011-12-13 ]

Launchpad bug id: 869012

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