From 77a48f1600bed51632656c1b9c027e4ec5c7c413 Mon Sep 17 00:00:00 2001 From: Leon Zhang Date: Tue, 28 May 2019 11:26:01 +0800 Subject: [PATCH] add max_execution_time hint for explain query SELECT /*+ MAX_EXECUTION_TIME(1000) */ --- database/explain.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/database/explain.go b/database/explain.go index b06587a..022fbb6 100644 --- a/database/explain.go +++ b/database/explain.go @@ -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 -- GitLab