<?xml version="1.0" encoding="utf-8"?>
<launchpad-bug id="694443">
  <date_last_updated>2011-12-13 15:33:52.978087+00:00</date_last_updated>
  <api_links>
    <bug_api_link>https://api.launchpad.net/1.0/bugs/694443</bug_api_link>
    <bug_owner_link>https://api.launchpad.net/1.0/~philip-stoev</bug_owner_link>
    <milestone_link>https://api.launchpad.net/1.0/maria/+milestone/5.3</milestone_link>
    <linked_branches_collection_link>https://api.launchpad.net/1.0/bugs/694443/linked_branches</linked_branches_collection_link>
    <activity_link>https://api.launchpad.net/1.0/bugs/694443/activity</activity_link>
  </api_links>
  <bug_web_link>https://bugs.launchpad.net/bugs/694443</bug_web_link>
  <owner>Philip Stoev</owner>
  <assignee>Igor Babaev</assignee>
  <milestone_title>Maria 5.3</milestone_title>
  <duplicate_link></duplicate_link>
  <duplicate_bug_id></duplicate_bug_id>
  <title>Wrong result with hash join and join_cache_level=6</title>
  <status>Fix Released</status>
  <importance>Critical</importance>
  <created>2010-12-26 10:03:00.901623+00:00</created>
  <description>
<![CDATA[In maria-5.3 , the following query:

SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

returns no rows even though 1 row matches the  WHERE predicate and is returned by all other plans.

explain:

id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2
1       SIMPLE  t2      ref     f3      f3      5       const   1       Using where; Using join buffer (flat, BNLH join)

test case:

CREATE TABLE t1 (f2 int(11), f4 varchar(10)) ;
INSERT IGNORE INTO t1 VALUES ('19','time'),('24','juabngoyrt');

CREATE TABLE t2 (f5 varchar(10), f2 int(11), f1 int(11), f3 int(11), KEY (f3)) ;
INSERT IGNORE INTO t2 VALUES ('time','4',NULL,NULL);

SET SESSION join_cache_level=6;
SET SESSION optimizer_switch='join_cache_bka=off';
SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;
EXPLAIN SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

SET SESSION join_cache_level=0;
SET SESSION optimizer_switch='index_condition_pushdown=off';
SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

Even though this particular test case includes join_cache_bka=off, the problematic query plan was also observed without having to force it.]]>  </description>
  <activities>
    <activity datechanged="2010-12-26T10:03:00.901623+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[]]>      </newvalue>
      <whatchanged>bug</whatchanged>
      <person>Philip Stoev</person>
      <message>added bug</message>
    </activity>
    <activity datechanged="2010-12-26T10:03:24.781293+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[Igor Babaev (igorb-seattle)]]>      </newvalue>
      <whatchanged>maria: assignee</whatchanged>
      <person>Philip Stoev</person>
      <message></message>
    </activity>
    <activity datechanged="2010-12-26T10:03:27.043294+00:00">
      <oldvalue>
<![CDATA[]]>      </oldvalue>
      <newvalue>
<![CDATA[5.3]]>      </newvalue>
      <whatchanged>maria: milestone</whatchanged>
      <person>Philip Stoev</person>
      <message></message>
    </activity>
    <activity datechanged="2010-12-26T10:05:24.706729+00:00">
      <oldvalue>
<![CDATA[In maria-5.3 , the following query:

SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

returns no rows even though 1 row matches the  WHERE predicate and is returned by all other plans.

explain:

id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2
1       SIMPLE  t2      ref     f3      f3      5       const   1       Using where; Using join buffer (flat, BNLH join)

test case:

CREATE TABLE t1 (f2 int(11), f4 varchar(10)) ;
INSERT IGNORE INTO t1 VALUES ('19','time'),('24','juabngoyrt');

CREATE TABLE t2 (f5 varchar(10), f2 int(11), f1 int(11), f3 int(11), KEY (f3)) ;
INSERT IGNORE INTO t2 VALUES ('time','4',NULL,NULL);

SET SESSION join_cache_level=6;
SET SESSION optimizer_switch='join_cache_bka=off';
SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;
EXPLAIN SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

SET SESSION join_cache_level=0;
SET SESSION optimizer_switch='index_condition_pushdown=off';
SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;]]>      </oldvalue>
      <newvalue>
