Bug #95876 Wrong result for query with outer join and IS NOT TRUE predicate in where clause
Submitted: 19 Jun 2019 11:38 Modified: 20 Jun 2019 10:45
Reporter: Valeriy Kravchuk Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.16, 5.7.26, 5.6.44 OS:Any
Assigned to: CPU Architecture:Any

[19 Jun 2019 11:38] Valeriy Kravchuk
Description:
As reported by Igor Babaev elsewhere, 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;

Note that row (1, NULL) in left join results:

mysql> select * from t1 left join t2 on a=b;
+------+------+
| a    | b    |
+------+------+
|    7 |    7 |
|    3 |    3 |
|    1 | NULL |
+------+------+
3 rows in set (0.00 sec)

satisfies this kind of WHERE conditions, as NULL is neither TRUE nor FALSE:

mysql> select null is not false;
+-------------------+
| null is not false |
+-------------------+
|                 1 |
+-------------------+
1 row in set (0.00 sec)

mysql> select null is not true;
+------------------+
| null is not true |
+------------------+
|                1 |
+------------------+
1 row in set (0.00 sec)

PosgreSQL returns correct result for this test.

How to repeat:
[openxs@fc29 8.0]$ bin/mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.16 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> drop table t1, t2;
ERROR 1051 (42S02): Unknown table 'test.t1,test.t2'
mysql> create table t1 (a int);
Query OK, 0 rows affected (0.42 sec)

mysql> create table t2 (b int);
Query OK, 0 rows affected (0.55 sec)

mysql> insert into t1 values (3), (7), (1);
Query OK, 3 rows affected (0.10 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> insert into t2 values (7), (4), (3);
Query OK, 3 rows affected (0.08 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from t1 left join t2 on a=b;
+------+------+
| a    | b    |
+------+------+
|    7 |    7 |
|    3 |    3 |
|    1 | NULL |
+------+------+
3 rows in set (0.00 sec)

mysql> 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)

mysql> 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> select * from t1 left join t2 on a=b where (b > 1) is not true;
Empty set (0.00 sec)

mysql> select null is not false;
+-------------------+
| null is not false |
+-------------------+
|                 1 |
+-------------------+
1 row in set (0.00 sec)

mysql> select null is not true;
+------------------+
| null is not true |
+------------------+
|                1 |
+------------------+
1 row in set (0.00 sec)

Suggested fix:
Process IS NOT RTUE and IS NOT FALSE conditions properly?
[19 Jun 2019 11:54] MySQL Verification Team
Hello Valeriy,

Thank you for the report and test case.
Verified as described with 8.0.16 build.

regards,
Umesh
[20 Jun 2019 10:45] Guilhem Bichot
Posted by developer:
 
Thanks for the report. Turns out that it's already fixed in 8.0.17 (under the number bug#94786).
[8 Mar 2023 20:56] Joel Rein
This bug continues to be present in builds in the 5.7 lineage, e.g. it is present in 5.7.41