Skip to content

Commit

Permalink
test: fix TestAggToCopHint (pingcap#14741)
Browse files Browse the repository at this point in the history
  • Loading branch information
lzmhhh123 authored Feb 12, 2020
1 parent fa04a32 commit 03705d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 20 deletions.
25 changes: 14 additions & 11 deletions planner/core/physical_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,41 +789,44 @@ func (s *testPlanSuite) TestAggToCopHint(c *C) {
dom.Close()
store.Close()
}()
se, err := session.CreateSession4Test(store)
c.Assert(err, IsNil)
_, err = se.Execute(context.Background(), "use test")
c.Assert(err, IsNil)
_, err = se.Execute(context.Background(), "insert into mysql.opt_rule_blacklist values(\"aggregation_eliminate\")")
c.Assert(err, IsNil)
_, err = se.Execute(context.Background(), "admin reload opt_rule_blacklist")
c.Assert(err, IsNil)
tk := testkit.NewTestKit(c, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists ta")
tk.MustExec("create table ta(a int, b int, index(a))")

var (
input []string
output []struct {
SQL string
Best string
Warning string
}
)
s.testData.GetTestCases(c, &input, &output)

ctx := context.Background()
is := domain.GetDomain(tk.Se).InfoSchema()
for i, test := range input {
comment := Commentf("case:%v sql:%s", i, test)
se.GetSessionVars().StmtCtx.SetWarnings(nil)
s.testData.OnRecord(func() {
output[i].SQL = test
})
c.Assert(test, Equals, output[i].SQL, comment)

tk.Se.GetSessionVars().StmtCtx.SetWarnings(nil)

stmt, err := s.ParseOneStmt(test, "", "")
c.Assert(err, IsNil, comment)

p, _, err := planner.Optimize(ctx, se, stmt, s.is)
p, _, err := planner.Optimize(ctx, tk.Se, stmt, is)
c.Assert(err, IsNil)
planString := core.ToString(p)
s.testData.OnRecord(func() {
output[i].Best = planString
})
c.Assert(planString, Equals, output[i].Best, comment)

warnings := se.GetSessionVars().StmtCtx.GetWarnings()
warnings := tk.Se.GetSessionVars().StmtCtx.GetWarnings()
s.testData.OnRecord(func() {
if len(warnings) > 0 {
output[i].Warning = warnings[0].Err.Error()
Expand Down
8 changes: 4 additions & 4 deletions planner/core/testdata/plan_suite_in.json
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,10 @@
{
"name": "TestAggToCopHint",
"cases": [
"select /*+ AGG_TO_COP(), HASH_AGG(), USE_INDEX(t) */ sum(a) from t group by a",
"select /*+ AGG_TO_COP(), USE_INDEX(t) */ sum(b) from t group by b",
"select /*+ AGG_TO_COP(), HASH_AGG(), USE_INDEX(t) */ distinct a from t group by a",
"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"
"select /*+ AGG_TO_COP(), HASH_AGG(), USE_INDEX(t) */ sum(a) from ta group by a",
"select /*+ AGG_TO_COP(), USE_INDEX(t) */ sum(b) from ta group by b",
"select /*+ AGG_TO_COP(), HASH_AGG(), USE_INDEX(t) */ distinct a from ta group by a",
"select /*+ AGG_TO_COP(), HASH_AGG(), HASH_JOIN(t1), USE_INDEX(t1), USE_INDEX(t2) */ sum(t1.a) from ta t1, ta t2 where t1.a = t2.b group by t1.a"
]
},
{
Expand Down
14 changes: 9 additions & 5 deletions planner/core/testdata/plan_suite_out.json
Original file line number Diff line number Diff line change
Expand Up @@ -1386,19 +1386,23 @@
"Name": "TestAggToCopHint",
"Cases": [
{
"Best": "TableReader(Table(t)->HashAgg)->HashAgg",
"SQL": "select /*+ AGG_TO_COP(), HASH_AGG(), USE_INDEX(t) */ sum(a) from ta group by a",
"Best": "IndexReader(Index(ta.a)[[NULL,+inf]]->HashAgg)->HashAgg",
"Warning": ""
},
{
"Best": "TableReader(Table(t)->HashAgg)->HashAgg",
"SQL": "select /*+ AGG_TO_COP(), USE_INDEX(t) */ sum(b) from ta group by b",
"Best": "TableReader(Table(ta)->HashAgg)->HashAgg",
"Warning": ""
},
{
"Best": "TableReader(Table(t)->HashAgg)->HashAgg->HashAgg",
"Warning": "[planner:1815]Optimizer Hint AGG_TO_COP is inapplicable"
"SQL": "select /*+ AGG_TO_COP(), HASH_AGG(), USE_INDEX(t) */ distinct a from ta group by a",
"Best": "IndexReader(Index(ta.a)[[NULL,+inf]]->HashAgg)->HashAgg",
"Warning": ""
},
{
"Best": "LeftHashJoin{TableReader(Table(t))->TableReader(Table(t))}(test.t.a,test.t.b)->Projection->HashAgg",
"SQL": "select /*+ AGG_TO_COP(), HASH_AGG(), HASH_JOIN(t1), USE_INDEX(t1), USE_INDEX(t2) */ sum(t1.a) from ta t1, ta t2 where t1.a = t2.b group by t1.a",
"Best": "LeftHashJoin{TableReader(Table(ta)->Sel([not(isnull(test.ta.a))]))->TableReader(Table(ta)->Sel([not(isnull(test.ta.b))]))}(test.ta.a,test.ta.b)->Projection->HashAgg",
"Warning": "[planner:1815]Optimizer Hint AGG_TO_COP is inapplicable"
}
]
Expand Down

0 comments on commit 03705d1

Please sign in to comment.