Skip to content

Commit

Permalink
planner: remove the limit that nth_plan hint value can't exceed 100 (
Browse files Browse the repository at this point in the history
  • Loading branch information
time-and-fate authored Aug 10, 2020
1 parent b8670fb commit 8978773
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions planner/core/find_best_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ var aggFuncFactor = map[string]float64{
}

// PlanCounterTp is used in hint nth_plan() to indicate which plan to use.
type PlanCounterTp int8
type PlanCounterTp int64

// PlanCounterDisabled is the default value of PlanCounterTp, indicating that optimizer needn't force a plan.
var PlanCounterDisabled PlanCounterTp = -1

// Dec minus PlanCounterTp value by x.
func (c *PlanCounterTp) Dec(x int8) {
func (c *PlanCounterTp) Dec(x int64) {
if *c <= 0 {
return
}
*c = PlanCounterTp(int8(*c) - x)
*c = PlanCounterTp(int64(*c) - x)
if *c < 0 {
*c = 0
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func (p *baseLogicalPlan) enumeratePhysicalPlans4Task(physicalPlans []PhysicalPl
}

cntPlan += curCntPlan
planCounter.Dec(int8(curCntPlan))
planCounter.Dec(curCntPlan)

if planCounter.Empty() {
bestTask = curTask
Expand Down
4 changes: 4 additions & 0 deletions planner/core/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ func (s *testPlanNormalize) TestNthPlanHint(c *C) {
tk.MustQuery("show warnings").Check(testkit.Rows(
"Warning 1105 The parameter of nth_plan() is out of range."))

tk.MustExec("explain format='hint' select /*+ nth_plan(500) */ * from t where a=1 and b=1")
tk.MustQuery("show warnings").Check(testkit.Rows(
"Warning 1105 The parameter of nth_plan() is out of range."))

// Test warning for multiply hints.
tk.MustQuery("explain format='hint' select /*+ nth_plan(1) nth_plan(2) */ * from t where a=1 and b=1").Check(testkit.Rows(
"use_index(@`sel_1` `test`.`t` `a_2`), nth_plan(1), nth_plan(2)"))
Expand Down
4 changes: 0 additions & 4 deletions planner/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,6 @@ func handleStmtHints(hints []*ast.TableOptimizerHint) (stmtHints stmtctx.StmtHin
stmtHints.ForceNthPlan = -1
warn := errors.Errorf("the hintdata for NTH_PLAN() is too small, hint ignored.")
warns = append(warns, warn)
} else if stmtHints.ForceNthPlan > 100 {
stmtHints.ForceNthPlan = -1
warn := errors.Errorf("the hintdata for NTH_PLAN() is too big, hint ignored.")
warns = append(warns, warn)
}
} else {
stmtHints.ForceNthPlan = -1
Expand Down

0 comments on commit 8978773

Please sign in to comment.