pingcap / pingcap/tidb

output column is incorrect when user explicitly quries `_tidb_rowid` in the SQL

Open
#64,922 0 comments 0 reactions 1 assignee Claimed by @time-and-fate View on GitHub
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)

Case 1

```sql
create table t(a int, b int);
insert into t value (1,1);
select *, _tidb_rowid from t;
select * from (select *, _tidb_rowid from t) n;
```

Case 2

```sql
create table t1(a int, b int);
create table t2(aa int, bb int);
explain select * from (select _tidb_rowid from t1) n1 natural join (select _tidb_rowid from t2) n2;
explain select * from (select _tidb_rowid, a from t1) n1 natural join (select _tidb_rowid, aa from t2) n2;
```

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

Case 1

The last 2 SQL have the same output.

Case 2

No error.

The join condition from the natural join should include `_tidb_rowid`.

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

Case 1

```
> select *, _tidb_rowid from t;
+------+------+-------------+
| a | b | _tidb_rowid |
+------+------+-------------+
| 1 | 1 | 1 |
+------+------+-------------+

> select * from (select *, _tidb_rowid from t) n;
+------+------+
| a | b |
+------+------+
| 1 | 1 |
+------+------+
```

Case 2

```
> explain select * from (select _tidb_rowid from t1) n1 natural join (select _tidb_rowid from t2) n2;
ERROR 1051 (42S02): Unknown table ''

> explain select * from (select _tidb_rowid, a from t1) n1 natural join (select _tidb_rowid, aa from t2) n2;
+-----------------------------+--------------+-----------+---------------+--------------------------------+
| id | estRows | task | access object | operator info |
+-----------------------------+--------------+-----------+---------------+--------------------------------+
| HashJoin_23 | 100000000.00 | root | | CARTESIAN inner join |
| ├─TableReader_28(Build) | 10000.00 | root | | data:TableFullScan_27 |
| │ └─TableFullScan_27 | 10000.00 | cop[tikv] | table:t2 | keep order:false, stats:pseudo |
| └─TableReader_26(Probe) | 10000.00 | root | | data:TableFullScan_25 |
| └─TableFullScan_25 | 10000.00 | cop[tikv] | table:t1 | keep order:false, stats:pseudo |
+-----------------------------+--------------+-----------+---------------+--------------------------------+

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

nightly

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.