pingcap / pingcap/tidb

Unexpected error `Unknown column 't1.c0' in 'where clause'`

Open
#43,569 0 comments 0 reactions 0 assignees View on GitHub
fuzz/sqlancer severity/minor 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)
The following program triggers this error, but actually `t1.c0` not in `where clause`:

```
CREATE TABLE t0(c0 CHAR);
CREATE TABLE t1(c0 CHAR);
SELECT COUNT(t1.c0) AS c0 FROM t0 NATURAL JOIN t1 WHERE 'Q'; -- Unknown column 't1.c0' in 'where clause'
```
I notice there are some other reports about this error message. For https://github.com/pingcap/tidb/issues/42732 and https://github.com/pingcap/tidb/issues/24324, the test case in this report does not contain subquery; for https://github.com/pingcap/tidb/issues/35031, I tried `SELECT COUNT(t1.c0) AS c0 FROM t0 NATURAL JOIN t1 WHERE t1.c0=1;` and do not return any error.
### 2. What did you expect to see? (Required)
No error.

### 3. What did you see instead (Required)
`Unknown column 't1.c0' in 'where clause'`

### 4. What is your TiDB version? (Required)
```
Release Version: v7.2.0-alpha-90-gb320fdca9\nEdition: Community\nGit Commit Hash: b320fdca9ff9dba02512b723908da3a8b2b82578\nGit Branch: master\nUTC Build Time: 2023-05-06 04:35:33\nGoVersion: go1.20.3\nRace Enabled: false\nTiKV Min Version: 6.2.0-alpha\nCheck Table Before Drop: false\nStore: 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.