pingcap / pingcap/tidb

VIEW containing correlated subquery returns NULL

Open
#63,289 3 comments 0 reactions 1 assignee Claimed by @hawkingrei View on GitHub
contribution fuzz/sqlancer impact/wrong-result severity/major sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step (Required)
```sql
CREATE TABLE t1 (c1 INT);
CREATE TABLE t3 (c0 INT);
INSERT INTO t1 VALUES (10);
INSERT INTO t3 VALUES (9);

WITH vtable0 AS (
SELECT
(SELECT t1.c1 FROM t1 WHERE MOD(t1.c1, t3.c0 + 1) = 0) AS c1
FROM t3
JOIN t1 ON TRUE
)
SELECT vtable0.c1 FROM vtable0;

CREATE VIEW vtable0 AS (
SELECT
(SELECT t1.c1 FROM t1 WHERE MOD(t1.c1, t3.c0 + 1) = 0) AS c1
FROM t3
JOIN t1 ON TRUE
);

SELECT vtable0.c1 FROM vtable0;
```
### 2. What did you expect to see? (Required)
10 for the 2nd query, which MySQL output 10.
### 3. What did you see instead (Required)
```
+------+
| c1 |
+------+
| 10 |
+------+
```
```
+------+
| c1 |
+------+
| NULL |
+------+
```
### 4. What is your TiDB version? (Required)
```
tiup playground nightly --host 0.0.0.0 --kv 3 --tiflash 3
```
```
8.0.11-TiDB-v9.0.0-beta.2.pre-384-g5fab436
```

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.