pingcap / pingcap/tidb

[planner] unused view QB_NAME warning is lost when alternative logical plans are enabled

Open
#69,908 2 comments 0 reactions 0 assignees 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

### 1. Minimal reproduce step (Required)

```sql
CREATE DATABASE IF NOT EXISTS tidb_issue_68646;
USE tidb_issue_68646;

DROP VIEW IF EXISTS v68646;
DROP TABLE IF EXISTS t68646;

CREATE TABLE t68646 (a INT);
INSERT INTO t68646 VALUES (1);
CREATE VIEW v68646 AS SELECT a FROM t68646;

-- Baseline: alternative logical plans disabled
SET SESSION tidb_opt_enable_alternative_logical_plans = OFF;
SELECT /*+ QB_NAME(qb_bad, v_not_exist) */ * FROM v68646;
SHOW WARNINGS;

-- Reproduce: alternative logical plans enabled
SET SESSION tidb_opt_enable_alternative_logical_plans = ON;
SELECT /*+ QB_NAME(qb_bad, v_not_exist) */ * FROM v68646;
SHOW WARNINGS;
```

The same session should be used for both cases. The view table in the `QB_NAME` hint is intentionally incorrect so that the view hint is unused.

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

Enabling `tidb_opt_enable_alternative_logical_plans` may change the selected execution plan, but it should not change whether an unused view `QB_NAME` hint is reported.

Both executions should return the row `1` and report:

```text
Warning 1815 The qb_name hint qb_bad is unused, please check whether the table list in the qb_name hint qb_bad is correct
```

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

With `tidb_opt_enable_alternative_logical_plans = OFF`, the warning is reported. With it set to `ON`, the query still returns `1`, but `SHOW WARNINGS` is empty.

This is a warning regression: the query result is unchanged, but users lose the diagnostic that the view hint did not take effect.

The suspected cause is that `builder.HandleUnusedViewHints()` is deferred until after the winner logical-plan context is snapshotted, and the final winner-context restore rolls the warning back. This behavior was introduced by the alternative logical plan work in [#68646](https://github.com/pingcap/tidb/pull/68646), which is related to the tracking issue [#66676](https://github.com/pingcap/tidb/issues/66676).

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

The source path was reviewed on `origin/master` at `9fed09dc9d58478054796577cb7aaea71410b455` (2026-07-17). The SQL reproduction was also verified with a local source build using unistore; its `SELECT tidb_version()` output is:

```text
Release Version: v8.4.0-this-is-a-placeholder
Edition: Community
Git Commit Hash: None
Git Branch: None
UTC Build Time: None
GoVersion: go1.25.10
Race Enabled: false
Check Table Before Drop: false
Store: unistore
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing planner handling around builder.HandleUnusedViewHints() and the alternative logical-plan winner-context snapshot and restore described in the issue. Run the provided SQL reproduction with alternative logical plans both OFF and ON, then verify that both executions return 1 and report the unused QB_NAME warning through SHOW WARNINGS.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.