pingcap/tidb

planner: warn if manual hints are overwritten by bindings

Open

Aperta il 21 mag 2026

Vedi su GitHub
 (4 commenti) (0 reazioni) (1 assegnatario)Go (40.090 star) (6186 fork)batch import
good first issuehelp wantedreport/customersig/plannertype/enhancement

Descrizione

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

Guida contributor