Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-19790

Wrong result for query with outer join and IS NOT TRUE predicate in where clause

Details

    Description

      The problem manifests itself when running queries with IS NOT TRUE or IS NOT FALSE predicates in their where clauses.
      The following simple test case can demonstrate the problem in 5.5 and all upper versions

      create table t1 (a int);
      create table t2 (b int);
      insert into t1 values (3), (7), (1);
      insert into t2 values (7), (4), (3);
      select * from t1 left join t2 on a=b;
      select * from t1 left join t2 on a=b where (b > 3) is not true;
      select * from t1 left join t2 on a=b where (b > 3) is not false;
      

      MariaDB [test]> select * from t1 left join t2 on a=b;
      +------+------+
      | a    | b    |
      +------+------+
      |    7 |    7 |
      |    3 |    3 |
      |    1 | NULL |
      +------+------+
      3 rows in set (0.00 sec)
       
      MariaDB [test]> select * from t1 left join t2 on a=b where (b > 3) is not true;
      +------+------+
      | a    | b    |
      +------+------+
      |    3 |    3 |
      +------+------+
      1 row in set (0.00 sec)
      MariaDB [test]> select * from t1 left join t2 on a=b where (b > 3) is not false;
      +------+------+
      | a    | b    |
      +------+------+
      |    7 |    7 |
      +------+------+
      1 row in set (0.00 sec)
      

      MySQL 8.0 (and most probably all prior versions) returns the same result sets for the above queries.
      Postgres returns correct results:

      postgres=# select * from t1 left join t2 on a=b;
       a | b 
      ---+---
       1 |  
       3 | 3
       7 | 7
      (3 rows)
       
      postgres=# select * from t1 left join t2 on a=b where (b > 1) is not true;
       a | b 
      ---+---
       1 |  
      (1 row)
      

      Attachments

        Activity

          igor Igor Babaev (Inactive) created issue -
          igor Igor Babaev (Inactive) made changes -
          Field Original Value New Value
          Status Open [ 1 ] In Progress [ 3 ]
          igor Igor Babaev (Inactive) made changes -
          Summary Wrong result for query with outer join and IS NOT TRUE predicate in the where clause Wrong result for query with outer join and IS NOT TRUE predicate in where clause
          valerii Valerii Kravchuk made changes -
          Labels upstream
          igor Igor Babaev (Inactive) made changes -
          Fix Version/s 5.5.65 [ 23402 ]
          Fix Version/s 10.1.41 [ 23406 ]
          Fix Version/s 10.2.26 [ 23409 ]
          Fix Version/s 10.3.17 [ 23411 ]
          Fix Version/s 10.4.7 [ 23720 ]
          Fix Version/s 5.5 [ 15800 ]
          igor Igor Babaev (Inactive) made changes -
          Resolution Fixed [ 1 ]
          Status In Progress [ 3 ] Closed [ 6 ]
          serg Sergei Golubchik made changes -
          Issue Type Task [ 3 ] Bug [ 1 ]
          serg Sergei Golubchik made changes -
          Workflow MariaDB v3 [ 97568 ] MariaDB v4 [ 156364 ]

          People

            igor Igor Babaev (Inactive)
            igor Igor Babaev (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.