pingcap/tidb

planner: warn if manual hints are overwritten by bindings

Closed

#68 550 ouverte le 21 mai 2026

Voir sur GitHub
 (4 commentaires) (0 réactions) (1 assigné)Go (6 186 forks)batch import
good first issuehelp wantedreport/customersig/plannertype/enhancement

Métriques du dépôt

Stars
 (40 090 stars)
Métriques de merge PR
 (Merge moyen 14j 4h) (346 PRs mergées en 30 j)

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              |
+-------------------------------+---------+-----------+---------------------+---------------------------------------------+

Guide contributeur