From d7628f28241acc9117e247b45cf78c7b527fb15a Mon Sep 17 00:00:00 2001 From: foreyes Date: Thu, 8 Aug 2019 11:13:02 +0800 Subject: [PATCH 01/10] rename --- planner/core/exhaust_physical_plans.go | 2 +- planner/core/logical_plan_builder.go | 24 +++++++++++++++--------- planner/core/physical_plan_test.go | 14 +++++++------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index ab94db70d850b..e2d68f56b6249 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -1329,7 +1329,7 @@ func (la *LogicalAggregation) exhaustPhysicalPlans(prop *property.PhysicalProper } if streamAggs == nil && preferStream { - errMsg := "Optimizer Hint TIDB_STREAMAGG is inapplicable" + errMsg := "Optimizer Hint STREAM_AGG is inapplicable" warning := ErrInternal.GenWithStack(errMsg) la.ctx.GetSessionVars().StmtCtx.AppendWarning(warning) } diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 0b671e6ee70a2..fa25160ea67bd 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -50,14 +50,20 @@ import ( const ( // TiDBMergeJoin is hint enforce merge join. TiDBMergeJoin = "tidb_smj" + // HintSMJ is hint enforce merge join. + HintSMJ = "sm_join" // TiDBIndexNestedLoopJoin is hint enforce index nested loop join. TiDBIndexNestedLoopJoin = "tidb_inlj" + // HintINLJ is hint enforce index nested loop join. + HintINLJ = "inl_join" // TiDBHashJoin is hint enforce hash join. TiDBHashJoin = "tidb_hj" - // TiDBHashAgg is hint enforce hash aggregation. - TiDBHashAgg = "tidb_hashagg" - // TiDBStreamAgg is hint enforce stream aggregation. - TiDBStreamAgg = "tidb_streamagg" + // HintHJoin is hint enforce hash join. + HintHJ = "hash_join" + // HintHashAgg is hint enforce hash aggregation. + HintHashAgg = "hash_agg" + // HintStreamAgg is hint enforce stream aggregation. + HintStreamAgg = "stream_agg" ) const ( @@ -1941,15 +1947,15 @@ func (b *PlanBuilder) pushTableHints(hints []*ast.TableOptimizerHint) { var preferAggType uint for _, hint := range hints { switch hint.HintName.L { - case TiDBMergeJoin: + case TiDBMergeJoin, HintSMJ: sortMergeTables = tableNames2HintTableInfo(hint.Tables) - case TiDBIndexNestedLoopJoin: + case TiDBIndexNestedLoopJoin, HintINLJ: INLJTables = tableNames2HintTableInfo(hint.Tables) - case TiDBHashJoin: + case TiDBHashJoin, HintHJ: hashJoinTables = tableNames2HintTableInfo(hint.Tables) - case TiDBHashAgg: + case HintHashAgg: preferAggType |= preferHashAgg - case TiDBStreamAgg: + case HintStreamAgg: preferAggType |= preferStreamAgg default: // ignore hints that not implemented diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index 22bddc2b88b0f..b0d914e914e47 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -1616,18 +1616,18 @@ func (s *testPlanSuite) TestAggregationHints(c *C) { }, // with Aggregation hints { - sql: "select /*+ TIDB_HASHAGG() */ count(*) from t t1, t t2 where t1.a = t2.b", + sql: "select /*+ HASH_AGG */ count(*) from t t1, t t2 where t1.a = t2.b", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.b)->HashAgg", warning: "", }, { - sql: "select /*+ TIDB_STREAMAGG() */ count(t1.a) from t t1, t t2 where t1.a = t2.a*2 group by t1.a", + sql: "select /*+ STREAM_AGG */ count(t1.a) from t t1, t t2 where t1.a = t2.a*2 group by t1.a", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))->Projection}(test.t1.a,mul(test.t2.a, 2))->Sort->StreamAgg", warning: "", }, // test conflict warning { - sql: "select /*+ TIDB_HASHAGG() TIDB_STREAMAGG() */ count(*) from t t1, t t2 where t1.a = t2.b", + sql: "select /*+ HASH_AGG STREAM_AGG */ count(*) from t t1, t t2 where t1.a = t2.b", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.b)->StreamAgg", warning: "[planner:1815]Optimizer aggregation hints are conflicted", }, @@ -1709,19 +1709,19 @@ func (s *testPlanSuite) TestHintScope(c *C) { }, // aggregation hints { - sql: "select /*+ TIDB_STREAMAGG() */ s, count(s) from (select /*+ TIDB_HASHAGG() */ sum(t1.a) as s from t t1, t t2 where t1.a = t2.b group by t1.a) p group by s", + sql: "select /*+ STREAM_AGG */ s, count(s) from (select /*+ HASH_AGG */ sum(t1.a) as s from t t1, t t2 where t1.a = t2.b group by t1.a) p group by s", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.b)->Projection->HashAgg->Sort->StreamAgg->Projection", }, { - sql: "select /*+ TIDB_HASHAGG() */ s, count(s) from (select /*+ TIDB_STREAMAGG() */ sum(t1.a) as s from t t1, t t2 where t1.a = t2.b group by t1.a) p group by s", + sql: "select /*+ HASH_AGG */ s, count(s) from (select /*+ STREAM_AGG */ sum(t1.a) as s from t t1, t t2 where t1.a = t2.b group by t1.a) p group by s", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.b)->Sort->Projection->StreamAgg->HashAgg->Projection", }, { - sql: "select /*+ TIDB_HASHAGG() */ s, count(s) from (select sum(t1.a) as s from t t1, t t2 where t1.a = t2.b group by t1.a) p group by s", + sql: "select /*+ HASH_AGG */ s, count(s) from (select sum(t1.a) as s from t t1, t t2 where t1.a = t2.b group by t1.a) p group by s", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.b)->Projection->HashAgg->HashAgg->Projection", }, { - sql: "select /*+ TIDB_STREAMAGG() */ s, count(s) from (select sum(t1.a) as s from t t1, t t2 where t1.a = t2.b group by t1.a) p group by s", + sql: "select /*+ STREAM_AGG */ s, count(s) from (select sum(t1.a) as s from t t1, t t2 where t1.a = t2.b group by t1.a) p group by s", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.a,test.t2.b)->Projection->HashAgg->Sort->StreamAgg->Projection", }, } From d668790c096c79e18ab2194cb4c88ddbcfaa2d62 Mon Sep 17 00:00:00 2001 From: foreyes Date: Thu, 8 Aug 2019 12:20:14 +0800 Subject: [PATCH 02/10] update parser --- go.mod | 2 ++ go.sum | 4 ++-- planner/core/logical_plan_builder.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 0a373f0dc22d6..59fd9816f46ab 100644 --- a/go.mod +++ b/go.mod @@ -75,3 +75,5 @@ require ( sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4 sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) + +replace github.com/pingcap/parser => github.com/foreyes/parser v0.0.0-20190808032107-76c8f0780623 diff --git a/go.sum b/go.sum index b4170e6ca9006..60e3459646768 100644 --- a/go.sum +++ b/go.sum @@ -47,6 +47,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/foreyes/parser v0.0.0-20190808032107-76c8f0780623 h1:GEisnO2MAUPOXT0D+cBds14WgbYVxq/VHJ+Ta2l78u0= +github.com/foreyes/parser v0.0.0-20190808032107-76c8f0780623/go.mod h1:3lbW3qHt81o5eguDSsve9wLN8OtUzvdZrVQ/pngnIg0= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew= @@ -165,8 +167,6 @@ 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-20190805112544-2b054e14336b h1:CAfB8gFHcyyNUEVBqv/L8uNGfCWnJGhxAXqApAk5ICA= -github.com/pingcap/parser v0.0.0-20190805112544-2b054e14336b/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 fa25160ea67bd..1f166731e462f 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -58,7 +58,7 @@ const ( HintINLJ = "inl_join" // TiDBHashJoin is hint enforce hash join. TiDBHashJoin = "tidb_hj" - // HintHJoin is hint enforce hash join. + // HintHJ is hint enforce hash join. HintHJ = "hash_join" // HintHashAgg is hint enforce hash aggregation. HintHashAgg = "hash_agg" From 9f486151a20203c16f91c8fb2ae60251cb49247e Mon Sep 17 00:00:00 2001 From: foreyes Date: Thu, 8 Aug 2019 14:08:54 +0800 Subject: [PATCH 03/10] add tests --- planner/core/physical_plan_test.go | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index b0d914e914e47..faa73f9925d7e 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -1740,3 +1740,50 @@ func (s *testPlanSuite) TestHintScope(c *C) { c.Assert(warnings, HasLen, 0, comment) } } + +func (s *testPlanSuite) TestHintAlias(c *C) { + defer testleak.AfterTest(c)() + store, dom, err := newStoreWithBootstrap() + c.Assert(err, IsNil) + defer func() { + dom.Close() + store.Close() + }() + se, err := session.CreateSession4Test(store) + c.Assert(err, IsNil) + _, err = se.Execute(context.Background(), "use test") + c.Assert(err, IsNil) + + tests := []struct { + sql1 string + sql2 string + }{ + { + sql1: "select /*+ TIDB_SMJ(t1) */ t1.a, t1.b from t t1, (select /*+ TIDB_INLJ(t3) */ t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", + sql2: "select /*+ SM_JOIN(t1) */ t1.a, t1.b from t t1, (select /*+ INL_JOIN(t3) */ t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", + }, + { + sql1: "select /*+ TIDB_HJ(t1) */ t1.a, t1.b from t t1, (select /*+ TIDB_SMJ(t2) */ t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", + sql2: "select /*+ HASH_JOIN(t1) */ t1.a, t1.b from t t1, (select /*+ SM_JOIN(t2) */ t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", + }, + { + sql1: "select /*+ TIDB_INLJ(t1) */ t1.a, t1.b from t t1, (select /*+ TIDB_HJ(t2) */ t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", + sql2: "select /*+ INL_JOIN(t1) */ t1.a, t1.b from t t1, (select /*+ HASH_JOIN(t2) */ t2.a from t t2, t t3 where t2.a = t3.c) s where t1.a=s.a", + }, + } + ctx := context.TODO() + for i, tt := range tests { + comment := Commentf("case:%v sql1:%s sql2:%s", i, tt.sql1, tt.sql2) + stmt1, err := s.ParseOneStmt(tt.sql1, "", "") + c.Assert(err, IsNil, comment) + stmt2, err := s.ParseOneStmt(tt.sql2, "", "") + c.Assert(err, IsNil, comment) + + p1, err := planner.Optimize(ctx, se, stmt1, s.is) + c.Assert(err, IsNil) + p2, err := planner.Optimize(ctx, se, stmt2, s.is) + c.Assert(err, IsNil) + + c.Assert(core.ToString(p1), Equals, core.ToString(p2)) + } +} From 3a13e472397e69d2ffd23511744f5e3a8420f32f Mon Sep 17 00:00:00 2001 From: foreyes Date: Thu, 8 Aug 2019 16:21:15 +0800 Subject: [PATCH 04/10] update parser --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 59fd9816f46ab..141bf6f4d0316 100644 --- a/go.mod +++ b/go.mod @@ -76,4 +76,4 @@ require ( sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) -replace github.com/pingcap/parser => github.com/foreyes/parser v0.0.0-20190808032107-76c8f0780623 +replace github.com/pingcap/parser => github.com/foreyes/parser v0.0.0-20190808081829-554c38302868 diff --git a/go.sum b/go.sum index 60e3459646768..e004efe712f51 100644 --- a/go.sum +++ b/go.sum @@ -47,8 +47,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/foreyes/parser v0.0.0-20190808032107-76c8f0780623 h1:GEisnO2MAUPOXT0D+cBds14WgbYVxq/VHJ+Ta2l78u0= -github.com/foreyes/parser v0.0.0-20190808032107-76c8f0780623/go.mod h1:3lbW3qHt81o5eguDSsve9wLN8OtUzvdZrVQ/pngnIg0= +github.com/foreyes/parser v0.0.0-20190808081829-554c38302868 h1:0NCpYx5gkfsCBOq3W1125IpzJvJLEDngodN/oYLIP3E= +github.com/foreyes/parser v0.0.0-20190808081829-554c38302868/go.mod h1:3lbW3qHt81o5eguDSsve9wLN8OtUzvdZrVQ/pngnIg0= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew= From f69753e9dc8643c748a2629af373dee5dd38b451 Mon Sep 17 00:00:00 2001 From: foreyes Date: Tue, 13 Aug 2019 14:50:55 +0800 Subject: [PATCH 05/10] small change & update parser --- go.mod | 2 +- go.sum | 4 ++-- planner/core/exhaust_physical_plans.go | 4 ++-- planner/core/logical_plan_builder.go | 6 +++--- planner/core/physical_plan_test.go | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 141bf6f4d0316..bcc317dbfa6a0 100644 --- a/go.mod +++ b/go.mod @@ -76,4 +76,4 @@ require ( sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) -replace github.com/pingcap/parser => github.com/foreyes/parser v0.0.0-20190808081829-554c38302868 +replace github.com/pingcap/parser => github.com/foreyes/parser v0.0.0-20190813063912-8bb2126c1499 diff --git a/go.sum b/go.sum index e004efe712f51..bb8dae99c7e39 100644 --- a/go.sum +++ b/go.sum @@ -47,8 +47,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/foreyes/parser v0.0.0-20190808081829-554c38302868 h1:0NCpYx5gkfsCBOq3W1125IpzJvJLEDngodN/oYLIP3E= -github.com/foreyes/parser v0.0.0-20190808081829-554c38302868/go.mod h1:3lbW3qHt81o5eguDSsve9wLN8OtUzvdZrVQ/pngnIg0= +github.com/foreyes/parser v0.0.0-20190813063912-8bb2126c1499 h1:s6EoP5pzlkTvs6oLenAb5lApcqe2nQr2EA3kL5soDX4= +github.com/foreyes/parser v0.0.0-20190813063912-8bb2126c1499/go.mod h1:3lbW3qHt81o5eguDSsve9wLN8OtUzvdZrVQ/pngnIg0= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew= diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index e2d68f56b6249..d3b4400e9a909 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -1005,9 +1005,9 @@ func (p *LogicalJoin) tryToGetIndexJoin(prop *property.PhysicalProperty) (indexJ defer func() { if !forced && hasIndexJoinHint { // Construct warning message prefix. - errMsg := "Optimizer Hint TIDB_INLJ is inapplicable" + errMsg := "Optimizer Hint INL_JOIN is inapplicable" if p.hintInfo != nil { - errMsg = fmt.Sprintf("Optimizer Hint %s is inapplicable", restore2JoinHint(TiDBIndexNestedLoopJoin, p.hintInfo.indexNestedLoopJoinTables)) + errMsg = fmt.Sprintf("Optimizer Hint %s is inapplicable", restore2JoinHint(HintINLJ, p.hintInfo.indexNestedLoopJoinTables)) } // Append inapplicable reason. diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index 1f166731e462f..ba1fbce55018e 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1971,9 +1971,9 @@ func (b *PlanBuilder) pushTableHints(hints []*ast.TableOptimizerHint) { func (b *PlanBuilder) popTableHints() { hintInfo := b.tableHintInfo[len(b.tableHintInfo)-1] - b.appendUnmatchedJoinHintWarning(TiDBIndexNestedLoopJoin, hintInfo.indexNestedLoopJoinTables) - b.appendUnmatchedJoinHintWarning(TiDBMergeJoin, hintInfo.sortMergeJoinTables) - b.appendUnmatchedJoinHintWarning(TiDBHashJoin, hintInfo.hashJoinTables) + b.appendUnmatchedJoinHintWarning(HintINLJ, hintInfo.indexNestedLoopJoinTables) + b.appendUnmatchedJoinHintWarning(HintSMJ, hintInfo.sortMergeJoinTables) + b.appendUnmatchedJoinHintWarning(HintHJ, hintInfo.hashJoinTables) b.tableHintInfo = b.tableHintInfo[:len(b.tableHintInfo)-1] } diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index faa73f9925d7e..3a9a60aea9933 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -1557,7 +1557,7 @@ func (s *testPlanSuite) TestJoinHints(c *C) { { sql: "select /*+ TIDB_INLJ(t1) */ t1.b, t2.a from t t1, t t2 where t1.b = t2.a;", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.b,test.t2.a)", - warning: "[planner:1815]Optimizer Hint /*+ TIDB_INLJ(t1) */ is inapplicable", + warning: "[planner:1815]Optimizer Hint /*+ INL_JOIN(t1) */ is inapplicable", }, } ctx := context.Background() From 67927d51e9e4469d1fb4d7b58581845293b095e7 Mon Sep 17 00:00:00 2001 From: foreyes Date: Tue, 13 Aug 2019 15:32:59 +0800 Subject: [PATCH 06/10] fix test & update parser --- executor/index_lookup_join_test.go | 8 ++++---- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/executor/index_lookup_join_test.go b/executor/index_lookup_join_test.go index c20ff9c461ca0..c32594415e424 100644 --- a/executor/index_lookup_join_test.go +++ b/executor/index_lookup_join_test.go @@ -85,17 +85,17 @@ func (s *testSuite1) TestInapplicableIndexJoinHint(c *C) { tk.MustExec(`create table t1(a bigint, b bigint);`) tk.MustExec(`create table t2(a bigint, b bigint);`) tk.MustQuery(`select /*+ TIDB_INLJ(t1, t2) */ * from t1, t2;`).Check(testkit.Rows()) - tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ TIDB_INLJ(t1, t2) */ is inapplicable without column equal ON condition`)) + tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t1, t2) */ is inapplicable without column equal ON condition`)) tk.MustQuery(`select /*+ TIDB_INLJ(t1, t2) */ * from t1 join t2 on t1.a=t2.a;`).Check(testkit.Rows()) - tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ TIDB_INLJ(t1, t2) */ is inapplicable`)) + tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t1, t2) */ is inapplicable`)) tk.MustExec(`drop table if exists t1, t2;`) tk.MustExec(`create table t1(a bigint, b bigint, index idx_a(a));`) tk.MustExec(`create table t2(a bigint, b bigint);`) tk.MustQuery(`select /*+ TIDB_INLJ(t1) */ * from t1 left join t2 on t1.a=t2.a;`).Check(testkit.Rows()) - tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ TIDB_INLJ(t1) */ is inapplicable`)) + tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t1) */ is inapplicable`)) tk.MustQuery(`select /*+ TIDB_INLJ(t2) */ * from t1 right join t2 on t1.a=t2.a;`).Check(testkit.Rows()) - tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ TIDB_INLJ(t2) */ is inapplicable`)) + tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t2) */ is inapplicable`)) } func (s *testSuite) TestIndexJoinOverflow(c *C) { diff --git a/go.mod b/go.mod index bcc317dbfa6a0..9b8318b8d4c90 100644 --- a/go.mod +++ b/go.mod @@ -76,4 +76,4 @@ require ( sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) -replace github.com/pingcap/parser => github.com/foreyes/parser v0.0.0-20190813063912-8bb2126c1499 +replace github.com/pingcap/parser => github.com/foreyes/parser v0.0.0-20190813070428-9df303f6af4f diff --git a/go.sum b/go.sum index bb8dae99c7e39..ab311e7acd2c5 100644 --- a/go.sum +++ b/go.sum @@ -47,8 +47,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/foreyes/parser v0.0.0-20190813063912-8bb2126c1499 h1:s6EoP5pzlkTvs6oLenAb5lApcqe2nQr2EA3kL5soDX4= -github.com/foreyes/parser v0.0.0-20190813063912-8bb2126c1499/go.mod h1:3lbW3qHt81o5eguDSsve9wLN8OtUzvdZrVQ/pngnIg0= +github.com/foreyes/parser v0.0.0-20190813070428-9df303f6af4f h1:65nLn4CRf4gmCnJP1yN1Ljps4UI/EzpnQHvMNO7K/0Q= +github.com/foreyes/parser v0.0.0-20190813070428-9df303f6af4f/go.mod h1:3lbW3qHt81o5eguDSsve9wLN8OtUzvdZrVQ/pngnIg0= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew= From 753ffa044e49b42fd806c8ce1ad89d747b7eff23 Mon Sep 17 00:00:00 2001 From: foreyes Date: Tue, 13 Aug 2019 16:13:15 +0800 Subject: [PATCH 07/10] fix test --- executor/index_lookup_join_test.go | 8 ++++---- planner/core/exhaust_physical_plans.go | 6 ++++-- planner/core/logical_plan_builder.go | 12 ++++++------ planner/core/physical_plan_test.go | 8 ++++---- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/executor/index_lookup_join_test.go b/executor/index_lookup_join_test.go index c32594415e424..ecdf8a44bad1b 100644 --- a/executor/index_lookup_join_test.go +++ b/executor/index_lookup_join_test.go @@ -85,17 +85,17 @@ func (s *testSuite1) TestInapplicableIndexJoinHint(c *C) { tk.MustExec(`create table t1(a bigint, b bigint);`) tk.MustExec(`create table t2(a bigint, b bigint);`) tk.MustQuery(`select /*+ TIDB_INLJ(t1, t2) */ * from t1, t2;`).Check(testkit.Rows()) - tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t1, t2) */ is inapplicable without column equal ON condition`)) + tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t1, t2) */ or /*+ TIDB_INLJ(t1, t2) */ is inapplicable without column equal ON condition`)) tk.MustQuery(`select /*+ TIDB_INLJ(t1, t2) */ * from t1 join t2 on t1.a=t2.a;`).Check(testkit.Rows()) - tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t1, t2) */ is inapplicable`)) + tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t1, t2) */ or /*+ TIDB_INLJ(t1, t2) */ is inapplicable`)) tk.MustExec(`drop table if exists t1, t2;`) tk.MustExec(`create table t1(a bigint, b bigint, index idx_a(a));`) tk.MustExec(`create table t2(a bigint, b bigint);`) tk.MustQuery(`select /*+ TIDB_INLJ(t1) */ * from t1 left join t2 on t1.a=t2.a;`).Check(testkit.Rows()) - tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t1) */ is inapplicable`)) + tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t1) */ or /*+ TIDB_INLJ(t1) */ is inapplicable`)) tk.MustQuery(`select /*+ TIDB_INLJ(t2) */ * from t1 right join t2 on t1.a=t2.a;`).Check(testkit.Rows()) - tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t2) */ is inapplicable`)) + tk.MustQuery(`show warnings;`).Check(testkit.Rows(`Warning 1815 Optimizer Hint /*+ INL_JOIN(t2) */ or /*+ TIDB_INLJ(t2) */ is inapplicable`)) } func (s *testSuite) TestIndexJoinOverflow(c *C) { diff --git a/planner/core/exhaust_physical_plans.go b/planner/core/exhaust_physical_plans.go index d3b4400e9a909..7bc2ca928f8a8 100644 --- a/planner/core/exhaust_physical_plans.go +++ b/planner/core/exhaust_physical_plans.go @@ -1005,9 +1005,11 @@ func (p *LogicalJoin) tryToGetIndexJoin(prop *property.PhysicalProperty) (indexJ defer func() { if !forced && hasIndexJoinHint { // Construct warning message prefix. - errMsg := "Optimizer Hint INL_JOIN is inapplicable" + errMsg := "Optimizer Hint INL_JOIN or TIDB_INLJ is inapplicable" if p.hintInfo != nil { - errMsg = fmt.Sprintf("Optimizer Hint %s is inapplicable", restore2JoinHint(HintINLJ, p.hintInfo.indexNestedLoopJoinTables)) + errMsg = fmt.Sprintf("Optimizer Hint %s or %s is inapplicable", + restore2JoinHint(HintINLJ, p.hintInfo.indexNestedLoopJoinTables), + restore2JoinHint(TiDBIndexNestedLoopJoin, p.hintInfo.indexNestedLoopJoinTables)) } // Append inapplicable reason. diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index ba1fbce55018e..db75844921a68 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1971,19 +1971,19 @@ func (b *PlanBuilder) pushTableHints(hints []*ast.TableOptimizerHint) { func (b *PlanBuilder) popTableHints() { hintInfo := b.tableHintInfo[len(b.tableHintInfo)-1] - b.appendUnmatchedJoinHintWarning(HintINLJ, hintInfo.indexNestedLoopJoinTables) - b.appendUnmatchedJoinHintWarning(HintSMJ, hintInfo.sortMergeJoinTables) - b.appendUnmatchedJoinHintWarning(HintHJ, hintInfo.hashJoinTables) + b.appendUnmatchedJoinHintWarning(HintINLJ, TiDBIndexNestedLoopJoin, hintInfo.indexNestedLoopJoinTables) + b.appendUnmatchedJoinHintWarning(HintSMJ, TiDBMergeJoin, hintInfo.sortMergeJoinTables) + b.appendUnmatchedJoinHintWarning(HintHJ, TiDBHashJoin, hintInfo.hashJoinTables) b.tableHintInfo = b.tableHintInfo[:len(b.tableHintInfo)-1] } -func (b *PlanBuilder) appendUnmatchedJoinHintWarning(joinType string, hintTables []hintTableInfo) { +func (b *PlanBuilder) appendUnmatchedJoinHintWarning(joinType string, joinTypeAlias string, hintTables []hintTableInfo) { unMatchedTables := extractUnmatchedTables(hintTables) if len(unMatchedTables) == 0 { return } - errMsg := fmt.Sprintf("There are no matching table names for (%s) in optimizer hint %s. Maybe you can use the table alias name", - strings.Join(unMatchedTables, ", "), restore2JoinHint(joinType, hintTables)) + errMsg := fmt.Sprintf("There are no matching table names for (%s) in optimizer hint %s or %s. Maybe you can use the table alias name", + strings.Join(unMatchedTables, ", "), restore2JoinHint(joinType, hintTables), restore2JoinHint(joinType, hintTables)) b.ctx.GetSessionVars().StmtCtx.AppendWarning(ErrInternal.GenWithStack(errMsg)) } diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index 3a9a60aea9933..6dc9d2a33658e 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -1495,15 +1495,15 @@ func (s *testPlanSuite) TestUnmatchedTableInHint(c *C) { }{ { sql: "SELECT /*+ TIDB_SMJ(t3, t4) */ * from t t1, t t2 where t1.a = t2.a", - warning: "[planner:1815]There are no matching table names for (t3, t4) in optimizer hint /*+ TIDB_SMJ(t3, t4) */. Maybe you can use the table alias name", + warning: "[planner:1815]There are no matching table names for (t3, t4) in optimizer hint /*+ SM_JOIN(t3, t4) */ or /*+ TIDB_SMJ(t3, t4) */. Maybe you can use the table alias name", }, { sql: "SELECT /*+ TIDB_HJ(t3, t4) */ * from t t1, t t2 where t1.a = t2.a", - warning: "[planner:1815]There are no matching table names for (t3, t4) in optimizer hint /*+ TIDB_HJ(t3, t4) */. Maybe you can use the table alias name", + warning: "[planner:1815]There are no matching table names for (t3, t4) in optimizer hint /*+ HASH_JOIN(t3, t4) */ or /*+ TIDB_HJ(t3, t4) */. Maybe you can use the table alias name", }, { sql: "SELECT /*+ TIDB_INLJ(t3, t4) */ * from t t1, t t2 where t1.a = t2.a", - warning: "[planner:1815]There are no matching table names for (t3, t4) in optimizer hint /*+ TIDB_INLJ(t3, t4) */. Maybe you can use the table alias name", + warning: "[planner:1815]There are no matching table names for (t3, t4) in optimizer hint /*+ INL_JOIN(t3, t4) */ or /*+ TIDB_INLJ(t3, t4) */. Maybe you can use the table alias name", }, { sql: "SELECT /*+ TIDB_SMJ(t1, t2) */ * from t t1, t t2 where t1.a = t2.a", @@ -1511,7 +1511,7 @@ func (s *testPlanSuite) TestUnmatchedTableInHint(c *C) { }, { sql: "SELECT /*+ TIDB_SMJ(t3, t4) */ * from t t1, t t2, t t3 where t1.a = t2.a and t2.a = t3.a", - warning: "[planner:1815]There are no matching table names for (t4) in optimizer hint /*+ TIDB_SMJ(t3, t4) */. Maybe you can use the table alias name", + warning: "[planner:1815]There are no matching table names for (t4) in optimizer hint /*+ SM_JOIN(t3, t4) */ or /*+ TIDB_SMJ(t3, t4) */. Maybe you can use the table alias name", }, } for _, test := range tests { From 42fb6a50a6cebff459f1c598f46e750b8ec3b837 Mon Sep 17 00:00:00 2001 From: foreyes Date: Tue, 13 Aug 2019 16:21:57 +0800 Subject: [PATCH 08/10] fix ci --- planner/core/physical_plan_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index 6dc9d2a33658e..2c130144680d3 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -1557,7 +1557,7 @@ func (s *testPlanSuite) TestJoinHints(c *C) { { sql: "select /*+ TIDB_INLJ(t1) */ t1.b, t2.a from t t1, t t2 where t1.b = t2.a;", best: "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t1.b,test.t2.a)", - warning: "[planner:1815]Optimizer Hint /*+ INL_JOIN(t1) */ is inapplicable", + warning: "[planner:1815]Optimizer Hint /*+ INL_JOIN(t1) */ or /*+ TIDB_INLJ(t1) */ is inapplicable", }, } ctx := context.Background() From fc73ed88b725df03ba70104dee229380024489fc Mon Sep 17 00:00:00 2001 From: foreyes Date: Tue, 13 Aug 2019 16:35:56 +0800 Subject: [PATCH 09/10] fix ci --- planner/core/logical_plan_builder.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planner/core/logical_plan_builder.go b/planner/core/logical_plan_builder.go index db75844921a68..075a0b2f48a3e 100644 --- a/planner/core/logical_plan_builder.go +++ b/planner/core/logical_plan_builder.go @@ -1983,7 +1983,7 @@ func (b *PlanBuilder) appendUnmatchedJoinHintWarning(joinType string, joinTypeAl return } errMsg := fmt.Sprintf("There are no matching table names for (%s) in optimizer hint %s or %s. Maybe you can use the table alias name", - strings.Join(unMatchedTables, ", "), restore2JoinHint(joinType, hintTables), restore2JoinHint(joinType, hintTables)) + strings.Join(unMatchedTables, ", "), restore2JoinHint(joinType, hintTables), restore2JoinHint(joinTypeAlias, hintTables)) b.ctx.GetSessionVars().StmtCtx.AppendWarning(ErrInternal.GenWithStack(errMsg)) } From d723768ecd78a8713b5d5421163b634fdf87f183 Mon Sep 17 00:00:00 2001 From: foreyes Date: Wed, 14 Aug 2019 17:33:12 +0800 Subject: [PATCH 10/10] update parser --- go.mod | 4 +--- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 9b8318b8d4c90..89b68ad81acba 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,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-20190805112544-2b054e14336b + github.com/pingcap/parser v0.0.0-20190814092219-43d2d687aecb 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 @@ -75,5 +75,3 @@ require ( sourcegraph.com/sourcegraph/appdash v0.0.0-20180531100431-4c381bd170b4 sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 ) - -replace github.com/pingcap/parser => github.com/foreyes/parser v0.0.0-20190813070428-9df303f6af4f diff --git a/go.sum b/go.sum index ab311e7acd2c5..5d56b30164492 100644 --- a/go.sum +++ b/go.sum @@ -47,8 +47,6 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385 h1:clC1lXBpe2kTj2VHdaIu9ajZQe4kcEY9j0NsnDDBZ3o= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= -github.com/foreyes/parser v0.0.0-20190813070428-9df303f6af4f h1:65nLn4CRf4gmCnJP1yN1Ljps4UI/EzpnQHvMNO7K/0Q= -github.com/foreyes/parser v0.0.0-20190813070428-9df303f6af4f/go.mod h1:3lbW3qHt81o5eguDSsve9wLN8OtUzvdZrVQ/pngnIg0= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32 h1:Mn26/9ZMNWSw9C9ERFA1PUxfmGpolnw2v0bKOREu5ew= @@ -167,6 +165,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-20190814092219-43d2d687aecb h1:7VLFE2QHeZIhnpKK0XRESkgXj/PtJguIkDZvW3MinN4= +github.com/pingcap/parser v0.0.0-20190814092219-43d2d687aecb/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=