planner: hints for index merge should check the DB name for a table (#16519)

This commit is contained in:
Zhuomin(Charming) Liu
2020-04-29 15:46:56 +08:00
committed by GitHub
parent cd362cae72
commit 76b910edd1
3 changed files with 16 additions and 2 deletions

View File

@ -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))

View File

@ -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"
]
},
{

View File

@ -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` )"
}
]
},