Wrong result with ICP, outer join, subquery in maria-5.3-icp

Bug #887026 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
LEFT JOIN t2
ON 1
WHERE ( t2.b ) NOT IN (
        SELECT t4.b
        FROM t3, t4
        WHERE t4.b <= 2
        AND t4.c = t3.c
);

returns no rows when executed with maria-5.3-icp and index_condition_pushdown=ON and {c,NULL} in all other cases. The issue is also reproducible without empty/constant tables. The issue is also reproducible with realistic ON conditions.

explain:

id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 1
1 PRIMARY t2 ALL NULL NULL NULL NULL 1 Using where
2 DEPENDENT SUBQUERY t3 ALL NULL NULL NULL NULL 1
2 DEPENDENT SUBQUERY t4 ref_or_null b b 5 func 2 Using index condition; Using where; Full scan on NULL key

minimal switch: index_condition_pushdown=ON;
full 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=off,derived_with_keys=off,firstmatch=off,loosescan=off,materialization=off,in_to_exists=on,semijoin=off,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

 bzr version-info
revision-id: <email address hidden>
date: 2011-11-06 01:23:03 -0700
build-date: 2011-11-07 10:39:33 +0200
revno: 3269
branch-nick: maria-5.3-icp

test case:

CREATE TABLE t1 ( c varchar(1)) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('c');

CREATE TABLE t2 ( b int) ENGINE=InnoDB;

CREATE TABLE t3 ( c varchar(1)) ENGINE=InnoDB;
INSERT INTO t3 VALUES ('c');

CREATE TABLE t4 ( b int, c varchar(1), KEY (b)) ENGINE=InnoDB;
INSERT INTO t4 VALUES (7,'c');

SET SESSION optimizer_switch='index_condition_pushdown=ON';
SELECT *
FROM t1
LEFT JOIN t2
ON 1
WHERE ( t2.b ) NOT IN (
        SELECT t4.b
        FROM t3, t4
        WHERE t4.b <= 2
        AND t4.c = t3.c
);

Related branches

Changed in maria:
milestone: none → 5.3
assignee: nobody → Igor Babaev (igorb-seattle)
description: updated
Changed in maria:
status: New → Confirmed
Changed in maria:
importance: Undecided → High
assignee: Igor Babaev (igorb-seattle) → Sergey Petrunia (sergefp)
Revision history for this message
Sergey Petrunia (sergefp) wrote :

A testcase with MyISAM (without const tables):
drop table t1,t2,t3,t4;

CREATE TABLE t1 (c varchar(1));
INSERT INTO t1 VALUES ('c'), ('c');

CREATE TABLE t2 (c varchar(1), b int);
INSERT INTO t2 VALUES ('d', NULL),('d', NULL);

CREATE TABLE t3 (c varchar(1));
INSERT INTO t3 VALUES ('c');
INSERT INTO t3 VALUES ('c');

CREATE TABLE t4 ( b int, c varchar(1), KEY (b));
INSERT INTO t4 VALUES (7,'c');
INSERT INTO t4 VALUES (7,'c');

SET SESSION optimizer_switch='index_condition_pushdown=ON';
explain
SELECT *
FROM t1
LEFT JOIN t2
ON t1.c=t2.b
WHERE ( t2.b ) NOT IN (
        SELECT t4.b
        FROM t3 STRAIGHT_JOIN t4
        WHERE t4.b <= 2
        AND t4.c = t3.c
);

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.