Unexpected Identical Results for Complementary Subquery Conditions in TiDB
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
## Bug Report
### 1. Minimal reproduce step (Required)
The following SQL statements create a test table and insert sample data:
```
DROP TABLE IF EXISTS `t1`;
CREATE TABLE `t1` (
`c1` int ,
`c2` int
);
INSERT INTO `t1` (`c1`, `c2`) VALUES
(NULL, NULL),
(-7, NULL);
```
Then, executing the following two queries produces the same results, which is unexpected:
Query 1:
```
select
ref_0.c2
from
t1 as ref_0
where ((ref_0.c2) in (
select
ref_1.c1 as c_0
from
t1 as ref_1
where (ref_0.c1) is not null))
and ((((ref_0.c1) in (select
1 as c_0
from
t1 as ref_2
))
or (true)))
```
Output:
+------+
| c2 |
+------+
| NULL |
| NULL |
+------+
2 rows in set (0.00 sec)
Query 2:
```
select
ref_0.c2
from
t1 as ref_0
where (not (((ref_0.c2) in (
select
ref_1.c1 as c_0
from
t1 as ref_1
where (ref_0.c1) is not null))
and ((((ref_0.c1) in (select
1 as c_0
from
t1 as ref_2
))
or (true)))))
or ((((ref_0.c2) in (
select
ref_1.c1 as c_0
from
t1 as ref_1
where (ref_0.c1) is not null))
and ((((ref_0.c1) in (select
1 as c_0
from
t1 as ref_2
))
or (true))))is null);
```
Output:
+------+
| c2 |
+------+
| NULL |
| NULL |
+------+
2 rows in set (0.00 sec)
### 2. What did you expect to see? (Required)
Since the second query negates the condition used in the first query (WHERE NOT X OR X IS NULL), the result set should be different
### 3. What did you see instead (Required)
Both queries return the same result set
### 4. What is your TiDB version? (Required)
8.0.11-TiDB
master b6141ec589ed8e73176692dc982a210ad7cf070b
GoVersion: go1.23.4
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
Contributor guide
Assessment
This issue has not been assessed yet.