From 7924bbac1c7eb90c9cc8c7c22833d18ff6942252 Mon Sep 17 00:00:00 2001 From: Shenghui Wu <793703860@qq.com> Date: Fri, 27 Mar 2020 15:24:14 +0800 Subject: [PATCH 1/2] cherry pick #15723 to release-3.1 Signed-off-by: sre-bot --- planner/core/integration_test.go | 77 ++++++ planner/core/planbuilder.go | 12 + .../testdata/integration_serial_suite_in.json | 50 ++++ .../integration_serial_suite_out.json | 242 ++++++++++++++++++ 4 files changed, 381 insertions(+) create mode 100644 planner/core/testdata/integration_serial_suite_in.json create mode 100644 planner/core/testdata/integration_serial_suite_out.json diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 9123ab2b0c5eb..07144b70e3c9f 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -416,6 +416,83 @@ func (s *testIntegrationSuite) TestReadFromStorageHintAndIsolationRead(c *C) { } } +<<<<<<< HEAD +======= +func (s *testIntegrationSerialSuite) TestIsolationReadTiFlashNotChoosePointGet(c *C) { + tk := testkit.NewTestKit(c, s.store) + + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, b int, primary key (a))") + + // Create virtual tiflash replica info. + dom := domain.GetDomain(tk.Se) + is := dom.InfoSchema() + db, exists := is.SchemaByName(model.NewCIStr("test")) + c.Assert(exists, IsTrue) + for _, tblInfo := range db.Tables { + tblInfo.TiFlashReplica = &model.TiFlashReplicaInfo{ + Count: 1, + Available: true, + } + } + + tk.MustExec("set @@session.tidb_isolation_read_engines=\"tiflash\"") + var input []string + var output []struct { + SQL string + Result []string + } + s.testData.GetTestCases(c, &input, &output) + for i, tt := range input { + s.testData.OnRecord(func() { + output[i].SQL = tt + output[i].Result = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Rows()) + }) + tk.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) + } +} + +func (s *testIntegrationSerialSuite) TestIsolationReadTiFlashUseIndexHint(c *C) { + tk := testkit.NewTestKit(c, s.store) + + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int, index idx(a));") + + // Create virtual tiflash replica info. + dom := domain.GetDomain(tk.Se) + is := dom.InfoSchema() + db, exists := is.SchemaByName(model.NewCIStr("test")) + c.Assert(exists, IsTrue) + for _, tblInfo := range db.Tables { + tblInfo.TiFlashReplica = &model.TiFlashReplicaInfo{ + Count: 1, + Available: true, + } + } + + tk.MustExec("set @@session.tidb_isolation_read_engines=\"tiflash\"") + var input []string + var output []struct { + SQL string + Plan []string + Warn []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()) + output[i].Warn = s.testData.ConvertSQLWarnToStrings(tk.Se.GetSessionVars().StmtCtx.GetWarnings()) + }) + res := tk.MustQuery(tt) + res.Check(testkit.Rows(output[i].Plan...)) + c.Assert(s.testData.ConvertSQLWarnToStrings(tk.Se.GetSessionVars().StmtCtx.GetWarnings()), DeepEquals, output[i].Warn) + } +} + +>>>>>>> 9dc6d9c... planner: check readEngines when building plan for index hint (#15723) 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 46473480da94c..e36c269a26609 100644 --- a/planner/core/planbuilder.go +++ b/planner/core/planbuilder.go @@ -564,6 +564,7 @@ func (b *PlanBuilder) getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInf } } + _, isolationReadEnginesHasTiKV := b.ctx.GetSessionVars().GetIsolationReadEngines()[kv.TiKV] for i, hint := range indexHints { if hint.HintScope != ast.HintForScan { continue @@ -571,6 +572,17 @@ func (b *PlanBuilder) getPossibleAccessPaths(indexHints []*ast.IndexHint, tblInf hasScanHint = true + if !isolationReadEnginesHasTiKV { + if hint.IndexNames != nil { + engineVals, _ := b.ctx.GetSessionVars().GetSystemVar(variable.TiDBIsolationReadEngines) + err := errors.New(fmt.Sprintf("TiDB doesn't support index in the isolation read engines(value: '%v')", engineVals)) + if i < indexHintsLen { + return nil, err + } + b.ctx.GetSessionVars().StmtCtx.AppendWarning(err) + } + continue + } // It is syntactically valid to omit index_list for USE INDEX, which means “use no indexes”. // Omitting index_list for FORCE INDEX or IGNORE INDEX is a syntax error. // See https://dev.mysql.com/doc/refman/8.0/en/index-hints.html. diff --git a/planner/core/testdata/integration_serial_suite_in.json b/planner/core/testdata/integration_serial_suite_in.json new file mode 100644 index 0000000000000..eba7a5c2da5db --- /dev/null +++ b/planner/core/testdata/integration_serial_suite_in.json @@ -0,0 +1,50 @@ +[ + { + "name": "TestSelPushDownTiFlash", + "cases": [ + "explain select * from t where t.a > 1 and t.b = \"flash\" or t.a + 3 * t.a = 5", + "explain select * from t where cast(t.a as float) + 3 = 5.1" + ] + }, + { + "name": "TestReadFromStorageHint", + "cases": [ + "desc select avg(a) from t", + "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t", + "desc select /*+ read_from_storage(tiflash[t]) */ sum(a) from t", + "desc select /*+ read_from_storage(tiflash[t]) */ sum(a+1) from t", + "desc select /*+ read_from_storage(tiflash[t]) */ sum(isnull(a)) from t", + "desc select /*+ READ_FROM_STORAGE(TIKV[t1], TIKV[t2]) */ * from t t1, t t2 where t1.a = t2.a", + "desc select /*+ READ_FROM_STORAGE(TIKV[t1], TIFLASH[t2]) */ * from t t1, t t2 where t1.a = t2.a", + "desc select * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)", + "desc select /*+ read_from_storage(tiflash[tt]) */ * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)", + "desc select * from ttt order by ttt.a desc", + "desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a desc", + "desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a" + ] + }, + { + "name": "TestReadFromStorageHintAndIsolationRead", + "cases": [ + "desc select /*+ read_from_storage(tikv[t], tiflash[t]) */ avg(a) from t", + "desc select /*+ read_from_storage(tikv[t]) */ avg(a) from t", + "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t" + ] + }, + { + "name": "TestIsolationReadTiFlashNotChoosePointGet", + "cases": [ + "explain select * from t where t.a = 1", + "explain select * from t where t.a in (1, 2)" + ] + }, + { + "name": "TestIsolationReadTiFlashUseIndexHint", + "cases": [ + "explain select * from t", + "explain select * from t use index();", + "explain select /*+ use_index(t, idx)*/ * from t", + "explain select /*+ use_index(t)*/ * from t" + ] + } +] diff --git a/planner/core/testdata/integration_serial_suite_out.json b/planner/core/testdata/integration_serial_suite_out.json new file mode 100644 index 0000000000000..1e34ea443b96e --- /dev/null +++ b/planner/core/testdata/integration_serial_suite_out.json @@ -0,0 +1,242 @@ +[ + { + "Name": "TestSelPushDownTiFlash", + "Cases": [ + { + "SQL": "explain select * from t where t.a > 1 and t.b = \"flash\" or t.a + 3 * t.a = 5", + "Plan": [ + "TableReader_7 8000.00 root data:Selection_6", + "└─Selection_6 8000.00 cop[tiflash] or(and(gt(test.t.a, 1), eq(test.t.b, \"flash\")), eq(plus(test.t.a, mul(3, test.t.a)), 5))", + " └─TableFullScan_5 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ] + }, + { + "SQL": "explain select * from t where cast(t.a as float) + 3 = 5.1", + "Plan": [ + "Selection_7 10000.00 root eq(plus(cast(test.t.a), 3), 5.1)", + "└─TableReader_6 10000.00 root data:TableFullScan_5", + " └─TableFullScan_5 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ] + } + ] + }, + { + "Name": "TestReadFromStorageHint", + "Cases": [ + { + "SQL": "desc select avg(a) from t", + "Plan": [ + "StreamAgg_24 1.00 root funcs:avg(Column#7, Column#8)->Column#4", + "└─TableReader_25 1.00 root data:StreamAgg_8", + " └─StreamAgg_8 1.00 cop[tiflash] funcs:count(test.t.a)->Column#7, funcs:sum(test.t.a)->Column#8", + " └─TableFullScan_22 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t", + "Plan": [ + "StreamAgg_16 1.00 root funcs:avg(Column#7, Column#8)->Column#4", + "└─TableReader_17 1.00 root data:StreamAgg_8", + " └─StreamAgg_8 1.00 cop[tiflash] funcs:count(test.t.a)->Column#7, funcs:sum(test.t.a)->Column#8", + " └─TableFullScan_15 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ sum(a) from t", + "Plan": [ + "StreamAgg_16 1.00 root funcs:sum(Column#6)->Column#4", + "└─TableReader_17 1.00 root data:StreamAgg_8", + " └─StreamAgg_8 1.00 cop[tiflash] funcs:sum(test.t.a)->Column#6", + " └─TableFullScan_15 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ sum(a+1) from t", + "Plan": [ + "StreamAgg_16 1.00 root funcs:sum(Column#6)->Column#4", + "└─TableReader_17 1.00 root data:StreamAgg_8", + " └─StreamAgg_8 1.00 cop[tiflash] funcs:sum(plus(test.t.a, 1))->Column#6", + " └─TableFullScan_15 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ sum(isnull(a)) from t", + "Plan": [ + "StreamAgg_16 1.00 root funcs:sum(Column#6)->Column#4", + "└─TableReader_17 1.00 root data:StreamAgg_8", + " └─StreamAgg_8 1.00 cop[tiflash] funcs:sum(isnull(test.t.a))->Column#6", + " └─TableFullScan_15 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ READ_FROM_STORAGE(TIKV[t1], TIKV[t2]) */ * from t t1, t t2 where t1.a = t2.a", + "Plan": [ + "HashJoin_37 12487.50 root inner join, equal:[eq(test.t.a, test.t.a)]", + "├─TableReader_55(Build) 9990.00 root data:Selection_54", + "│ └─Selection_54 9990.00 cop[tikv] not(isnull(test.t.a))", + "│ └─TableFullScan_53 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", + "└─TableReader_49(Probe) 9990.00 root data:Selection_48", + " └─Selection_48 9990.00 cop[tikv] not(isnull(test.t.a))", + " └─TableFullScan_47 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ READ_FROM_STORAGE(TIKV[t1], TIFLASH[t2]) */ * from t t1, t t2 where t1.a = t2.a", + "Plan": [ + "HashJoin_23 12487.50 root inner join, equal:[eq(test.t.a, test.t.a)]", + "├─TableReader_31(Build) 9990.00 root data:Selection_30", + "│ └─Selection_30 9990.00 cop[tiflash] not(isnull(test.t.a))", + "│ └─TableFullScan_29 10000.00 cop[tiflash] table:t2 keep order:false, stats:pseudo", + "└─TableReader_34(Probe) 9990.00 root data:Selection_33", + " └─Selection_33 9990.00 cop[tikv] not(isnull(test.t.a))", + " └─TableFullScan_32 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)", + "Plan": [ + "TableReader_8 44.00 root data:TableRangeScan_7", + "└─TableRangeScan_7 44.00 cop[tiflash] table:tt range:(1,20), [30,55), keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ read_from_storage(tiflash[tt]) */ * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)", + "Plan": [ + "TableReader_6 44.00 root data:TableRangeScan_5", + "└─TableRangeScan_5 44.00 cop[tiflash] table:tt range:(1,20), [30,55), keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select * from ttt order by ttt.a desc", + "Plan": [ + "TableReader_13 10000.00 root data:TableFullScan_12", + "└─TableFullScan_12 10000.00 cop[tikv] table:ttt keep order:true, desc, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a desc", + "Plan": [ + "Sort_4 10000.00 root test.ttt.a:desc", + "└─TableReader_8 10000.00 root data:TableFullScan_7", + " └─TableFullScan_7 10000.00 cop[tiflash] table:ttt keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a", + "Plan": [ + "TableReader_11 10000.00 root data:TableFullScan_10", + "└─TableFullScan_10 10000.00 cop[tiflash] table:ttt keep order:true, stats:pseudo" + ], + "Warn": null + } + ] + }, + { + "Name": "TestReadFromStorageHintAndIsolationRead", + "Cases": [ + { + "SQL": "desc select /*+ read_from_storage(tikv[t], tiflash[t]) */ avg(a) from t", + "Plan": [ + "StreamAgg_20 1.00 root funcs:avg(Column#7, Column#8)->Column#4", + "└─IndexReader_21 1.00 root index:StreamAgg_8", + " └─StreamAgg_8 1.00 cop[tikv] funcs:avg(test.t.a)->Column#7", + " └─IndexFullScan_19 10000.00 cop[tikv] table:t, index:ia(a) keep order:false, stats:pseudo" + ], + "Warn": [ + "[planner:1815]Storage hints are conflict, you can only specify one storage type of table test.t" + ] + }, + { + "SQL": "desc select /*+ read_from_storage(tikv[t]) */ avg(a) from t", + "Plan": [ + "StreamAgg_20 1.00 root funcs:avg(Column#7, Column#8)->Column#4", + "└─IndexReader_21 1.00 root index:StreamAgg_8", + " └─StreamAgg_8 1.00 cop[tikv] funcs:avg(test.t.a)->Column#7", + " └─IndexFullScan_19 10000.00 cop[tikv] table:t, index:ia(a) keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t", + "Plan": [ + "StreamAgg_20 1.00 root funcs:avg(Column#7, Column#8)->Column#4", + "└─IndexReader_21 1.00 root index:StreamAgg_8", + " └─StreamAgg_8 1.00 cop[tikv] funcs:avg(test.t.a)->Column#7", + " └─IndexFullScan_19 10000.00 cop[tikv] table:t, index:ia(a) keep order:false, stats:pseudo" + ], + "Warn": [ + "[planner:1815]No available path for table test.t with the store type tiflash of the hint /*+ read_from_storage */, please check the status of the table replica and variable value of tidb_isolation_read_engines(map[0:{}])" + ] + } + ] + }, + { + "Name": "TestIsolationReadTiFlashNotChoosePointGet", + "Cases": [ + { + "SQL": "explain select * from t where t.a = 1", + "Result": [ + "TableReader_6 1.00 root data:TableRangeScan_5", + "└─TableRangeScan_5 1.00 cop[tiflash] table:t range:[1,1], keep order:false, stats:pseudo" + ] + }, + { + "SQL": "explain select * from t where t.a in (1, 2)", + "Result": [ + "TableReader_6 2.00 root data:TableRangeScan_5", + "└─TableRangeScan_5 2.00 cop[tiflash] table:t range:[1,1], [2,2], keep order:false, stats:pseudo" + ] + } + ] + }, + { + "Name": "TestIsolationReadTiFlashUseIndexHint", + "Cases": [ + { + "SQL": "explain select * from t", + "Plan": [ + "TableReader_5 10000.00 root data:TableFullScan_4", + "└─TableFullScan_4 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "explain select * from t use index();", + "Plan": [ + "TableReader_5 10000.00 root data:TableFullScan_4", + "└─TableFullScan_4 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "explain select /*+ use_index(t, idx)*/ * from t", + "Plan": [ + "TableReader_5 10000.00 root data:TableFullScan_4", + "└─TableFullScan_4 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ], + "Warn": [ + "TiDB doesn't support index in the isolation read engines(value: 'tiflash')" + ] + }, + { + "SQL": "explain select /*+ use_index(t)*/ * from t", + "Plan": [ + "TableReader_5 10000.00 root data:TableFullScan_4", + "└─TableFullScan_4 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + ], + "Warn": null + } + ] + } +] From ff3893bb235eda2e1756127743dd8848f6c8ef6e Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Fri, 27 Mar 2020 15:32:11 +0800 Subject: [PATCH 2/2] fix cherry-pick --- planner/core/integration_test.go | 40 +-- .../testdata/integration_serial_suite_in.json | 50 ---- .../integration_serial_suite_out.json | 242 ------------------ .../core/testdata/integration_suite_in.json | 9 + .../core/testdata/integration_suite_out.json | 39 +++ 5 files changed, 49 insertions(+), 331 deletions(-) delete mode 100644 planner/core/testdata/integration_serial_suite_in.json delete mode 100644 planner/core/testdata/integration_serial_suite_out.json diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 07144b70e3c9f..2564fad5d7716 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -416,44 +416,7 @@ func (s *testIntegrationSuite) TestReadFromStorageHintAndIsolationRead(c *C) { } } -<<<<<<< HEAD -======= -func (s *testIntegrationSerialSuite) TestIsolationReadTiFlashNotChoosePointGet(c *C) { - tk := testkit.NewTestKit(c, s.store) - - tk.MustExec("use test") - tk.MustExec("drop table if exists t") - tk.MustExec("create table t(a int, b int, primary key (a))") - - // Create virtual tiflash replica info. - dom := domain.GetDomain(tk.Se) - is := dom.InfoSchema() - db, exists := is.SchemaByName(model.NewCIStr("test")) - c.Assert(exists, IsTrue) - for _, tblInfo := range db.Tables { - tblInfo.TiFlashReplica = &model.TiFlashReplicaInfo{ - Count: 1, - Available: true, - } - } - - tk.MustExec("set @@session.tidb_isolation_read_engines=\"tiflash\"") - var input []string - var output []struct { - SQL string - Result []string - } - s.testData.GetTestCases(c, &input, &output) - for i, tt := range input { - s.testData.OnRecord(func() { - output[i].SQL = tt - output[i].Result = s.testData.ConvertRowsToStrings(tk.MustQuery(tt).Rows()) - }) - tk.MustQuery(tt).Check(testkit.Rows(output[i].Result...)) - } -} - -func (s *testIntegrationSerialSuite) TestIsolationReadTiFlashUseIndexHint(c *C) { +func (s *testIntegrationSuite) TestIsolationReadTiFlashUseIndexHint(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -492,7 +455,6 @@ func (s *testIntegrationSerialSuite) TestIsolationReadTiFlashUseIndexHint(c *C) } } ->>>>>>> 9dc6d9c... planner: check readEngines when building plan for index hint (#15723) func (s *testIntegrationSuite) TestPartitionTableStats(c *C) { tk := testkit.NewTestKit(c, s.store) diff --git a/planner/core/testdata/integration_serial_suite_in.json b/planner/core/testdata/integration_serial_suite_in.json deleted file mode 100644 index eba7a5c2da5db..0000000000000 --- a/planner/core/testdata/integration_serial_suite_in.json +++ /dev/null @@ -1,50 +0,0 @@ -[ - { - "name": "TestSelPushDownTiFlash", - "cases": [ - "explain select * from t where t.a > 1 and t.b = \"flash\" or t.a + 3 * t.a = 5", - "explain select * from t where cast(t.a as float) + 3 = 5.1" - ] - }, - { - "name": "TestReadFromStorageHint", - "cases": [ - "desc select avg(a) from t", - "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t", - "desc select /*+ read_from_storage(tiflash[t]) */ sum(a) from t", - "desc select /*+ read_from_storage(tiflash[t]) */ sum(a+1) from t", - "desc select /*+ read_from_storage(tiflash[t]) */ sum(isnull(a)) from t", - "desc select /*+ READ_FROM_STORAGE(TIKV[t1], TIKV[t2]) */ * from t t1, t t2 where t1.a = t2.a", - "desc select /*+ READ_FROM_STORAGE(TIKV[t1], TIFLASH[t2]) */ * from t t1, t t2 where t1.a = t2.a", - "desc select * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)", - "desc select /*+ read_from_storage(tiflash[tt]) */ * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)", - "desc select * from ttt order by ttt.a desc", - "desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a desc", - "desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a" - ] - }, - { - "name": "TestReadFromStorageHintAndIsolationRead", - "cases": [ - "desc select /*+ read_from_storage(tikv[t], tiflash[t]) */ avg(a) from t", - "desc select /*+ read_from_storage(tikv[t]) */ avg(a) from t", - "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t" - ] - }, - { - "name": "TestIsolationReadTiFlashNotChoosePointGet", - "cases": [ - "explain select * from t where t.a = 1", - "explain select * from t where t.a in (1, 2)" - ] - }, - { - "name": "TestIsolationReadTiFlashUseIndexHint", - "cases": [ - "explain select * from t", - "explain select * from t use index();", - "explain select /*+ use_index(t, idx)*/ * from t", - "explain select /*+ use_index(t)*/ * from t" - ] - } -] diff --git a/planner/core/testdata/integration_serial_suite_out.json b/planner/core/testdata/integration_serial_suite_out.json deleted file mode 100644 index 1e34ea443b96e..0000000000000 --- a/planner/core/testdata/integration_serial_suite_out.json +++ /dev/null @@ -1,242 +0,0 @@ -[ - { - "Name": "TestSelPushDownTiFlash", - "Cases": [ - { - "SQL": "explain select * from t where t.a > 1 and t.b = \"flash\" or t.a + 3 * t.a = 5", - "Plan": [ - "TableReader_7 8000.00 root data:Selection_6", - "└─Selection_6 8000.00 cop[tiflash] or(and(gt(test.t.a, 1), eq(test.t.b, \"flash\")), eq(plus(test.t.a, mul(3, test.t.a)), 5))", - " └─TableFullScan_5 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ] - }, - { - "SQL": "explain select * from t where cast(t.a as float) + 3 = 5.1", - "Plan": [ - "Selection_7 10000.00 root eq(plus(cast(test.t.a), 3), 5.1)", - "└─TableReader_6 10000.00 root data:TableFullScan_5", - " └─TableFullScan_5 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestReadFromStorageHint", - "Cases": [ - { - "SQL": "desc select avg(a) from t", - "Plan": [ - "StreamAgg_24 1.00 root funcs:avg(Column#7, Column#8)->Column#4", - "└─TableReader_25 1.00 root data:StreamAgg_8", - " └─StreamAgg_8 1.00 cop[tiflash] funcs:count(test.t.a)->Column#7, funcs:sum(test.t.a)->Column#8", - " └─TableFullScan_22 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t", - "Plan": [ - "StreamAgg_16 1.00 root funcs:avg(Column#7, Column#8)->Column#4", - "└─TableReader_17 1.00 root data:StreamAgg_8", - " └─StreamAgg_8 1.00 cop[tiflash] funcs:count(test.t.a)->Column#7, funcs:sum(test.t.a)->Column#8", - " └─TableFullScan_15 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ sum(a) from t", - "Plan": [ - "StreamAgg_16 1.00 root funcs:sum(Column#6)->Column#4", - "└─TableReader_17 1.00 root data:StreamAgg_8", - " └─StreamAgg_8 1.00 cop[tiflash] funcs:sum(test.t.a)->Column#6", - " └─TableFullScan_15 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ sum(a+1) from t", - "Plan": [ - "StreamAgg_16 1.00 root funcs:sum(Column#6)->Column#4", - "└─TableReader_17 1.00 root data:StreamAgg_8", - " └─StreamAgg_8 1.00 cop[tiflash] funcs:sum(plus(test.t.a, 1))->Column#6", - " └─TableFullScan_15 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ sum(isnull(a)) from t", - "Plan": [ - "StreamAgg_16 1.00 root funcs:sum(Column#6)->Column#4", - "└─TableReader_17 1.00 root data:StreamAgg_8", - " └─StreamAgg_8 1.00 cop[tiflash] funcs:sum(isnull(test.t.a))->Column#6", - " └─TableFullScan_15 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ READ_FROM_STORAGE(TIKV[t1], TIKV[t2]) */ * from t t1, t t2 where t1.a = t2.a", - "Plan": [ - "HashJoin_37 12487.50 root inner join, equal:[eq(test.t.a, test.t.a)]", - "├─TableReader_55(Build) 9990.00 root data:Selection_54", - "│ └─Selection_54 9990.00 cop[tikv] not(isnull(test.t.a))", - "│ └─TableFullScan_53 10000.00 cop[tikv] table:t2 keep order:false, stats:pseudo", - "└─TableReader_49(Probe) 9990.00 root data:Selection_48", - " └─Selection_48 9990.00 cop[tikv] not(isnull(test.t.a))", - " └─TableFullScan_47 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ READ_FROM_STORAGE(TIKV[t1], TIFLASH[t2]) */ * from t t1, t t2 where t1.a = t2.a", - "Plan": [ - "HashJoin_23 12487.50 root inner join, equal:[eq(test.t.a, test.t.a)]", - "├─TableReader_31(Build) 9990.00 root data:Selection_30", - "│ └─Selection_30 9990.00 cop[tiflash] not(isnull(test.t.a))", - "│ └─TableFullScan_29 10000.00 cop[tiflash] table:t2 keep order:false, stats:pseudo", - "└─TableReader_34(Probe) 9990.00 root data:Selection_33", - " └─Selection_33 9990.00 cop[tikv] not(isnull(test.t.a))", - " └─TableFullScan_32 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)", - "Plan": [ - "TableReader_8 44.00 root data:TableRangeScan_7", - "└─TableRangeScan_7 44.00 cop[tiflash] table:tt range:(1,20), [30,55), keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ read_from_storage(tiflash[tt]) */ * from tt where (tt.a > 1 and tt.a < 20) or (tt.a >= 30 and tt.a < 55)", - "Plan": [ - "TableReader_6 44.00 root data:TableRangeScan_5", - "└─TableRangeScan_5 44.00 cop[tiflash] table:tt range:(1,20), [30,55), keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select * from ttt order by ttt.a desc", - "Plan": [ - "TableReader_13 10000.00 root data:TableFullScan_12", - "└─TableFullScan_12 10000.00 cop[tikv] table:ttt keep order:true, desc, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a desc", - "Plan": [ - "Sort_4 10000.00 root test.ttt.a:desc", - "└─TableReader_8 10000.00 root data:TableFullScan_7", - " └─TableFullScan_7 10000.00 cop[tiflash] table:ttt keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ read_from_storage(tiflash[ttt]) */ * from ttt order by ttt.a", - "Plan": [ - "TableReader_11 10000.00 root data:TableFullScan_10", - "└─TableFullScan_10 10000.00 cop[tiflash] table:ttt keep order:true, stats:pseudo" - ], - "Warn": null - } - ] - }, - { - "Name": "TestReadFromStorageHintAndIsolationRead", - "Cases": [ - { - "SQL": "desc select /*+ read_from_storage(tikv[t], tiflash[t]) */ avg(a) from t", - "Plan": [ - "StreamAgg_20 1.00 root funcs:avg(Column#7, Column#8)->Column#4", - "└─IndexReader_21 1.00 root index:StreamAgg_8", - " └─StreamAgg_8 1.00 cop[tikv] funcs:avg(test.t.a)->Column#7", - " └─IndexFullScan_19 10000.00 cop[tikv] table:t, index:ia(a) keep order:false, stats:pseudo" - ], - "Warn": [ - "[planner:1815]Storage hints are conflict, you can only specify one storage type of table test.t" - ] - }, - { - "SQL": "desc select /*+ read_from_storage(tikv[t]) */ avg(a) from t", - "Plan": [ - "StreamAgg_20 1.00 root funcs:avg(Column#7, Column#8)->Column#4", - "└─IndexReader_21 1.00 root index:StreamAgg_8", - " └─StreamAgg_8 1.00 cop[tikv] funcs:avg(test.t.a)->Column#7", - " └─IndexFullScan_19 10000.00 cop[tikv] table:t, index:ia(a) keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t", - "Plan": [ - "StreamAgg_20 1.00 root funcs:avg(Column#7, Column#8)->Column#4", - "└─IndexReader_21 1.00 root index:StreamAgg_8", - " └─StreamAgg_8 1.00 cop[tikv] funcs:avg(test.t.a)->Column#7", - " └─IndexFullScan_19 10000.00 cop[tikv] table:t, index:ia(a) keep order:false, stats:pseudo" - ], - "Warn": [ - "[planner:1815]No available path for table test.t with the store type tiflash of the hint /*+ read_from_storage */, please check the status of the table replica and variable value of tidb_isolation_read_engines(map[0:{}])" - ] - } - ] - }, - { - "Name": "TestIsolationReadTiFlashNotChoosePointGet", - "Cases": [ - { - "SQL": "explain select * from t where t.a = 1", - "Result": [ - "TableReader_6 1.00 root data:TableRangeScan_5", - "└─TableRangeScan_5 1.00 cop[tiflash] table:t range:[1,1], keep order:false, stats:pseudo" - ] - }, - { - "SQL": "explain select * from t where t.a in (1, 2)", - "Result": [ - "TableReader_6 2.00 root data:TableRangeScan_5", - "└─TableRangeScan_5 2.00 cop[tiflash] table:t range:[1,1], [2,2], keep order:false, stats:pseudo" - ] - } - ] - }, - { - "Name": "TestIsolationReadTiFlashUseIndexHint", - "Cases": [ - { - "SQL": "explain select * from t", - "Plan": [ - "TableReader_5 10000.00 root data:TableFullScan_4", - "└─TableFullScan_4 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "explain select * from t use index();", - "Plan": [ - "TableReader_5 10000.00 root data:TableFullScan_4", - "└─TableFullScan_4 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ], - "Warn": null - }, - { - "SQL": "explain select /*+ use_index(t, idx)*/ * from t", - "Plan": [ - "TableReader_5 10000.00 root data:TableFullScan_4", - "└─TableFullScan_4 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ], - "Warn": [ - "TiDB doesn't support index in the isolation read engines(value: 'tiflash')" - ] - }, - { - "SQL": "explain select /*+ use_index(t)*/ * from t", - "Plan": [ - "TableReader_5 10000.00 root data:TableFullScan_4", - "└─TableFullScan_4 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" - ], - "Warn": null - } - ] - } -] diff --git a/planner/core/testdata/integration_suite_in.json b/planner/core/testdata/integration_suite_in.json index 839af504e7858..397c54f9ccaad 100644 --- a/planner/core/testdata/integration_suite_in.json +++ b/planner/core/testdata/integration_suite_in.json @@ -63,5 +63,14 @@ "desc select /*+ read_from_storage(tikv[t]) */ avg(a) from t", "desc select /*+ read_from_storage(tiflash[t]) */ avg(a) from t" ] + }, + { + "name": "TestIsolationReadTiFlashUseIndexHint", + "cases": [ + "explain select * from t", + "explain select * from t use index();", + "explain select /*+ use_index(t, idx)*/ * from t", + "explain select /*+ use_index(t)*/ * from t" + ] } ] diff --git a/planner/core/testdata/integration_suite_out.json b/planner/core/testdata/integration_suite_out.json index eb27a19c88832..29fe8582b7f39 100644 --- a/planner/core/testdata/integration_suite_out.json +++ b/planner/core/testdata/integration_suite_out.json @@ -247,5 +247,44 @@ ] } ] + }, + { + "Name": "TestIsolationReadTiFlashUseIndexHint", + "Cases": [ + { + "SQL": "explain select * from t", + "Plan": [ + "TableReader_5 10000.00 root data:TableScan_4", + "└─TableScan_4 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "explain select * from t use index();", + "Plan": [ + "TableReader_5 10000.00 root data:TableScan_4", + "└─TableScan_4 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" + ], + "Warn": null + }, + { + "SQL": "explain select /*+ use_index(t, idx)*/ * from t", + "Plan": [ + "TableReader_5 10000.00 root data:TableScan_4", + "└─TableScan_4 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" + ], + "Warn": [ + "TiDB doesn't support index in the isolation read engines(value: 'tiflash')" + ] + }, + { + "SQL": "explain select /*+ use_index(t)*/ * from t", + "Plan": [ + "TableReader_5 10000.00 root data:TableScan_4", + "└─TableScan_4 10000.00 cop[tiflash] table:t, range:[-inf,+inf], keep order:false, stats:pseudo" + ], + "Warn": null + } + ] } ]