<![CDATA[In maria-5.3 , the following query:

SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

returns no rows even though 1 row matches the  WHERE predicate and is returned by all other plans.

explain:

id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2
1       SIMPLE  t2      ref     f3      f3      5       const   1       Using where; Using join buffer (flat, BNLH join)

test case:

CREATE TABLE t1 (f2 int(11), f4 varchar(10)) ;
INSERT IGNORE INTO t1 VALUES ('19','time'),('24','juabngoyrt');

CREATE TABLE t2 (f5 varchar(10), f2 int(11), f1 int(11), f3 int(11), KEY (f3)) ;
INSERT IGNORE INTO t2 VALUES ('time','4',NULL,NULL);

SET SESSION join_cache_level=6;
SET SESSION optimizer_switch='join_cache_bka=off';
SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;
EXPLAIN SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

SET SESSION join_cache_level=0;
SET SESSION optimizer_switch='index_condition_pushdown=off';
SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

Even though this particular test case includes join_cache_bka=off, the problematic query plan was also observed without having to force it.]]>      </newvalue>
      <whatchanged>description</whatchanged>
      <person>Philip Stoev</person>
      <message></message>
    </activity>
    <activity datechanged="2010-12-26T20:02:26.618015+00:00">
      <oldvalue>
<![CDATA[New]]>      </oldvalue>
      <newvalue>
<![CDATA[Confirmed]]>      </newvalue>
      <whatchanged>maria: status</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2010-12-26T20:02:38.840107+00:00">
      <oldvalue>
<![CDATA[Undecided]]>      </oldvalue>
      <newvalue>
<![CDATA[Critical]]>      </newvalue>
      <whatchanged>maria: importance</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2010-12-26T20:50:15.619415+00:00">
      <oldvalue>
<![CDATA[Confirmed]]>      </oldvalue>
      <newvalue>
<![CDATA[In Progress]]>      </newvalue>
      <whatchanged>maria: status</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2010-12-30T03:02:33.947208+00:00">
      <oldvalue>
<![CDATA[In Progress]]>      </oldvalue>
      <newvalue>
<![CDATA[Fix Committed]]>      </newvalue>
      <whatchanged>maria: status</whatchanged>
      <person>Igor Babaev</person>
      <message></message>
    </activity>
    <activity datechanged="2011-12-13T15:33:52.105571+00:00">
      <oldvalue>
<![CDATA[Fix Committed]]>      </oldvalue>
      <newvalue>
<![CDATA[Fix Released]]>      </newvalue>
      <whatchanged>maria: status</whatchanged>
      <person>Daniel Bartholomew</person>
      <message></message>
    </activity>
  </activities>
  <comments>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/694443/comments/0" datecreated="2010-12-26T10:03:00.901623+00:00">
      <person>Philip Stoev</person>
      <subject>
<![CDATA[Wrong result with hash join and join_cache_level=6]]>      </subject>
      <content>
<![CDATA[In maria-5.3 , the following query:

SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

returns no rows even though 1 row matches the  WHERE predicate and is returned by all other plans.

explain:

id      select_type     table   type    possible_keys   key     key_len ref     rows    Extra
1       SIMPLE  t1      ALL     NULL    NULL    NULL    NULL    2
1       SIMPLE  t2      ref     f3      f3      5       const   1       Using where; Using join buffer (flat, BNLH join)

test case:

CREATE TABLE t1 (f2 int(11), f4 varchar(10)) ;
INSERT IGNORE INTO t1 VALUES ('19','time'),('24','juabngoyrt');

CREATE TABLE t2 (f5 varchar(10), f2 int(11), f1 int(11), f3 int(11), KEY (f3)) ;
INSERT IGNORE INTO t2 VALUES ('time','4',NULL,NULL);

SET SESSION join_cache_level=6;
SET SESSION optimizer_switch='join_cache_bka=off';
SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;
EXPLAIN SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;

SET SESSION join_cache_level=0;
SET SESSION optimizer_switch='index_condition_pushdown=off';
SELECT STRAIGHT_JOIN t1.f2 FROM t1 JOIN t2 ON t1.f4 = t2.f5 WHERE ( t2.f1 OR t2.f2 ) AND t2.f3 IS NULL ;]]>      </content>
    </comment>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/694443/comments/1" datecreated="2010-12-26T10:03:54.179044+00:00">
      <person>Philip Stoev</person>
      <subject>
