From c3816b2bbfff0681c5274cf7139237212db51ed2 Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Tue, 15 Sep 2020 14:53:49 +0800 Subject: [PATCH] executor: fix query slow_query error when slow-log file not exist Signed-off-by: crazycs520 --- executor/executor_test.go | 14 ++++++++++++++ executor/slow_query.go | 3 +++ 2 files changed, 17 insertions(+) diff --git a/executor/executor_test.go b/executor/executor_test.go index fa3c64bc82038..ea3826b95d658 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -6224,6 +6224,20 @@ func (s *testSuite) TestGenerateColumnReplace(c *C) { tk.MustQuery("select * from t1").Check(testkit.Rows("3 4")) } +func (s *testSlowQuery) TestSlowQueryWithoutSlowLog(c *C) { + tk := testkit.NewTestKit(c, s.store) + originCfg := config.GetGlobalConfig() + newCfg := *originCfg + newCfg.Log.SlowQueryFile = "tidb-slow-not-exist.log" + newCfg.Log.SlowThreshold = math.MaxUint64 + config.StoreGlobalConfig(&newCfg) + defer func() { + config.StoreGlobalConfig(originCfg) + }() + tk.MustQuery("select query from information_schema.slow_query").Check(testkit.Rows()) + tk.MustQuery("select query from information_schema.slow_query where time > '2020-09-15 12:16:39' and time < now()").Check(testkit.Rows()) +} + func (s *testSlowQuery) TestSlowQuerySensitiveQuery(c *C) { tk := testkit.NewTestKit(c, s.store) originCfg := config.GetGlobalConfig() diff --git a/executor/slow_query.go b/executor/slow_query.go index d4120046bbc12..fab505f431910 100644 --- a/executor/slow_query.go +++ b/executor/slow_query.go @@ -707,6 +707,9 @@ func (e *slowQueryRetriever) getAllFiles(sctx sessionctx.Context, logFilePath st if e.extractor == nil || !e.extractor.Enable { file, err := os.Open(logFilePath) if err != nil { + if os.IsNotExist(err) { + return nil, nil + } return nil, err } return []logFile{{file: file}}, nil