pingcap/tidb

planner: warn if manual hints are overwritten by bindings

Closed

#68.550 aberto em 21 de mai. de 2026

Ver no GitHub
 (4 comments) (0 reactions) (1 assignee)Go (6.186 forks)batch import
good first issuehelp wantedreport/customersig/plannertype/enhancement

Métricas do repositório

Stars
 (40.090 stars)
Métricas de merge de PR
 (Mesclagem média 14d 4h) (346 fundiu PRs em 30d)

Description

Enhancement

In the example below, the user wants to use a hint to force the optimizer to use index b, but it's still using index a, since a binding overwrites the hint. We should warn in this scenario to avoid confusing users.

mysql> create table t (a int, b int, key(a), key(b));
Query OK, 0 rows affected (0.016 sec)

mysql> create global binding using select /*+ use_index(t, a) */ * from t where a=1 and b=1;                                                                                                                                   
Query OK, 0 rows affected (0.006 sec)

mysql> explain select /*+ use_index(t, b) */ * from t where a=1 and b=1;
+-------------------------------+---------+-----------+---------------------+---------------------------------------------+
| id                            | estRows | task      | access object       | operator info                               |
+-------------------------------+---------+-----------+---------------------+---------------------------------------------+
| IndexLookUp_8                 | 0.01    | root      |                     |                                             |
| ├─IndexRangeScan_5(Build)     | 10.00   | cop[tikv] | table:t, index:a(a) | range:[1,1], keep order:false, stats:pseudo |
| └─Selection_7(Probe)          | 0.01    | cop[tikv] |                     | eq(test.t.b, 1)                             |
|   └─TableRowIDScan_6          | 10.00   | cop[tikv] | table:t             | keep order:false, stats:pseudo              |
+-------------------------------+---------+-----------+---------------------+---------------------------------------------+

Guia do colaborador