<![CDATA[Re: Wrong result with hash join and join_cache_level=6]]>      </subject>
      <content>
<![CDATA[bzr version-info:


revision-id: igor@askmonty.org-20101226025414-1opbueutu602o8eu
date: 2010-12-25 18:54:14 -0800
build-date: 2010-12-26 12:03:40 +0200
revno: 2871
branch-nick: maria-5.3]]>      </content>
    </comment>
    <comment commentlink="https://api.launchpad.net/1.0/maria/+bug/694443/comments/2" datecreated="2010-12-26T21:42:52.112954+00:00">
      <person>Igor Babaev</person>
      <subject>
<![CDATA[Re: Wrong result with hash join and join_cache_level=6]]>      </subject>
      <content>
<![CDATA[The bug can be reproduced with join_cache_level=4, without STRAIGHT_JOIN and
with tables of a simpler structure: 

MariaDB [test]> CREATE TABLE t1 (a int PRIMARY KEY);
Query OK, 0 rows affected (0.02 sec)

MariaDB [test]> INSERT INTO t1 VALUES
    ->   (7), (4), (9), (1), (3), (8), (2);
Query OK, 7 rows affected (0.01 sec)
Records: 7  Duplicates: 0  Warnings: 0

MariaDB [test]> CREATE TABLE t2 (a int, b int, INDEX idx (a));
Query OK, 0 rows affected (0.00 sec)

MariaDB [test]> INSERT INTO t2 VALUES
    ->   (NULL,10), (4,80), (7,70), (6,11), (7,90), (NULL,40),
    ->   (4,77), (4,50), (NULL,41), (7,99), (7,88), (8,12),
    ->   (1,21), (4,90), (7,91), (8,22), (6,92), (NULL,42),
    ->   (2,78), (2,51), (1,43), (5,97), (5,89);
Query OK, 23 rows affected (0.00 sec)
Records: 23  Duplicates: 0  Warnings: 0

MariaDB [test]> 
MariaDB [test]> SET SESSION join_cache_level = 1;
Query OK, 0 rows affected (0.00 sec)

MariaDB [test]> EXPLAIN 
    -> SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL;
+----+-------------+-------+-------+---------------+---------+---------+-------+------+--------------------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | Extra                    |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+--------------------------+
|  1 | SIMPLE      | t1    | range | PRIMARY       | PRIMARY | 4       | NULL  |    3 | Using where; Using index |
|  1 | SIMPLE      | t2    | ref   | idx           | idx     | 5       | const |    4 | Using index condition    |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+--------------------------+
2 rows in set (0.00 sec)

MariaDB [test]> SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL;
+---+------+------+
| a | a    | b    |
+---+------+------+
| 1 | NULL |   10 |
| 1 | NULL |   40 |
| 1 | NULL |   41 |
| 1 | NULL |   42 |
| 2 | NULL |   10 |
| 2 | NULL |   40 |
| 2 | NULL |   41 |
| 2 | NULL |   42 |
+---+------+------+
8 rows in set (0.00 sec)
 
MariaDB [test]> SET SESSION join_cache_level = 4;
Query OK, 0 rows affected (0.00 sec)

MariaDB [test]> EXPLAIN 
    -> SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL;
+----+-------------+-------+-------+---------------+---------+---------+-------+------+--------------------------------------------------+
| id | select_type | table | type  | possible_keys | key     | key_len | ref   | rows | Extra                                            |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+--------------------------------------------------+
|  1 | SIMPLE      | t1    | range | PRIMARY       | PRIMARY | 4       | NULL  |    3 | Using where; Using index                         |
|  1 | SIMPLE      | t2    | ref   | idx           | idx     | 5       | const |    4 | Using where; Using join buffer (flat, BNLH join) |
+----+-------------+-------+-------+---------------+---------+---------+-------+------+--------------------------------------------------+
2 rows in set (0.00 sec)

MariaDB [test]> SELECT * FROM t1,t2 WHERE t1.a < 3 and t2.a IS NULL;
Empty set (0.00 sec)

]]>      </content>
    </comment>
  </comments>
</launchpad-bug>
