From 1b5bd2001065fa1028b3d102c9bcd1fd60e0dd11 Mon Sep 17 00:00:00 2001 From: "Zhuomin(Charming) Liu" Date: Fri, 5 Jun 2020 17:12:27 +0800 Subject: [PATCH] cherry pick #17556 to release-4.0 Signed-off-by: sre-bot --- planner/core/integration_test.go | 21 ++++++++++++++++ planner/core/planbuilder.go | 2 +- .../testdata/integration_serial_suite_in.json | 8 +++++++ .../integration_serial_suite_out.json | 24 +++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 8766fd6d64ecd..fdaeca12e5749 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -532,6 +532,27 @@ func (s *testIntegrationSerialSuite) TestIsolationReadTiFlashUseIndexHint(c *C) } } +func (s *testIntegrationSerialSuite) TestIsolationReadDoNotFilterSystemDB(c *C) { + tk := testkit.NewTestKit(c, s.store) + + tk.MustExec("use test") + tk.MustExec("set @@tidb_isolation_read_engines = \"tiflash\"") + var input []string + var output []struct { + SQL string + Plan []string + } + s.testData.GetTestCases(c, &input, &output) + for i, tt := range input { + s.testData.OnRecord(func() { + output[i].SQL = tt + output[i].Plan = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Rows()) + }) + res := tk.MustQuery(tt) + res.Check(testkit.Rows(output[i].Plan...)) + } +} + func (s *testIntegrationSuite) TestPartitionTableStats(c *C) { tk := testkit.NewTestKit(c, s.store) diff --git a/planner/core/planbuilder.go b/planner/core/planbuilder.go index 71e50c0c96bd9..4918d08ea5bb3 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -828,7 +828,7 @@ func (b *PlanBuilder) filterPathByIsolationRead(paths []*util.AccessPath, dbName } availableEngineStr += paths[i].StoreType.Name() } - if _, ok := isolationReadEngines[paths[i].StoreType]; !ok { + if _, ok := isolationReadEngines[paths[i].StoreType]; !ok && paths[i].StoreType != kv.TiDB { paths = append(paths[:i], paths[i+1:]...) } } diff --git a/planner/core/testdata/integration_serial_suite_in.json b/planner/core/testdata/integration_serial_suite_in.json index 21acd71812f66..dd62c3b372578 100644 --- a/planner/core/testdata/integration_serial_suite_in.json +++ b/planner/core/testdata/integration_serial_suite_in.json @@ -42,6 +42,14 @@ "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t" ] }, + { + "name": "TestIsolationReadDoNotFilterSystemDB", + "cases": [ + "desc select * from metrics_schema.tidb_query_duration where time >= '2019-12-23 16:10:13' and time <= '2019-12-23 16:30:13'", + "desc select * from information_schema.tables", + "desc select * from mysql.stats_meta" + ] + }, { "name": "TestIsolationReadTiFlashNotChoosePointGet", "cases": [ diff --git a/planner/core/testdata/integration_serial_suite_out.json b/planner/core/testdata/integration_serial_suite_out.json index 16065f2ac89d2..f3ce566e30d0e 100644 --- a/planner/core/testdata/integration_serial_suite_out.json +++ b/planner/core/testdata/integration_serial_suite_out.json @@ -240,6 +240,30 @@ } ] }, + { + "Name": "TestIsolationReadDoNotFilterSystemDB", + "Cases": [ + { + "SQL": "desc select * from metrics_schema.tidb_query_duration where time >= '2019-12-23 16:10:13' and time <= '2019-12-23 16:30:13'", + "Plan": [ + "MemTableScan_5 10000.00 root table:tidb_query_duration PromQL:histogram_quantile(0.9, sum(rate(tidb_server_handle_query_duration_seconds_bucket{}[60s])) by (le,sql_type,instance)), start_time:2019-12-23 16:10:13, end_time:2019-12-23 16:30:13, step:1m0s" + ] + }, + { + "SQL": "desc select * from information_schema.tables", + "Plan": [ + "MemTableScan_4 10000.00 root table:TABLES " + ] + }, + { + "SQL": "desc select * from mysql.stats_meta", + "Plan": [ + "TableReader_5 10000.00 root data:TableFullScan_4", + "└─TableFullScan_4 10000.00 cop[tikv] table:stats_meta keep order:false, stats:pseudo" + ] + } + ] + }, { "Name": "TestIsolationReadTiFlashNotChoosePointGet", "Cases": [