planner: hints for index merge should check the DB name for a table (#16519)
This commit is contained in:
committed by
GitHub
parent
cd362cae72
commit
76b910edd1
@ -2704,7 +2704,7 @@ func (b *PlanBuilder) buildDataSource(ctx context.Context, tn *ast.TableName, as
|
||||
var indexMergeHints []*ast.IndexHint
|
||||
if hints := b.TableHints(); hints != nil {
|
||||
for i, hint := range hints.indexMergeHintList {
|
||||
if hint.tblName.L == tblName.L {
|
||||
if hint.tblName.L == tblName.L && hint.dbName.L == dbName.L {
|
||||
hints.indexMergeHintList[i].matched = true
|
||||
// check whether the index names in IndexMergeHint are valid.
|
||||
invalidIdxNames := make([]string, 0, len(hint.indexHint.IndexNames))
|
||||
|
||||
4
planner/core/testdata/plan_suite_in.json
vendored
4
planner/core/testdata/plan_suite_in.json
vendored
@ -60,7 +60,9 @@
|
||||
"select /*+ NO_INDEX_MERGE(), USE_INDEX_MERGE(t, primary, f_g, c_d_e) */ * from t where a < 1 or f > 2",
|
||||
"select /*+ USE_INDEX_MERGE(t1, c_d_e, f_g) */ * from t where c < 1 or f > 2",
|
||||
"select /*+ NO_INDEX_MERGE(), USE_INDEX_MERGE(t, primary, f_g, c_d_e) */ * from t where a < 1 or f > 2",
|
||||
"select /*+ USE_INDEX_MERGE(t) USE_INDEX_MERGE(t) */ * from t where c < 1 or f > 2"
|
||||
"select /*+ USE_INDEX_MERGE(t) USE_INDEX_MERGE(t) */ * from t where c < 1 or f > 2",
|
||||
"select /*+ USE_INDEX_MERGE(db2.t) */ * from t where c < 1 or f > 2",
|
||||
"select /*+ USE_INDEX_MERGE(db2.t, c_d_e, f_g) */ * from t where c < 1 or f > 2"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
12
planner/core/testdata/plan_suite_out.json
vendored
12
planner/core/testdata/plan_suite_out.json
vendored
@ -229,6 +229,18 @@
|
||||
"Best": "IndexMergeReader(PartialPlans->[Index(t.c_d_e)[[-inf,1)], Index(t.f_g)[(2,+inf]]], TablePlan->Table(t))",
|
||||
"HasWarn": false,
|
||||
"Hints": "use_index_merge(@`sel_1` `t` `c_d_e`, `f_g`)"
|
||||
},
|
||||
{
|
||||
"SQL": "select /*+ USE_INDEX_MERGE(db2.t) */ * from t where c < 1 or f > 2",
|
||||
"Best": "TableReader(Table(t)->Sel([or(lt(test.t.c, 1), gt(test.t.f, 2))]))",
|
||||
"HasWarn": true,
|
||||
"Hints": "use_index(@`sel_1` `test`.`t` )"
|
||||
},
|
||||
{
|
||||
"SQL": "select /*+ USE_INDEX_MERGE(db2.t, c_d_e, f_g) */ * from t where c < 1 or f > 2",
|
||||
"Best": "TableReader(Table(t)->Sel([or(lt(test.t.c, 1), gt(test.t.f, 2))]))",
|
||||
"HasWarn": true,
|
||||
"Hints": "use_index(@`sel_1` `test`.`t` )"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user