Skip to content

Commit

Permalink
add max_execution_time hint for explain query
Browse files Browse the repository at this point in the history
  SELECT /*+ MAX_EXECUTION_TIME(1000) */
  • Loading branch information
martianzhang committed May 28, 2019
1 parent 82efd3c commit 77a48f1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions database/explain.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ func (db *Connector) explainQuery(sql string, explainType int, formatType int) s
sql, err = db.explainAbleSQL(sql)
if sql == "" || err != nil {
return sql
} else {
// MySQL 5.7 support MAX_EXECUTION_TIME hint
// ref: https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html
re := regexp.MustCompile(`(?i)(^select)(.*)`)
sql = re.ReplaceAllString(sql, "SELECT /*+ MAX_EXECUTION_TIME(1000) */${2}")
}

// 5.6以上支持 FORMAT=JSON
Expand Down

0 comments on commit 77a48f1

Please sign in to comment.