From 2599af3c9482d671b7a4694b9cae2e08b8d98281 Mon Sep 17 00:00:00 2001 From: crazycs Date: Tue, 15 Sep 2020 20:45:00 +0800 Subject: [PATCH 1/2] cherry pick #20000 to release-4.0 Signed-off-by: ti-srebot --- executor/executor_test.go | 18 ++++++++++++++++++ executor/slow_query.go | 3 +++ 2 files changed, 21 insertions(+) diff --git a/executor/executor_test.go b/executor/executor_test.go index 1a4af061f395c..075c311a3e660 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -5910,7 +5910,25 @@ func (s *testSuite) TestGenerateColumnReplace(c *C) { tk.MustQuery("select * from t1").Check(testkit.Rows("3 4")) } +<<<<<<< HEAD func (s *testSuite) TestSlowQuerySensitiveQuery(c *C) { +======= +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) { +>>>>>>> aed24e4... executor: fix query slow_query error when slow-log file not exist (#20000) tk := testkit.NewTestKit(c, s.store) originCfg := config.GetGlobalConfig() newCfg := *originCfg 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 From d155fb0ce9eab52b4487ae9ddf846b0a2099425a Mon Sep 17 00:00:00 2001 From: crazycs520 Date: Fri, 18 Sep 2020 10:51:33 +0800 Subject: [PATCH 2/2] fix conflict Signed-off-by: crazycs520 --- executor/executor_test.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/executor/executor_test.go b/executor/executor_test.go index 5d9f1b71fd158..3fcfc722ce6e7 100644 --- a/executor/executor_test.go +++ b/executor/executor_test.go @@ -5910,25 +5910,7 @@ func (s *testSuite) TestGenerateColumnReplace(c *C) { tk.MustQuery("select * from t1").Check(testkit.Rows("3 4")) } -<<<<<<< HEAD func (s *testSuite) TestSlowQuerySensitiveQuery(c *C) { -======= -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) { ->>>>>>> aed24e4... executor: fix query slow_query error when slow-log file not exist (#20000) tk := testkit.NewTestKit(c, s.store) originCfg := config.GetGlobalConfig() newCfg := *originCfg @@ -5957,6 +5939,20 @@ func (s *testSlowQuery) 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() {