Wrong result with semijoin + materialization + AND in WHERE

Bug #869012 reported by Philip Stoev
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MariaDB
Fix Released
High
Sergey Petrunia

Bug 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 ;

Tags: regression
Changed in maria:
assignee: nobody → Sergey Petrunia (sergefp)
milestone: none → 5.3
Changed in maria:
importance: Undecided → High
Revision history for this message
Sergey Petrunia (sergefp) wrote :

The bug can only be repeated after

 ALTER TABLE t2 engine=innodb;

Changed in maria:
status: New → Confirmed
Revision history for this message
Sergey Petrunia (sergefp) wrote :

This bug has most likely been introduced by this change:

revno: 3053.1.1
revision-id: <email address hidden>
parent: <email address hidden>
  committer: Sergey Petrunya <email address hidden>
  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.

tags: added: regression
Changed in maria:
status: Confirmed → Fix Committed
Changed in maria:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.