Wrong column value returned from 3-column covering index under Cascades Planner
- 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 database_t;
CREATE DATABASE database_t;
USE database_t;
CREATE TABLE idx_t1 (c0 INT NOT NULL, c4 DECIMAL(10,4), c7 INT NOT NULL);
INSERT INTO idx_t1(c0, c4, c7) VALUES (1, 1.0, 1);
CREATE INDEX cover_idx ON idx_t1 (c0, c4, c7);
-- [CORRECT] Result with cascades planner OFF
SET SESSION tidb_enable_cascades_planner=0;
SELECT '[CORRECT] cascades OFF' AS test, c7 FROM idx_t1 ORDER BY c0 LIMIT 1;
-- [BUG] Result with cascades planner ON
SET SESSION tidb_enable_cascades_planner=1;
SELECT '[BUG] cascades ON' AS test, c7 FROM idx_t1 ORDER BY c0 LIMIT 1;
```
### 2. What did you expect to see? (Required)
Both queries should return `c7 = 1`, which is the actual value stored in the table:
```
test c7
[CORRECT] cascades OFF 1
[BUG] cascades ON 1
```
### 3. What did you see instead (Required)
With cascades planner enabled, the query returns a garbage value for `c7`:
```
test c7
[CORRECT] cascades OFF 1
[BUG] cascades ON 4295230470
```
The cascades planner is reading from the wrong offset in the covering index, returning bytes that belong to the `c4` (DECIMAL) column instead of the `c7` (INT) column.
**Trigger conditions (all required):**
- A 3-column covering index containing columns of different types (INT + DECIMAL + INT). A 2-column or 1-column index does NOT trigger the bug.
- `ORDER BY` on the first index column
- `LIMIT` clause present (without LIMIT the result is correct)
- `tidb_enable_cascades_planner=1`
### 4. What is your TiDB version? (Required)
```
Release Version: v8.5.6
Edition: Community
Git Commit Hash: ae18096e023780bb56bfce33698abec0d4640d0a
Git Branch: HEAD
UTC Build Time: 2026-04-24 09:13:10
GoVersion: go1.25.8
Race Enabled: false
Check Table Before Drop: false
Store: unistore
Contributor guide
Assessment
This issue has not been assessed yet.