diff --git a/go.mod b/go.mod index 2a976ee72eca9..1530082711ce2 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( github.com/pingcap/goleveldb v0.0.0-20171020122428-b9ff6c35079e github.com/pingcap/kvproto v0.0.0-20190703131923-d9830856b531 github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 - github.com/pingcap/parser v0.0.0-20190828080649-a621a0f9b06c + github.com/pingcap/parser v0.0.0-20190912032624-978b8272c04e github.com/pingcap/pd v0.0.0-20190712044914-75a1f9f3062b github.com/pingcap/tidb-tools v2.1.3-0.20190321065848-1e8b48f5c168+incompatible github.com/pingcap/tipb v0.0.0-20190428032612-535e1abaa330 diff --git a/go.sum b/go.sum index 3d7d00ed95842..ec82908b95d89 100644 --- a/go.sum +++ b/go.sum @@ -167,8 +167,8 @@ github.com/pingcap/kvproto v0.0.0-20190703131923-d9830856b531/go.mod h1:QMdbTAXC github.com/pingcap/log v0.0.0-20190214045112-b37da76f67a7/go.mod h1:xsfkWVaFVV5B8e1K9seWfyJWFrIhbtUTAD8NV1Pq3+w= github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596 h1:t2OQTpPJnrPDGlvA+3FwJptMTt6MEPdzK1Wt99oaefQ= github.com/pingcap/log v0.0.0-20190307075452-bd41d9273596/go.mod h1:WpHUKhNZ18v116SvGrmjkA9CBhYmuUTKL+p8JC9ANEw= -github.com/pingcap/parser v0.0.0-20190828080649-a621a0f9b06c h1:VcQ60QkH7Vv98dbedNKDEO7RfUw+6TE59r/lQokNz/k= -github.com/pingcap/parser v0.0.0-20190828080649-a621a0f9b06c/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= +github.com/pingcap/parser v0.0.0-20190912032624-978b8272c04e h1:QeD1wC7bGElAhufSHH4JcIbs1cVdxnGWD3n3gcE5qeY= +github.com/pingcap/parser v0.0.0-20190912032624-978b8272c04e/go.mod h1:1FNvfp9+J0wvc4kl8eGNh7Rqrxveg15jJoWo/a0uHwA= github.com/pingcap/pd v0.0.0-20190712044914-75a1f9f3062b h1:oS9PftxQqgcRouKhhdaB52tXhVLEP7Ng3Qqsd6Z18iY= github.com/pingcap/pd v0.0.0-20190712044914-75a1f9f3062b/go.mod h1:3DlDlFT7EF64A1bmb/tulZb6wbPSagm5G4p1AlhaEDs= github.com/pingcap/tidb-tools v2.1.3-0.20190321065848-1e8b48f5c168+incompatible h1:MkWCxgZpJBgY2f4HtwWMMFzSBb3+JPzeJgF3VrXE/bU= diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index fe0a0a0658944..968ea44c6fdcb 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -64,8 +64,10 @@ const ( HintHashAgg = "hash_agg" // HintStreamAgg is hint enforce stream aggregation. HintStreamAgg = "stream_agg" - // HintIndex is hint enforce using some indexes. - HintIndex = "index" + // HintUseIndex is hint enforce using some indexes. + HintUseIndex = "use_index" + // HintIgnoreIndex is hint enforce ignoring some indexes. + HintIgnoreIndex = "ignore_index" // HintAggToCop is hint enforce pushing aggregation to coprocessor. HintAggToCop = "agg_to_cop" ) @@ -1967,7 +1969,7 @@ func (b *PlanBuilder) pushTableHints(hints []*ast.TableOptimizerHint, nodeType n aggHints.preferAggType |= preferStreamAgg case HintAggToCop: aggHints.preferAggToCop = true - case HintIndex: + case HintUseIndex: if len(hint.Tables) != 0 { indexHintList = append(indexHintList, indexHintInfo{ tblName: hint.Tables[0].TableName, @@ -1978,6 +1980,17 @@ func (b *PlanBuilder) pushTableHints(hints []*ast.TableOptimizerHint, nodeType n }, }) } + case HintIgnoreIndex: + if len(hint.Tables) != 0 { + indexHintList = append(indexHintList, indexHintInfo{ + tblName: hint.Tables[0].TableName, + indexHint: &ast.IndexHint{ + IndexNames: hint.Indexes, + HintType: ast.HintIgnore, + HintScope: ast.HintForScan, + }, + }) + } default: // ignore hints that not implemented } diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index d5a37c38dd2ba..c81efa55dc4e3 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -1687,20 +1687,20 @@ func (s *testPlanSuite) TestAggToCopHint(c *C) { warning string }{ { - sql: "select /*+ AGG_TO_COP(), HASH_AGG(), INDEX(t) */ sum(a) from t group by a", + sql: "select /*+ AGG_TO_COP(), HASH_AGG(), USE_INDEX(t) */ sum(a) from t group by a", best: "TableReader(Table(t)->HashAgg)->HashAgg", }, { - sql: "select /*+ AGG_TO_COP(), INDEX(t) */ sum(b) from t group by b", + sql: "select /*+ AGG_TO_COP(), USE_INDEX(t) */ sum(b) from t group by b", best: "TableReader(Table(t)->HashAgg)->HashAgg", }, { - sql: "select /*+ AGG_TO_COP(), HASH_AGG(), INDEX(t) */ distinct a from t group by a", + sql: "select /*+ AGG_TO_COP(), HASH_AGG(), USE_INDEX(t) */ distinct a from t group by a", best: "TableReader(Table(t)->HashAgg)->HashAgg->HashAgg", warning: "[planner:1815]Optimizer Hint AGG_TO_COP is inapplicable", }, { - sql: "select /*+ AGG_TO_COP(), HASH_AGG(), HASH_JOIN(t1), INDEX(t1), INDEX(t2) */ sum(t1.a) from t t1, t t2 where t1.a = t2.b group by t1.a", + sql: "select /*+ AGG_TO_COP(), HASH_AGG(), HASH_JOIN(t1), USE_INDEX(t1), USE_INDEX(t2) */ sum(t1.a) from t t1, t t2 where t1.a = t2.b group by t1.a", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.b)->Projection->HashAgg", warning: "[planner:1815]Optimizer Hint AGG_TO_COP is inapplicable", }, @@ -1836,7 +1836,9 @@ func (s *testPlanSuite) TestIndexHint(c *C) { ctx := context.Background() for i, test := range tests { comment := Commentf("case:%v sql:%s", i, test) - stmt, err := s.ParseOneStmt(test.sql, "", "") + se.GetSessionVars().StmtCtx.SetWarnings(nil) + + stmt, err := s.ParseOneStmt(test, "", "") c.Assert(err, IsNil, comment) p, err := planner.Optimize(ctx, se, stmt, s.is)