pingcap / pingcap/tidb

Incorrect results of SELECT caused by JOIN table

Open
#42,821 5 comments 0 reactions 1 assignee Claimed by @winoros View on GitHub
may-affects-4.0 may-affects-5.0 may-affects-5.1 may-affects-5.2 may-affects-5.3 may-affects-5.4 may-affects-6.1 may-affects-6.5 severity/moderate sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

**Setup the environment:**

```
CREATE TABLE t4 (vkey int(11), c13 double);
INSERT INTO t4 VALUES (31,0);
CREATE TABLE t7 (vkey int(11), pkey int(11), c26 double, c27 int(11));
INSERT INTO t7 VALUES (29,164000,0,NULL);
```

**Testcase 1**
```
select 1 as c0
from
(t7 as ref_0
inner join (t7 as ref_1
right join t4 as ref_2
on (ref_1.vkey = ref_2.vkey ))
on (ref_0.c26 = ref_2.c13 ))
where not (not (
(nullif(ref_0.pkey, ref_1.c27) is not null) and false
));
```
Testcase 1 outputs 1 row.

```
+----+
| c0 |
+----+
| 1 |
+----+
1 row in set (0.00 sec)
```

Then, I replace `(nullif(ref_0.pkey, ref_1.c27) is not null) and false` with `false`. The results should not be changed because `anything and false` is `false`. The test case becomes:

**Testcase 2**
```
select 1 as c0
from
(t7 as ref_0
inner join (t7 as ref_1
right join t4 as ref_2
on (ref_1.vkey = ref_2.vkey ))
on (ref_0.c26 = ref_2.c13 ))
where not (not (
false
));
```

### 2. What did you expect to see? (Required)

Testcase 1 and Testcase 2 should output the same results.

### 3. What did you see instead (Required)

Testcase 2 outputs
```
Empty set (0.00 sec)
```
While Testcase 1 outputs:
```
+----+
| c0 |
+----+
| 1 |
+----+
1 row in set (0.00 sec)
```

### 4. What is your TiDB version? (Required)

+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.1.0-alpha-27-gf5ca27ef3
Edition: Community
Git Commit Hash: f5ca27ef326e94fb29b4ba35a5d59aa575f66880
Git Branch: master
UTC Build Time: 2023-03-23 13:57:53
GoVersion: go1.20.2
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.