Bug #121419 `IN (SELECT NULL WHERE tautology) IS TRUE` returns NULL instead of 0

Submitted: 1 Oct 18:25 Modified: 5 Oct 8:34
Reporter: jinxin gui Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.46, 8.4.11, 9.7.2, 26.07 OS:Linux
Assigned to: CPU Architecture:Any
Tags: IN clause, OR

[1 Oct 18:25] jinxin gui
Description:
Adding an always-true `WHERE` condition to a tableless subquery changes the value returned by `IS TRUE`. Both subqueries below return one row containing `NULL`, so the two queries should produce the same result. 

How to repeat:
```sql
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (id INT);
INSERT INTO t1 VALUES (1), (2), (3), (4), (5);
ANALYZE TABLE t1;

SELECT id, id IN (SELECT NULL) IS TRUE AS result
FROM t1;

SELECT id, id IN (SELECT NULL WHERE TRUE) IS TRUE AS result
FROM t1;
```

Actual result:

The first query returns `result = 0` for all five IDs. The second query returns `result = NULL` for all five IDs.

Expected result:

The second query should also return `result = 0` for all five IDs. Its `WHERE` condition is true, so its subquery still returns one `NULL`. For a non-NULL `id`, the `IN` expression is `NULL`, and `NULL IS TRUE` is `0`.
[5 Oct 8:34] Chaithra Marsur Gopala Reddy
Hi jinxin gui,

Thanks for the test case. Verified as described.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.038 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.