Description:
Hi, MySQL developers.
Please see below test cases. The second query produces empty results, which is wrong, because (subQuery1.col0) IS UNKNOWN should be evaluated as TRUE.
```
CREATE TABLE t1(c0 INT, c1 INT);
CREATE TABLE t2(c0 INT, c1 INT);
INSERT INTO t1(c0, c1) VALUES(NULL, NULL);
SELECT *
FROM t2
RIGHT JOIN (SELECT DISTINCT t1.c0 and t1.c1 AS col0
FROM t1) as subQuery1 ON true;
-- c0, c1, col0
-- NULL, NULL, NULL
SELECT *
FROM t2
RIGHT JOIN (SELECT DISTINCT (t1.c0 and t1.c1) AS col0
FROM t1) as subQuery1 ON true
where (subQuery1.col0) IS UNKNOWN;
-- empty result, which is wrong.
-- '(subQuery1.col0) IS UNKNOWN' should be evaluated as true, and then this query should produce NULL,NULL,NULL
SELECT *
FROM t2
RIGHT JOIN (SELECT DISTINCT (NULL) AS col0
FROM t1) as subQuery1 ON true
where (subQuery1.col0) IS UNKNOWN;
-- NULL,NULL,NULL
-- if I change '(t1.c0 and t1.c1)' to NULL, this query then produces correct result. So I guess there are also some bugs in the optimization of expression '(t1.c0 and t1.c1)'.
```
How to repeat:
CREATE TABLE t1(c0 INT, c1 INT);
CREATE TABLE t2(c0 INT, c1 INT);
INSERT INTO t1(c0, c1) VALUES(NULL, NULL);
SELECT *
FROM t2
RIGHT JOIN (SELECT DISTINCT t1.c0 and t1.c1 AS col0
FROM t1) as subQuery1 ON true;
-- c0, c1, col0
-- NULL, NULL, NULL
SELECT *
FROM t2
RIGHT JOIN (SELECT DISTINCT (t1.c0 and t1.c1) AS col0
FROM t1) as subQuery1 ON true
where (subQuery1.col0) IS UNKNOWN;
-- empty result, which is wrong.
SELECT *
FROM t2
RIGHT JOIN (SELECT DISTINCT (NULL) AS col0
FROM t1) as subQuery1 ON true
where (subQuery1.col0) IS UNKNOWN;
-- NULL,NULL,NULL