Planner fails with "Can't find column gid in schema" on a valid query over GROUPING/ROLLUP view
- Dominant language
- Go
- Stars
- 40.5k
- Forks
- 6.2k
- PR merge metrics
- PR metrics pending
Description
---
name: "🐛 Bug Report"
about: As a User, I want to report a Bug.
labels: type/bug
---
## Bug Report
Please answer these questions before submitting your issue. Thanks!
### 1. Minimal reproduce step (Required)
This issue comes from a minimized Shiro repro bundle:
- report directory: `reports/case_0004_019d1567-28c8-7aaa-a63b-3e38558c38bd`
- oracle: `EET`
- rewrite: `and_true`
- minimize status: `success`
- flaky: `false`
Repro steps:
1. Apply the schema from the attached `schema.sql`.
2. Load the data from the attached `inserts.sql`.
3. Run the query below from `case.sql`.
4. Observe that TiDB fails with `Error 1105 (HY000): Can't find column gid in schema`.
5. If needed, use the attached `plan_replayer.zip` from the same Shiro case.
Repro artifacts
- `schema.sql`
- `inserts.sql`
- `case.sql`
- `plan_replayer.zip`
Query
```sql
SELECT DISTINCT COUNT(1) AS cnt, SUM(t0.c5) AS sum1
FROM t0
JOIN t4 ON (1 = 0)
RIGHT JOIN t1 ON (1 = 0)
WHERE NOT EXISTS (
SELECT v1.g1 AS c0
FROM v1
WHERE ((v1.sum1 < v1.g0) OR (v1.sum1 < v1.cnt))
ORDER BY v1.g1, v1.grp_flag, v1.g0
LIMIT 3
);
```
### 2. What did you expect to see? (Required)
The query should execute successfully.
It is valid SQL over schema objects created by `schema.sql`, including view `v1`. The presence of `GROUPING(...)`, `WITH ROLLUP`, and ordering on view columns should not trigger an internal missing-column failure.
### 3. What did you see instead (Required)
TiDB fails with:
```text
Error 1105 (HY000): Can't find column gid in schema Column: [Column#38,Column#39,Column#43] PKOrUK: [] NullableUK: []
```
This is also captured in the attached `plan_replayer.zip` bundle.
### 4. What is your TiDB version? (Required)
```text
Release Version: v9.0.0-beta.2.pre-1419-gb75374faa6
Edition: Community
Git Commit Hash: b75374faa619e24e380292fdbdf0f6fe5bf11943
Git Branch: HEAD
UTC Build Time: 2026-03-20 15:42:42
GoVersion: go1.25.8
Race Enabled: false
Check Table Before Drop: false
Store: tikv
Kernel Type: Classic
```
## Analysis
1. The failure points to internal column `gid`, which strongly suggests a GROUPING/ROLLUP schema propagation bug rather than invalid user SQL.
2. The query reads from view `v1`, and `v1` itself contains `GROUPING(t1.id) AS grp_flag` with `WITH ROLLUP`. A likely failure mode is that the planner expands or resolves the view without preserving the synthetic grouping identifier required later by `GROUPING` / `ORDER BY`.
3. Because the error is `Can't find column gid in schema`, the issue appears to be in planner/schema resolution around grouping-set internal columns, possibly across a view boundary.
Contributor guide
Assessment
This issue has not been assessed yet.