pingcap / pingcap/tidb

Limit operator fails to resolve columns from non-covering index scan under cascades planner

Open
#68,428 2 comments 0 reactions 0 assignees View on GitHub
contribution severity/moderate 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
DROP DATABASE IF EXISTS db73_test;
CREATE DATABASE db73_test;
USE db73_test;

-- Setup: a simple table with PK + one additional column, and a secondary index
CREATE TABLE t(c0 INT PRIMARY KEY, c1 INT);
CREATE INDEX i ON t (c1);

-- Step 1: Normal query (without Cascades Planner) — works fine, returns empty set
SELECT * FROM t ORDER BY c1 LIMIT 1;

-- Step 2: Enable Cascades Planner, then run the same query — triggers the error
SET SESSION tidb_enable_cascades_planner=1;
SELECT * FROM t ORDER BY c1 LIMIT 1;
```

### 2. What did you expect to see? (Required)
The query `SELECT * FROM t ORDER BY c1 LIMIT 1;` should return `Empty set (0.00 sec)`, the same result as when the Cascades Planner is not enabled. Enabling the Cascades Planner should not cause an error for such a basic query.
### 3. What did you see instead (Required)
When `tidb_enable_cascades_planner=1` is set, executing `SELECT * FROM t ORDER BY c1 LIMIT 1;` fails with the following error:

```
ERROR 1105 (HY000): Some columns of Limit_20 cannot find the reference from its child(ren)
```

This is an internal planner error indicating the Cascades optimizer fails to correctly resolve column references when building the Limit operator on top of a non-covering secondary index scan with ORDER BY.
### 4. What is your TiDB version? (Required)

v8.5.6

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.