Wrong result with derived_merge=ON, RIGHT JOIN

Bug #901312 reported by Elena Stepanova
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MariaDB
Fix Released
Critical
Igor Babaev

Bug Description

The following query

SELECT alias1.* FROM
   ( SELECT * FROM t1 ) AS alias1
  RIGHT JOIN t2
    ON ( b = a )
WHERE
    t2.b IN ( SELECT c FROM t3 );

Returns NULLs instead of numeric column values with derived_merge=ON, and correct values with derived_merge=OFF.

EXPLAIN with derived_merge=ON:

1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 5 func 1 100.00
1 PRIMARY t1 ALL NULL NULL NULL NULL 2 100.00 Using where
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00

select `test`.`t1`.`a` AS `a` from `test`.`t2` semi join (`test`.`t3`) left join (`test`.`t1`) on((`test`.`t1`.`a` = `test`.`t2`.`b`)) where 1

EXPLAIN with derived_merge=OFF:

1 PRIMARY t2 ALL NULL NULL NULL NULL 2 100.00
1 PRIMARY <subquery3> eq_ref distinct_key distinct_key 5 func 1 100.00
1 PRIMARY <derived2> ref key0 key0 5 test.t2.b 2100.00 Using where
3 MATERIALIZED t3 ALL NULL NULL NULL NULL 2 100.00
2 DERIVED t1 ALL NULL NULL NULL NULL 2 100.00

select `alias1`.`a` AS `a` from `test`.`t2` semi join (`test`.`t3`) left join (select `test`.`t1`.`a` AS `a` from `test`.`t1`) `alias1` on(((`alias1`.`a` = `test`.`t2`.`b`) and (`test`.`t2`.`b` is not null))) where 1

Minimal optimizer_switch: none needed (derived_merge=ON by default)

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=on,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=on,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

Test case:

CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (4),(1);
CREATE TABLE t2 (b INT);
INSERT INTO t2 VALUES (4),(1);
CREATE TABLE t3 (c INT);
INSERT INTO t3 VALUES (4),(1);

SELECT alias1.* FROM
   ( SELECT * FROM t1 ) AS alias1
  RIGHT JOIN t2
    ON ( b = a )
WHERE
    t2.b IN ( SELECT c FROM t3 );

bzr version-info:

revision-id: <email address hidden>
date: 2011-12-06 13:42:18 -0800
build-date: 2011-12-07 20:37:21 +0300
revno: 3334
branch-nick: maria-5.3

Elena Stepanova (elenst)
Changed in maria:
milestone: none → 5.3
assignee: nobody → Igor Babaev (igorb-seattle)
Changed in maria:
status: New → Confirmed
importance: Undecided → Critical
Revision history for this message
Igor Babaev (igorb-seattle) wrote :

The bug can be reproduced without derived table:

MariaDB [test]> SELECT alias1.* FROM t1 AS alias1 RIGHT JOIN t2 ON ( b = a ) WHERE t2.b IN ( SELECT c FROM t3 );
+------+
| a |
+------+
| NULL |
| NULL |
+------+
2 rows in set (0.01 sec)

MariaDB [test]> SELECT * FROM t1 AS alias1 RIGHT JOIN t2 ON ( b = a ) WHERE t2.b IN ( SELECT c FROM t3);
+------+------+
| a | b |
+------+------+
| NULL | 4 |
| NULL | 1 |
+------+------+
2 rows in set (0.00 sec)

Changed in maria:
status: Confirmed → In Progress
Revision history for this message
Elena Stepanova (elenst) wrote :

Given Igor's comment, bug#901796 must be a duplicate of this one.

Changed in maria:
status: In Progress → 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.