pingcap / pingcap/tidb

Unexpected error in `ORDER BY`

Open
#42,941 1 comment 0 reactions 1 assignee Claimed by @AilinKid 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

### 1. Minimal reproduce step (Required)

The following program triggers an error
```
CREATE TABLE t0(c0 DECIMAL, c1 FLOAT, c2 DOUBLE);
CREATE TABLE t1 LIKE t0;
SELECT t1.c1 AS c0 FROM t0 NATURAL LEFT JOIN t1 WHERE t0.c2 ORDER BY (CASE (CASE NULL WHEN t1.c1 THEN t0.c1 ELSE DEFAULT(t1.c0) END ) WHEN t1.c0 THEN 1 ELSE t0.c2 END );
```

This is the error message:
```
ERROR 1052 (23000) at line 8: Column 't1.c0' in field list is ambiguous
```

But I run this query in MySQL, it can run normally. https://www.db-fiddle.com/f/bE5V1Nx1CjEPSzt6Cucs8B/0

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

No error.

### 3. What did you see instead (Required)
```
ERROR 1052 (23000) at line 8: Column 't1.c0' in field list is ambiguous
```

### 4. What is your TiDB version? (Required)
```
Release Version: v7.1.0-alpha-162-gc233969b2
Edition: Community
Git Commit Hash: c233969b2c385b4292a7caaf16517dd8b152d7f1
Git Branch: master
UTC Build Time: 2023-04-11 03:01:14
GoVersion: go1.20.3
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.