Skip to content

Commit

Permalink
planner: improve the error message for hints defined more than once (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
raygift authored Jun 1, 2020
1 parent 7b2d79c commit 8a164d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions planner/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func handleStmtHints(hints []*ast.TableOptimizerHint) (stmtHints stmtctx.StmtHin
// Handle MEMORY_QUOTA
if memoryQuotaHintCnt != 0 {
if memoryQuotaHintCnt > 1 {
warn := errors.New("There are multiple MEMORY_QUOTA hints, only the last one will take effect")
warn := errors.Errorf("MEMORY_QUOTA() s defined more than once, only the last definition takes effect: MEMORY_QUOTA(%v)", memoryQuotaHint.HintData.(int64))
warns = append(warns, warn)
}
// Executor use MemoryQuota <= 0 to indicate no memory limit, here use < 0 to handle hint syntax error.
Expand All @@ -351,7 +351,7 @@ func handleStmtHints(hints []*ast.TableOptimizerHint) (stmtHints stmtctx.StmtHin
// Handle USE_TOJA
if useToJAHintCnt != 0 {
if useToJAHintCnt > 1 {
warn := errors.New("There are multiple USE_TOJA hints, only the last one will take effect")
warn := errors.Errorf("USE_TOJA() is defined more than once, only the last definition takes effect: USE_TOJA(%v)", useToJAHint.HintData.(bool))
warns = append(warns, warn)
}
stmtHints.HasAllowInSubqToJoinAndAggHint = true
Expand All @@ -369,15 +369,15 @@ func handleStmtHints(hints []*ast.TableOptimizerHint) (stmtHints stmtctx.StmtHin
// Handle NO_INDEX_MERGE
if noIndexMergeHintCnt != 0 {
if noIndexMergeHintCnt > 1 {
warn := errors.New("There are multiple NO_INDEX_MERGE hints, only the last one will take effect")
warn := errors.New("NO_INDEX_MERGE() is defined more than once, only the last definition takes effect")
warns = append(warns, warn)
}
stmtHints.NoIndexMergeHint = true
}
// Handle READ_CONSISTENT_REPLICA
if readReplicaHintCnt != 0 {
if readReplicaHintCnt > 1 {
warn := errors.New("There are multiple READ_CONSISTENT_REPLICA hints, only the last one will take effect")
warn := errors.New("READ_CONSISTENT_REPLICA() is defined more than once, only the last definition takes effect")
warns = append(warns, warn)
}
stmtHints.HasReplicaReadHint = true
Expand All @@ -386,7 +386,7 @@ func handleStmtHints(hints []*ast.TableOptimizerHint) (stmtHints stmtctx.StmtHin
// Handle MAX_EXECUTION_TIME
if maxExecutionTimeCnt != 0 {
if maxExecutionTimeCnt > 1 {
warn := errors.New("There are multiple MAX_EXECUTION_TIME hints, only the last one will take effect")
warn := errors.Errorf("MAX_EXECUTION_TIME() is defined more than once, only the last definition takes effect: MAX_EXECUTION_TIME(%v)", maxExecutionTime.HintData.(uint64))
warns = append(warns, warn)
}
stmtHints.HasMaxExecutionTime = true
Expand Down
2 changes: 1 addition & 1 deletion session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,7 @@ func (s *testSessionSuite3) TestMaxExeucteTime(c *C) {

tk.MustQuery("select /*+ MAX_EXECUTION_TIME(1000) MAX_EXECUTION_TIME(500) */ * FROM MaxExecTime;")
c.Assert(tk.Se.GetSessionVars().StmtCtx.GetWarnings(), HasLen, 1)
c.Assert(tk.Se.GetSessionVars().StmtCtx.GetWarnings()[0].Err.Error(), Equals, "There are multiple MAX_EXECUTION_TIME hints, only the last one will take effect")
c.Assert(tk.Se.GetSessionVars().StmtCtx.GetWarnings()[0].Err.Error(), Equals, "MAX_EXECUTION_TIME() is defined more than once, only the last definition takes effect: MAX_EXECUTION_TIME(500)")
c.Assert(tk.Se.GetSessionVars().StmtCtx.HasMaxExecutionTime, Equals, true)
c.Assert(tk.Se.GetSessionVars().StmtCtx.MaxExecutionTime, Equals, uint64(500))

Expand Down

0 comments on commit 8a164d2

Please sign in to comment.