Description:
When performing a RIGHT JOIN with a VIEW that contains an IN subquery predicate, MySQL incorrectly returns a non-NULL value from the left side (VIEW) instead of NULL when the VIEW itself returns an empty set. This appears to be a query optimizer issue where view merging incorrectly preserves semantics during JOIN operations.
How to repeat:
CREATE TABLE t0(c0 INT);
CREATE TABLE t1(c0 INT , c1 BOOLEAN);
INSERT INTO t0 VALUES (1), (2);
INSERT INTO t1 VALUES (1, FALSE);
CREATE VIEW v AS (
SELECT t0.c0 AS c0
FROM t0, t1
WHERE t0.c0 IN (SELECT c0 FROM t1 WHERE c1));
SELECT v.c0 FROM v;
-- empty set, correct
SELECT v.c0 FROM v RIGHT JOIN t1 ON TRUE;
-- 1, wrong, should be null
SELECT /*+ NO_MERGE(v) */ v.c0 FROM v RIGHT JOIN t1 ON TRUE;
-- NULL, correct