Bug #111241 Wrong result of `IN` clause
Submitted: 1 Jun 2023 11:39 Modified: 1 Jun 2023 13:45
Reporter: chi zhang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:Last commit version in github https://gi OS:Any
Assigned to: CPU Architecture:Any
Tags: Logic bug

[1 Jun 2023 11:39] chi zhang
Description:
Consider the following program:
```
CREATE TABLE t0(c0 BOOL);
INSERT INTO t0 VALUES (true);

SELECT MIN(t0.c0) FROM t0 ;  # 1

SELECT t0.c0 FROM t0 WHERE (('0')NOT REGEXP((((t0.c0))NOT LIKE(CASE t0.c0 WHEN 76 THEN 0.7 ELSE t0.c0 END )))AND( t0.c0 IN ((1))));  # 1

SELECT t0.c0 FROM t0 WHERE (('0')NOT REGEXP((((t0.c0))NOT LIKE(CASE t0.c0 WHEN 76 THEN 0.7 ELSE t0.c0 END )))AND( t0.c0 IN (SELECT MIN(t0.c0) FROM t0 )));  # empty result
```
The first query return `1`, the second query is equivalent to the third one, because I just replace the `IN` clause from a concrete number to a subquery. So they should have the same results, but the second query return `1`, while the third query return an empty result.

I believe the second query generate a wrong result. Because `(('0')NOT REGEXP((((t0.c0))NOT LIKE(CASE t0.c0 WHEN 76 THEN 0.7 ELSE t0.c0 END ))))` should equal to false, so even `t0.c0 IN ((1))` equals to true, the whole condition should be false.

How to repeat:
I clone mysql source code from github https://github.com/mysql/mysql-server/commit/ea7087d885006918ad54458e7aad215b1650312c, and build it in ubuntu.

This is the configure command `cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/tmp/boost -DFORCE_INSOURCE_BUILD=ON`

Suggested fix:
The second and third queries should have the same results.
[1 Jun 2023 13:45] MySQL Verification Team
Hi Mr. zhang,

Thank you for your bug report.

We have tested your test case on the regular 8.0.33 and got the following results:

+------------+
| MIN(t0.c0) |
+------------+
|          1 |
+------------+
+------+
| c0   |
+------+
|    1 |
+------+

+------+
| c0   |
+------+
|    |
+------+

We agree with your logic and we are verifying your report.

Verified.