diff --git a/executor/executor_test.go b/executor/executor_test.go index 5d93cea0dbb50..3fcfc722ce6e7 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -5939,6 +5939,20 @@ func (s *testSuite) TestSlowQuerySensitiveQuery(c *C) { )) } +func (s *testClusterTableSuite) 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 *testSplitTable) TestKillTableReader(c *C) { var retry = "github.com/pingcap/tidb/store/tikv/mockRetrySendReqToRegion" defer func() { diff --git a/executor/slow_query.go b/executor/slow_query.go index f0540ed8e496f..f689b42374e41 100644 --- a/executor/slow_query.go +++ b/executor/slow_query.go @@ -618,6 +618,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