From d323b8d3aefdb5c5b4fb700214c85c9ad919617a Mon Sep 17 00:00:00 2001 From: Yuanjia Zhang Date: Sat, 5 Nov 2022 10:58:00 +0800 Subject: [PATCH] planner: update some UTs to cost model2 (#38893) ref pingcap/tidb#35240 --- planner/core/enforce_mpp_test.go | 10 + planner/core/integration_test.go | 15 ++ planner/core/physical_plan_test.go | 1 + planner/core/plan_cost_ver2.go | 10 +- .../core/testdata/enforce_mpp_suite_out.json | 201 +++++++++--------- .../core/testdata/integration_suite_in.json | 12 +- .../core/testdata/integration_suite_out.json | 97 +++++---- 7 files changed, 185 insertions(+), 161 deletions(-) diff --git a/planner/core/enforce_mpp_test.go b/planner/core/enforce_mpp_test.go index 8b0582ee54492..dfd0a4fadbe3a 100644 --- a/planner/core/enforce_mpp_test.go +++ b/planner/core/enforce_mpp_test.go @@ -35,6 +35,7 @@ func TestSetVariables(t *testing.T) { tk := testkit.NewTestKit(t, store) // test value limit of tidb_opt_tiflash_concurrency_factor + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("set @@tidb_opt_tiflash_concurrency_factor = 0") tk.MustQuery("SHOW WARNINGS").Check(testkit.Rows("Warning 1292 Truncated incorrect tidb_opt_tiflash_concurrency_factor value: '0'")) tk.MustQuery(`select @@tidb_opt_tiflash_concurrency_factor`).Check(testkit.Rows("1")) @@ -52,6 +53,7 @@ func TestRowSizeInMPP(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a varchar(10), b varchar(20), c varchar(256))") tk.MustExec("insert into t values (space(10), space(20), space(256))") @@ -89,6 +91,7 @@ func TestEnforceMPP(t *testing.T) { // test query tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b int)") tk.MustExec("create index idx on t(a)") @@ -154,6 +157,7 @@ func TestEnforceMPPWarning1(t *testing.T) { // test query tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b int as (a+1), c enum('xx', 'yy'), d bit(1))") tk.MustExec("create index idx on t(a)") @@ -224,6 +228,7 @@ func TestEnforceMPPWarning2(t *testing.T) { // test query tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("CREATE TABLE t (a int, b char(20)) PARTITION BY HASH(a)") @@ -275,6 +280,7 @@ func TestEnforceMPPWarning3(t *testing.T) { // test query tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("CREATE TABLE t (a int, b char(20))") @@ -335,6 +341,7 @@ func TestEnforceMPPWarning4(t *testing.T) { // test table tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("CREATE TABLE t(a int primary key)") tk.MustExec("drop table if exists s") @@ -388,6 +395,7 @@ func TestMPP2PhaseAggPushDown(t *testing.T) { // test table tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists c") tk.MustExec("drop table if exists o") tk.MustExec("create table c(c_id bigint)") @@ -441,6 +449,7 @@ func TestMPPSkewedGroupDistinctRewrite(t *testing.T) { // test table tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b bigint not null, c bigint, d date, e varchar(20))") @@ -492,6 +501,7 @@ func TestMPPSingleDistinct3Stage(t *testing.T) { // test table tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b bigint not null, c bigint, d date, e varchar(20) collate utf8mb4_general_ci)") diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index 2dbfac7a1c9ac..44a9101613d1e 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -50,6 +50,7 @@ func TestShowSubquery(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a varchar(10), b int, c int)") tk.MustQuery("show columns from t where true").Check(testkit.Rows( @@ -123,6 +124,7 @@ func TestAggPushDownLeftJoin(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists customer") tk.MustExec("create table customer (C_CUSTKEY bigint(20) NOT NULL, C_NAME varchar(25) NOT NULL, " + "C_ADDRESS varchar(25) NOT NULL, PRIMARY KEY (`C_CUSTKEY`) /*T![clustered_index] CLUSTERED */)") @@ -165,6 +167,7 @@ func TestPushLimitDownIndexLookUpReader(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("set @@session.tidb_executor_concurrency = 4;") tk.MustExec("set @@session.tidb_hash_join_concurrency = 5;") tk.MustExec("set @@session.tidb_distsql_scan_concurrency = 15;") @@ -195,6 +198,7 @@ func TestAggColumnPrune(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int)") tk.MustExec("insert into t values(1),(2)") @@ -219,6 +223,7 @@ func TestIsFromUnixtimeNullRejective(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec(`drop table if exists t;`) tk.MustExec(`create table t(a bigint, b bigint);`) var input []string @@ -376,6 +381,7 @@ func TestSimplifyOuterJoinWithCast(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int not null, b datetime default null)") @@ -1567,6 +1573,7 @@ func TestMaxMinEliminate(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int primary key)") @@ -1606,6 +1613,7 @@ func TestIndexJoinUniqueCompositeIndex(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("use test") tk.MustExec("drop table if exists t1, t2") tk.Session().GetSessionVars().EnableClusteredIndex = variable.ClusteredIndexDefModeIntOnly @@ -1764,6 +1772,7 @@ func TestSubqueryWithTopN(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("use test") tk.MustExec("drop table if exists t") tk.MustExec("create table t(a int, b int)") @@ -2127,6 +2136,7 @@ func TestIndexJoinInnerIndexNDV(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t1, t2") tk.MustExec("create table t1(a int not null, b int not null, c int not null)") tk.MustExec("create table t2(a int not null, b int not null, c int not null, index idx1(a,b), index idx2(c))") @@ -4283,6 +4293,7 @@ func TestPushDownProjectionForTiFlashCoprocessor(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t (a int, b real, i int, id int, value decimal(6,3), name char(128), d decimal(6,3), s char(128), t datetime, c bigint as ((a+1)) virtual, e real as ((b+a)))") tk.MustExec("analyze table t") @@ -4323,6 +4334,7 @@ func TestPushDownProjectionForTiFlash(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t (id int, value decimal(6,3), name char(128))") tk.MustExec("analyze table t") @@ -4363,6 +4375,7 @@ func TestPushDownSelectionForMPP(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t (id int, value decimal(6,3), name char(128))") tk.MustExec("analyze table t") @@ -4405,6 +4418,7 @@ func TestPushDownProjectionForMPP(t *testing.T) { store := testkit.CreateMockStore(t) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t") tk.MustExec("create table t (id int, value decimal(6,3), name char(128))") tk.MustExec("analyze table t") @@ -4447,6 +4461,7 @@ func TestReorderSimplifiedOuterJoins(t *testing.T) { tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("drop table if exists t1,t2,t3") tk.MustExec("create table t1 (pk char(32) primary key nonclustered, col1 char(32), col2 varchar(40), col3 char(32), key (col1), key (col3), key (col2,col3), key (col1,col3))") tk.MustExec("create table t2 (pk char(32) primary key nonclustered, col1 varchar(100))") diff --git a/planner/core/physical_plan_test.go b/planner/core/physical_plan_test.go index d4f52dc94aa18..5bf4d3ab7cf3f 100644 --- a/planner/core/physical_plan_test.go +++ b/planner/core/physical_plan_test.go @@ -804,6 +804,7 @@ func TestMPPHints(t *testing.T) { store := testkit.CreateMockStore(t, withMockTiFlash(2)) tk := testkit.NewTestKit(t, store) tk.MustExec("use test") + tk.MustExec("set tidb_cost_model_version=2") tk.MustExec("create table t (a int, b int, c int)") tk.MustExec("alter table t set tiflash replica 1") tk.MustExec("set @@session.tidb_allow_mpp=ON") diff --git a/planner/core/plan_cost_ver2.go b/planner/core/plan_cost_ver2.go index ef4be46bee174..27960e9c10091 100644 --- a/planner/core/plan_cost_ver2.go +++ b/planner/core/plan_cost_ver2.go @@ -713,7 +713,7 @@ func netCostVer2(option *PlanCostOption, rows, rowSize float64, netFactor costVe func filterCostVer2(option *PlanCostOption, rows float64, filters []expression.Expression, cpuFactor costVer2Factor) costVer2 { numFuncs := numFunctions(filters) return newCostVer2(option, cpuFactor, - rows*float64(numFuncs)*cpuFactor.Value, + rows*numFuncs*cpuFactor.Value, "cpu(%v*filters(%v)*%v)", rows, numFuncs, cpuFactor) } @@ -727,15 +727,17 @@ func aggCostVer2(option *PlanCostOption, rows float64, aggFuncs []*aggregation.A func groupCostVer2(option *PlanCostOption, rows float64, groupItems []expression.Expression, cpuFactor costVer2Factor) costVer2 { numFuncs := numFunctions(groupItems) return newCostVer2(option, cpuFactor, - rows*float64(numFuncs)*cpuFactor.Value, + rows*numFuncs*cpuFactor.Value, "group(%v*cols(%v)*%v)", rows, numFuncs, cpuFactor) } -func numFunctions(exprs []expression.Expression) int { - num := 0 +func numFunctions(exprs []expression.Expression) float64 { + num := 0.0 for _, e := range exprs { if _, ok := e.(*expression.ScalarFunction); ok { num++ + } else { // Column and Constant + num += 0.01 // an empirical value } } return num diff --git a/planner/core/testdata/enforce_mpp_suite_out.json b/planner/core/testdata/enforce_mpp_suite_out.json index 96fa1db985ac0..20f349233aed4 100644 --- a/planner/core/testdata/enforce_mpp_suite_out.json +++ b/planner/core/testdata/enforce_mpp_suite_out.json @@ -31,31 +31,30 @@ { "SQL": "explain format='verbose' select count(*) from t where a=1", "Plan": [ - "StreamAgg_24 1.00 35.88 root funcs:count(Column#6)->Column#4", - "└─IndexReader_25 1.00 32.88 root index:StreamAgg_9", - " └─StreamAgg_9 1.00 465.00 cop[tikv] funcs:count(1)->Column#6", - " └─IndexRangeScan_23 10.00 435.00 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" + "StreamAgg_24 1.00 217.09 root funcs:count(Column#6)->Column#4", + "└─IndexReader_25 1.00 167.19 root index:StreamAgg_9", + " └─StreamAgg_9 1.00 2476.20 cop[tikv] funcs:count(1)->Column#6", + " └─IndexRangeScan_23 10.00 1977.20 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" ], "Warn": null }, { "SQL": "explain format='verbose' select /*+ read_from_storage(tikv[t]) */ count(*) from t where a=1", "Plan": [ - "StreamAgg_17 1.00 35.88 root funcs:count(Column#6)->Column#4", - "└─IndexReader_18 1.00 32.88 root index:StreamAgg_9", - " └─StreamAgg_9 1.00 465.00 cop[tikv] funcs:count(1)->Column#6", - " └─IndexRangeScan_16 10.00 435.00 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" + "StreamAgg_17 1.00 217.09 root funcs:count(Column#6)->Column#4", + "└─IndexReader_18 1.00 167.19 root index:StreamAgg_9", + " └─StreamAgg_9 1.00 2476.20 cop[tikv] funcs:count(1)->Column#6", + " └─IndexRangeScan_16 10.00 1977.20 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" ], "Warn": null }, { "SQL": "explain format='verbose' select /*+ read_from_storage(tiflash[t]) */ count(*) from t where a=1", "Plan": [ - "StreamAgg_20 1.00 19006.88 root funcs:count(Column#6)->Column#4", - "└─TableReader_21 1.00 19003.88 root data:StreamAgg_9", - " └─StreamAgg_9 1.00 285030.00 batchCop[tiflash] funcs:count(1)->Column#6", - " └─Selection_19 10.00 285000.00 batchCop[tiflash] eq(test.t.a, 1)", - " └─TableFullScan_18 10000.00 255000.00 batchCop[tiflash] table:t keep order:false, stats:pseudo" + "StreamAgg_10 1.00 65360.67 root funcs:count(1)->Column#4", + "└─TableReader_24 10.00 64861.67 root data:Selection_23", + " └─Selection_23 10.00 972291.38 cop[tiflash] eq(test.t.a, 1)", + " └─TableFullScan_22 10000.00 948291.38 cop[tiflash] table:t keep order:false, stats:pseudo" ], "Warn": null }, @@ -72,32 +71,30 @@ { "SQL": "explain format='verbose' select count(*) from t where a=1", "Plan": [ - "StreamAgg_31 1.00 35.88 root funcs:count(Column#7)->Column#4", - "└─IndexReader_32 1.00 32.88 root index:StreamAgg_11", - " └─StreamAgg_11 1.00 465.00 cop[tikv] funcs:count(1)->Column#7", - " └─IndexRangeScan_30 10.00 435.00 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" + "StreamAgg_31 1.00 217.09 root funcs:count(Column#7)->Column#4", + "└─IndexReader_32 1.00 167.19 root index:StreamAgg_11", + " └─StreamAgg_11 1.00 2476.20 cop[tikv] funcs:count(1)->Column#7", + " └─IndexRangeScan_30 10.00 1977.20 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" ], "Warn": null }, { "SQL": "explain format='verbose' select /*+ read_from_storage(tikv[t]) */ count(*) from t where a=1", "Plan": [ - "StreamAgg_19 1.00 35.88 root funcs:count(Column#6)->Column#4", - "└─IndexReader_20 1.00 32.88 root index:StreamAgg_11", - " └─StreamAgg_11 1.00 465.00 cop[tikv] funcs:count(1)->Column#6", - " └─IndexRangeScan_18 10.00 435.00 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" + "StreamAgg_19 1.00 217.09 root funcs:count(Column#6)->Column#4", + "└─IndexReader_20 1.00 167.19 root index:StreamAgg_11", + " └─StreamAgg_11 1.00 2476.20 cop[tikv] funcs:count(1)->Column#6", + " └─IndexRangeScan_18 10.00 1977.20 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" ], "Warn": null }, { "SQL": "explain format='verbose' select /*+ read_from_storage(tiflash[t]) */ count(*) from t where a=1", "Plan": [ - "HashAgg_22 1.00 11910.73 root funcs:count(Column#6)->Column#4", - "└─TableReader_24 1.00 11877.13 root data:ExchangeSender_23", - " └─ExchangeSender_23 1.00 285030.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashAgg_10 1.00 285030.00 mpp[tiflash] funcs:count(1)->Column#6", - " └─Selection_21 10.00 285000.00 mpp[tiflash] eq(test.t.a, 1)", - " └─TableFullScan_20 10000.00 255000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" + "StreamAgg_12 1.00 65360.67 root funcs:count(1)->Column#4", + "└─TableReader_31 10.00 64861.67 root data:Selection_30", + " └─Selection_30 10.00 972291.38 cop[tiflash] eq(test.t.a, 1)", + " └─TableFullScan_29 10000.00 948291.38 cop[tiflash] table:t keep order:false, stats:pseudo" ], "Warn": null }, @@ -109,34 +106,30 @@ { "SQL": "explain format='verbose' select count(*) from t where a=1", "Plan": [ - "HashAgg_25 1.00 33.89 root funcs:count(Column#6)->Column#4", - "└─TableReader_27 1.00 0.29 root data:ExchangeSender_26", - " └─ExchangeSender_26 1.00 285030.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashAgg_10 1.00 285030.00 mpp[tiflash] funcs:count(1)->Column#6", - " └─Selection_24 10.00 285000.00 mpp[tiflash] eq(test.t.a, 1)", - " └─TableFullScan_23 10000.00 255000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" + "StreamAgg_31 1.00 217.09 root funcs:count(Column#7)->Column#4", + "└─IndexReader_32 1.00 167.19 root index:StreamAgg_11", + " └─StreamAgg_11 1.00 2476.20 cop[tikv] funcs:count(1)->Column#7", + " └─IndexRangeScan_30 10.00 1977.20 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" ], "Warn": null }, { "SQL": "explain format='verbose' select /*+ read_from_storage(tikv[t]) */ count(*) from t where a=1", "Plan": [ - "StreamAgg_19 1.00 35.88 root funcs:count(Column#6)->Column#4", - "└─IndexReader_20 1.00 32.88 root index:StreamAgg_11", - " └─StreamAgg_11 1.00 465.00 cop[tikv] funcs:count(1)->Column#6", - " └─IndexRangeScan_18 10.00 435.00 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" + "StreamAgg_19 1.00 217.09 root funcs:count(Column#6)->Column#4", + "└─IndexReader_20 1.00 167.19 root index:StreamAgg_11", + " └─StreamAgg_11 1.00 2476.20 cop[tikv] funcs:count(1)->Column#6", + " └─IndexRangeScan_18 10.00 1977.20 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" ], "Warn": null }, { "SQL": "explain format='verbose' select /*+ read_from_storage(tiflash[t]) */ count(*) from t where a=1", "Plan": [ - "HashAgg_22 1.00 33.89 root funcs:count(Column#6)->Column#4", - "└─TableReader_24 1.00 0.29 root data:ExchangeSender_23", - " └─ExchangeSender_23 1.00 285030.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashAgg_10 1.00 285030.00 mpp[tiflash] funcs:count(1)->Column#6", - " └─Selection_21 10.00 285000.00 mpp[tiflash] eq(test.t.a, 1)", - " └─TableFullScan_20 10000.00 255000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" + "StreamAgg_12 1.00 65360.67 root funcs:count(1)->Column#4", + "└─TableReader_31 10.00 64861.67 root data:Selection_30", + " └─Selection_30 10.00 972291.38 cop[tiflash] eq(test.t.a, 1)", + " └─TableFullScan_29 10000.00 948291.38 cop[tiflash] table:t keep order:false, stats:pseudo" ], "Warn": null }, @@ -148,22 +141,20 @@ { "SQL": "explain format='verbose' select count(*) from t where a=1", "Plan": [ - "HashAgg_25 1.00 33.60 root funcs:count(Column#6)->Column#4", - "└─TableReader_27 1.00 0.00 root data:ExchangeSender_26", - " └─ExchangeSender_26 1.00 285030.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashAgg_10 1.00 285030.00 mpp[tiflash] funcs:count(1)->Column#6", - " └─Selection_24 10.00 285000.00 mpp[tiflash] eq(test.t.a, 1)", - " └─TableFullScan_23 10000.00 255000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" + "StreamAgg_31 1.00 217.09 root funcs:count(Column#7)->Column#4", + "└─IndexReader_32 1.00 167.19 root index:StreamAgg_11", + " └─StreamAgg_11 1.00 2476.20 cop[tikv] funcs:count(1)->Column#7", + " └─IndexRangeScan_30 10.00 1977.20 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" ], "Warn": null }, { "SQL": "explain format='verbose' select /*+ read_from_storage(tikv[t]) */ count(*) from t where a=1", "Plan": [ - "StreamAgg_19 1.00 35.88 root funcs:count(Column#6)->Column#4", - "└─IndexReader_20 1.00 32.88 root index:StreamAgg_11", - " └─StreamAgg_11 1.00 465.00 cop[tikv] funcs:count(1)->Column#6", - " └─IndexRangeScan_18 10.00 435.00 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" + "StreamAgg_19 1.00 217.09 root funcs:count(Column#6)->Column#4", + "└─IndexReader_20 1.00 167.19 root index:StreamAgg_11", + " └─StreamAgg_11 1.00 2476.20 cop[tikv] funcs:count(1)->Column#6", + " └─IndexRangeScan_18 10.00 1977.20 cop[tikv] table:t, index:idx(a) range:[1,1], keep order:false, stats:pseudo" ], "Warn": [ "MPP mode may be blocked because you have set a hint to read table `t` from TiKV." @@ -172,12 +163,12 @@ { "SQL": "explain format='verbose' select /*+ read_from_storage(tiflash[t]) */ count(*) from t where a=1", "Plan": [ - "HashAgg_22 1.00 33.60 root funcs:count(Column#6)->Column#4", + "HashAgg_22 1.00 39930.30 root funcs:count(Column#6)->Column#4", "└─TableReader_24 1.00 0.00 root data:ExchangeSender_23", - " └─ExchangeSender_23 1.00 285030.00 mpp[tiflash] ExchangeType: PassThrough", - " └─HashAgg_10 1.00 285030.00 mpp[tiflash] funcs:count(1)->Column#6", - " └─Selection_21 10.00 285000.00 mpp[tiflash] eq(test.t.a, 1)", - " └─TableFullScan_20 10000.00 255000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" + " └─ExchangeSender_23 1.00 974211.94 mpp[tiflash] ExchangeType: PassThrough", + " └─HashAgg_10 1.00 974211.94 mpp[tiflash] funcs:count(1)->Column#6", + " └─Selection_21 10.00 972291.38 mpp[tiflash] eq(test.t.a, 1)", + " └─TableFullScan_20 10000.00 948291.38 mpp[tiflash] table:t keep order:false, stats:pseudo" ], "Warn": null } @@ -296,10 +287,10 @@ " └─TableRowIDScan(Probe) 10.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "Warn": [ - "Aggregation can not be pushed to tiflash because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now", "Aggregation can not be pushed to tiflash because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now", "Aggregation can not be pushed to tikv because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now", - "Aggregation can not be pushed to tiflash because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now", + "Aggregation can not be pushed to tikv because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now", + "Aggregation can not be pushed to tikv because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now", "Aggregation can not be pushed to tiflash because expressions of AggFunc `count` contain virtual column or correlated column, which is not supported now" ] }, @@ -313,21 +304,19 @@ ], "Warn": [ "Aggregation can not be pushed to tiflash because groupByItems contain virtual columns, which is not supported now", - "Aggregation can not be pushed to tiflash because groupByItems contain virtual columns, which is not supported now", + "Aggregation can not be pushed to tikv because groupByItems contain virtual columns, which is not supported now", "Aggregation can not be pushed to tiflash because groupByItems contain virtual columns, which is not supported now" ] }, { "SQL": "EXPLAIN format = 'brief' SELECT count(a) from t group by md5(a); -- 10. scalar func not supported", "Plan": [ - "HashAgg 8000.00 root group by:Column#8, funcs:count(Column#7)->Column#6", - "└─Projection 10000.00 root test.t.a, md5(cast(test.t.a, var_string(20)))->Column#8", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + "HashAgg 8000.00 root group by:Column#7, funcs:count(Column#8)->Column#6", + "└─IndexReader 8000.00 root index:HashAgg", + " └─HashAgg 8000.00 cop[tikv] group by:md5(cast(test.t.a, var_string(20))), funcs:count(test.t.a)->Column#8", + " └─IndexFullScan 10000.00 cop[tikv] table:t, index:idx(a) keep order:false, stats:pseudo" ], "Warn": [ - "Scalar function 'md5'(signature: MD5, return type: var_string(32)) is not supported to push down to tiflash now.", - "Aggregation can not be pushed to tiflash because groupByItems contain unsupported exprs", "Scalar function 'md5'(signature: MD5, return type: var_string(32)) is not supported to push down to tiflash now.", "Aggregation can not be pushed to tiflash because groupByItems contain unsupported exprs", "Scalar function 'md5'(signature: MD5, return type: var_string(32)) is not supported to push down to tiflash now.", @@ -337,10 +326,11 @@ { "SQL": "EXPLAIN format = 'brief' SELECT count(a) from t where c=1; -- 11. type not supported", "Plan": [ - "StreamAgg 1.00 root funcs:count(test.t.a)->Column#6", - "└─Selection 10.00 root eq(test.t.c, 1)", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + "StreamAgg 1.00 root funcs:count(Column#8)->Column#6", + "└─TableReader 1.00 root data:StreamAgg", + " └─StreamAgg 1.00 cop[tikv] funcs:count(test.t.a)->Column#8", + " └─Selection 10.00 cop[tikv] eq(test.t.c, 1)", + " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "Warn": [ "Expression about 'test.t.c' can not be pushed to TiFlash because it contains unsupported calculation of type 'enum'.", @@ -353,10 +343,11 @@ { "SQL": "EXPLAIN format = 'brief' SELECT count(a) from t where d=1; -- 11.1. type not supported", "Plan": [ - "StreamAgg 1.00 root funcs:count(test.t.a)->Column#6", - "└─Selection 10.00 root eq(test.t.d, 1)", - " └─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + "StreamAgg 1.00 root funcs:count(Column#8)->Column#6", + "└─TableReader 1.00 root data:StreamAgg", + " └─StreamAgg 1.00 cop[tikv] funcs:count(test.t.a)->Column#8", + " └─Selection 10.00 cop[tikv] eq(test.t.d, 1)", + " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ], "Warn": [ "Expression about 'test.t.d' can not be pushed to TiFlash because it contains unsupported calculation of type 'bit'.", @@ -384,11 +375,10 @@ { "SQL": "EXPLAIN SELECT count(*) from t where a=1; -- 1. static partition prune", "Plan": [ - "StreamAgg_32 1.00 root funcs:count(Column#6)->Column#4", - "└─TableReader_33 1.00 root data:StreamAgg_13", - " └─StreamAgg_13 1.00 batchCop[tiflash] funcs:count(1)->Column#6", - " └─Selection_31 10.00 batchCop[tiflash] eq(test.t.a, 1)", - " └─TableFullScan_30 10000.00 batchCop[tiflash] table:t, partition:p0 keep order:false, stats:pseudo" + "StreamAgg_14 1.00 root funcs:count(1)->Column#4", + "└─TableReader_39 10.00 root data:Selection_38", + " └─Selection_38 10.00 cop[tiflash] eq(test.t.a, 1)", + " └─TableFullScan_37 10000.00 cop[tiflash] table:t, partition:p0 keep order:false, stats:pseudo" ], "Warn": [ "MPP mode may be blocked because table `t`is a partition table which is not supported when `@@tidb_partition_prune_mode=static`." @@ -650,13 +640,14 @@ "└─TableReader_35 9990.00 root data:ExchangeSender_34", " └─ExchangeSender_34 9990.00 mpp[tiflash] ExchangeType: PassThrough", " └─HashJoin_14 9990.00 mpp[tiflash] inner join, equal:[eq(test.c.c_id, test.o.c_id)]", - " ├─ExchangeReceiver_26(Build) 8000.00 mpp[tiflash] ", - " │ └─ExchangeSender_25 8000.00 mpp[tiflash] ExchangeType: Broadcast", - " │ └─Projection_24 8000.00 mpp[tiflash] Column#7, test.o.c_id", - " │ └─HashAgg_19 8000.00 mpp[tiflash] group by:test.o.c_id, funcs:count(1)->Column#7, funcs:firstrow(test.o.c_id)->test.o.c_id", - " │ └─ExchangeReceiver_23 10000.00 mpp[tiflash] ", - " │ └─ExchangeSender_22 10000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.o.c_id, collate: binary]", - " │ └─TableFullScan_21 10000.00 mpp[tiflash] table:o keep order:false, stats:pseudo", + " ├─ExchangeReceiver_33(Build) 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender_32 8000.00 mpp[tiflash] ExchangeType: Broadcast", + " │ └─Projection_28 8000.00 mpp[tiflash] Column#7, test.o.c_id", + " │ └─HashAgg_29 8000.00 mpp[tiflash] group by:test.o.c_id, funcs:sum(Column#8)->Column#7, funcs:firstrow(test.o.c_id)->test.o.c_id", + " │ └─ExchangeReceiver_31 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender_30 8000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.o.c_id, collate: binary]", + " │ └─HashAgg_20 8000.00 mpp[tiflash] group by:test.o.c_id, funcs:count(1)->Column#8", + " │ └─TableFullScan_27 10000.00 mpp[tiflash] table:o keep order:false, stats:pseudo", " └─Selection_18(Probe) 9990.00 mpp[tiflash] not(isnull(test.c.c_id))", " └─TableFullScan_17 10000.00 mpp[tiflash] table:c keep order:false, stats:pseudo" ], @@ -673,13 +664,14 @@ " └─ExchangeReceiver_71 9990.00 mpp[tiflash] ", " └─ExchangeSender_70 9990.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.o.o_id, collate: binary]", " └─HashJoin_69 9990.00 mpp[tiflash] inner join, equal:[eq(test.c.c_id, test.o.c_id)]", - " ├─ExchangeReceiver_27(Build) 8000.00 mpp[tiflash] ", - " │ └─ExchangeSender_26 8000.00 mpp[tiflash] ExchangeType: Broadcast", - " │ └─Projection_25 8000.00 mpp[tiflash] Column#7, Column#8, test.o.o_id, test.o.c_id", - " │ └─HashAgg_20 8000.00 mpp[tiflash] group by:test.o.c_id, test.o.o_id, funcs:count(1)->Column#7, funcs:firstrow(test.o.o_id)->Column#8, funcs:firstrow(test.o.o_id)->test.o.o_id, funcs:firstrow(test.o.c_id)->test.o.c_id", - " │ └─ExchangeReceiver_24 10000.00 mpp[tiflash] ", - " │ └─ExchangeSender_23 10000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.o.o_id, collate: binary], [name: test.o.c_id, collate: binary]", - " │ └─TableFullScan_22 10000.00 mpp[tiflash] table:o keep order:false, stats:pseudo", + " ├─ExchangeReceiver_34(Build) 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender_33 8000.00 mpp[tiflash] ExchangeType: Broadcast", + " │ └─Projection_29 8000.00 mpp[tiflash] Column#7, Column#8, test.o.o_id, test.o.c_id", + " │ └─HashAgg_30 8000.00 mpp[tiflash] group by:test.o.c_id, test.o.o_id, funcs:sum(Column#9)->Column#7, funcs:firstrow(test.o.o_id)->Column#8, funcs:firstrow(test.o.o_id)->test.o.o_id, funcs:firstrow(test.o.c_id)->test.o.c_id", + " │ └─ExchangeReceiver_32 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender_31 8000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.o.o_id, collate: binary], [name: test.o.c_id, collate: binary]", + " │ └─HashAgg_21 8000.00 mpp[tiflash] group by:test.o.c_id, test.o.o_id, funcs:count(1)->Column#9", + " │ └─TableFullScan_28 10000.00 mpp[tiflash] table:o keep order:false, stats:pseudo", " └─Selection_19(Probe) 9990.00 mpp[tiflash] not(isnull(test.c.c_id))", " └─TableFullScan_18 10000.00 mpp[tiflash] table:c keep order:false, stats:pseudo" ], @@ -696,13 +688,14 @@ " └─ExchangeReceiver_71 9990.00 mpp[tiflash] ", " └─ExchangeSender_70 9990.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.o.c_id, collate: binary]", " └─HashJoin_69 9990.00 mpp[tiflash] inner join, equal:[eq(test.c.c_id, test.o.c_id)]", - " ├─ExchangeReceiver_27(Build) 8000.00 mpp[tiflash] ", - " │ └─ExchangeSender_26 8000.00 mpp[tiflash] ExchangeType: Broadcast", - " │ └─Projection_25 8000.00 mpp[tiflash] Column#7, Column#8, test.o.c_id", - " │ └─HashAgg_20 8000.00 mpp[tiflash] group by:test.o.c_id, funcs:count(1)->Column#7, funcs:firstrow(test.o.c_id)->Column#8, funcs:firstrow(test.o.c_id)->test.o.c_id", - " │ └─ExchangeReceiver_24 10000.00 mpp[tiflash] ", - " │ └─ExchangeSender_23 10000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.o.c_id, collate: binary]", - " │ └─TableFullScan_22 10000.00 mpp[tiflash] table:o keep order:false, stats:pseudo", + " ├─ExchangeReceiver_34(Build) 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender_33 8000.00 mpp[tiflash] ExchangeType: Broadcast", + " │ └─Projection_29 8000.00 mpp[tiflash] Column#7, Column#8, test.o.c_id", + " │ └─HashAgg_30 8000.00 mpp[tiflash] group by:test.o.c_id, funcs:sum(Column#9)->Column#7, funcs:firstrow(test.o.c_id)->Column#8, funcs:firstrow(test.o.c_id)->test.o.c_id", + " │ └─ExchangeReceiver_32 8000.00 mpp[tiflash] ", + " │ └─ExchangeSender_31 8000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.o.c_id, collate: binary]", + " │ └─HashAgg_21 8000.00 mpp[tiflash] group by:test.o.c_id, funcs:count(1)->Column#9", + " │ └─TableFullScan_28 10000.00 mpp[tiflash] table:o keep order:false, stats:pseudo", " └─Selection_19(Probe) 9990.00 mpp[tiflash] not(isnull(test.c.c_id))", " └─TableFullScan_18 10000.00 mpp[tiflash] table:c keep order:false, stats:pseudo" ], @@ -1169,10 +1162,10 @@ { "SQL": "EXPLAIN select count(distinct b), json_objectagg(d,c) from t;", "Plan": [ - "StreamAgg_7 1.00 root funcs:count(distinct Column#9)->Column#7, funcs:json_objectagg(Column#10, Column#11)->Column#8", + "HashAgg_6 1.00 root funcs:count(distinct Column#9)->Column#7, funcs:json_objectagg(Column#10, Column#11)->Column#8", "└─Projection_16 10000.00 root test.t.b, cast(test.t.d, var_string(10))->Column#10, test.t.c", - " └─TableReader_15 10000.00 root data:TableFullScan_14", - " └─TableFullScan_14 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + " └─TableReader_11 10000.00 root data:TableFullScan_10", + " └─TableFullScan_10 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" ], "Warn": [ "Aggregation can not be pushed to tiflash because AggFunc `json_objectagg` is not supported now", diff --git a/planner/core/testdata/integration_suite_in.json b/planner/core/testdata/integration_suite_in.json index 66b6afdeb026e..d820bdc629197 100644 --- a/planner/core/testdata/integration_suite_in.json +++ b/planner/core/testdata/integration_suite_in.json @@ -745,12 +745,12 @@ { "name": "TestPushDownProjectionForTiFlash", "cases": [ - "desc format = 'brief' select /*+ hash_agg()*/ count(b) from (select id + 1 as b from t)A", - "desc format = 'brief' select /*+ hash_agg()*/ count(*) from (select id + 1 as b from t)A", - "desc format = 'brief' select /*+ hash_agg()*/ sum(b) from (select id + 1 as b from t)A", - "desc format = 'brief' select /*+ stream_agg()*/ count(b) from (select id + 1 as b from t)A", - "desc format = 'brief' select /*+ stream_agg()*/ count(*) from (select id + 1 as b from t)A", - "desc format = 'brief' select /*+ stream_agg()*/ sum(b) from (select id + 1 as b from t)A", + "desc format = 'brief' select /*+ hash_agg()*/ count(b) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", + "desc format = 'brief' select /*+ hash_agg()*/ count(*) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", + "desc format = 'brief' select /*+ hash_agg()*/ sum(b) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", + "desc format = 'brief' select /*+ stream_agg()*/ count(b) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", + "desc format = 'brief' select /*+ stream_agg()*/ count(*) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", + "desc format = 'brief' select /*+ stream_agg()*/ sum(b) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", "desc format = 'brief' select * from (select id-2 as b from t) B join (select id-2 as b from t) A on A.b=B.b", "desc format = 'brief' select * from t join (select id-2 as b from t) A on A.b=t.id", "desc format = 'brief' select * from t left join (select id-2 as b from t) A on A.b=t.id", diff --git a/planner/core/testdata/integration_suite_out.json b/planner/core/testdata/integration_suite_out.json index b6635a1cfac75..bc36df6a8f5e4 100644 --- a/planner/core/testdata/integration_suite_out.json +++ b/planner/core/testdata/integration_suite_out.json @@ -14,11 +14,12 @@ { "SQL": "explain format = 'brief' select * from tbl use index(idx_b_c) where b > 1 order by b desc limit 2,1", "Plan": [ - "TopN 1.00 root test.tbl.b:desc, offset:2, count:1", - "└─IndexLookUp 3.00 root ", - " ├─TopN(Build) 3.00 cop[tikv] test.tbl.b:desc, offset:0, count:3", - " │ └─IndexRangeScan 4.00 cop[tikv] table:tbl, index:idx_b_c(b, c) range:(1,+inf], keep order:false", - " └─TableRowIDScan(Probe) 3.00 cop[tikv] table:tbl keep order:false" + "Limit 1.00 root offset:2, count:1", + "└─Projection 3.00 root test.tbl.a, test.tbl.b, test.tbl.c", + " └─IndexLookUp 3.00 root ", + " ├─Limit(Build) 3.00 cop[tikv] offset:0, count:3", + " │ └─IndexRangeScan 3.00 cop[tikv] table:tbl, index:idx_b_c(b, c) range:(1,+inf], keep order:true, desc", + " └─TableRowIDScan(Probe) 3.00 cop[tikv] table:tbl keep order:false" ] }, { @@ -2503,7 +2504,7 @@ { "SQL": "explain format = 'verbose' select * from t3 order by a", "Plan": [ - "Sort_4 3.00 309.53 root test.t3.a", + "Sort_4 3.00 310.13 root test.t3.a", "└─TableReader_8 3.00 62.67 root data:TableFullScan_7", " └─TableFullScan_7 3.00 559.82 cop[tikv] table:t3 keep order:false" ] @@ -2511,7 +2512,7 @@ { "SQL": "explain format = 'verbose' select * from t3 order by b", "Plan": [ - "Sort_4 3.00 309.53 root test.t3.b", + "Sort_4 3.00 310.13 root test.t3.b", "└─TableReader_8 3.00 62.67 root data:TableFullScan_7", " └─TableFullScan_7 3.00 559.82 cop[tikv] table:t3 keep order:false" ] @@ -2537,10 +2538,10 @@ { "SQL": "explain format = 'verbose' select count(*) from t2 group by a", "Plan": [ - "TableReader_25 3.00 25896.21 root data:ExchangeSender_24", - "└─ExchangeSender_24 3.00 388390.38 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection_23 3.00 388390.38 mpp[tiflash] Column#4", - " └─HashAgg_9 3.00 388390.38 mpp[tiflash] group by:test.t2.a, funcs:count(1)->Column#4", + "TableReader_44 3.00 25896.85 root data:ExchangeSender_43", + "└─ExchangeSender_43 3.00 388400.01 mpp[tiflash] ExchangeType: PassThrough", + " └─Projection_38 3.00 388400.00 mpp[tiflash] Column#4", + " └─HashAgg_36 3.00 388399.98 mpp[tiflash] group by:test.t2.a, funcs:count(1)->Column#4", " └─ExchangeReceiver_22 3.00 385507.26 mpp[tiflash] ", " └─ExchangeSender_21 3.00 385459.26 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.t2.a, collate: binary]", " └─TableFullScan_20 3.00 385459.26 mpp[tiflash] table:t2 keep order:false" @@ -2620,16 +2621,16 @@ { "SQL": "explain format = 'verbose' select (2) in (select /*+ read_from_storage(tiflash[t1]) */ count(*) from t1) from (select t.b < (select /*+ read_from_storage(tiflash[t2]) */ t.b from t2 limit 1 ) from t3 t) t", "Plan": [ - "HashJoin_19 3.00 110724.19 root CARTESIAN left outer semi join", + "HashJoin_19 3.00 110724.79 root CARTESIAN left outer semi join", "├─Selection_38(Build) 0.80 24733.71 root eq(2, Column#18)", "│ └─StreamAgg_45 1.00 24683.81 root funcs:count(1)->Column#18", "│ └─TableReader_59 3.00 24534.11 root data:TableFullScan_58", "│ └─TableFullScan_58 3.00 367821.61 cop[tiflash] table:t1 keep order:false", - "└─Projection_20(Probe) 3.00 85919.34 root 1->Column#28", - " └─Apply_22 3.00 85919.34 root CARTESIAN left outer join", + "└─Projection_20(Probe) 3.00 85919.94 root 1->Column#28", + " └─Apply_22 3.00 85919.64 root CARTESIAN left outer join", " ├─TableReader_24(Build) 3.00 49.99 root data:TableFullScan_23", " │ └─TableFullScan_23 3.00 559.82 cop[tikv] table:t keep order:false", - " └─Projection_27(Probe) 3.00 28623.12 root 1->Column#26", + " └─Projection_27(Probe) 3.00 28623.22 root 1->Column#26", " └─Limit_30 3.00 28623.12 root offset:0, count:1", " └─TableReader_37 3.00 28623.12 root data:ExchangeSender_36", " └─ExchangeSender_36 3.00 429293.93 mpp[tiflash] ExchangeType: PassThrough", @@ -2640,8 +2641,8 @@ { "SQL": "explain format = 'verbose' select /*+ merge_join(t1), read_from_storage(tiflash[t1, t2]) */ count(*) from t1 join t2 on t1.a = t2.a", "Plan": [ - "StreamAgg_14 1.00 52064.31 root funcs:count(1)->Column#7", - "└─MergeJoin_26 3.00 51914.61 root inner join, left key:test.t1.a, right key:test.t2.a", + "StreamAgg_14 1.00 52067.30 root funcs:count(1)->Column#7", + "└─MergeJoin_26 3.00 51917.60 root inner join, left key:test.t1.a, right key:test.t2.a", " ├─Sort_24(Build) 3.00 25957.31 root test.t2.a", " │ └─TableReader_23 3.00 25710.44 root data:Selection_22", " │ └─Selection_22 3.00 385466.46 cop[tiflash] not(isnull(test.t2.a))", @@ -4753,9 +4754,9 @@ { "SQL": "desc format = 'brief' select md5(s) from t", "Plan": [ - "Projection 10000.00 root md5(test.t.s)->Column#13", - "└─TableReader 10000.00 root data:TableFullScan", - " └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" + "TableReader 10000.00 root data:Projection", + "└─Projection 10000.00 cop[tikv] md5(test.t.s)->Column#13", + " └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo" ] }, { @@ -4878,13 +4879,13 @@ "SQL": "desc format = 'brief' select * from t right join (select id-2 as b from t) A on A.b=t.id", "Plan": [ "HashJoin 12487.50 root right outer join, equal:[eq(test.t.id, Column#25)]", - "├─TableReader(Build) 9990.00 root data:Selection", - "│ └─Selection 9990.00 cop[tiflash] not(isnull(test.t.id))", - "│ └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo", - "└─TableReader(Probe) 10000.00 root data:ExchangeSender", - " └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: PassThrough", - " └─Projection 10000.00 mpp[tiflash] minus(test.t.id, 2)->Column#25", - " └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" + "├─TableReader(Build) 10000.00 root data:ExchangeSender", + "│ └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: PassThrough", + "│ └─Projection 10000.00 mpp[tiflash] minus(test.t.id, 2)->Column#25", + "│ └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo", + "└─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tiflash] not(isnull(test.t.id))", + " └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" ] }, { @@ -4945,7 +4946,7 @@ "Name": "TestPushDownProjectionForTiFlash", "Cases": [ { - "SQL": "desc format = 'brief' select /*+ hash_agg()*/ count(b) from (select id + 1 as b from t)A", + "SQL": "desc format = 'brief' select /*+ hash_agg()*/ count(b) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", "Plan": [ "HashAgg 1.00 root funcs:count(Column#8)->Column#6", "└─TableReader 1.00 root data:HashAgg", @@ -4955,7 +4956,7 @@ ] }, { - "SQL": "desc format = 'brief' select /*+ hash_agg()*/ count(*) from (select id + 1 as b from t)A", + "SQL": "desc format = 'brief' select /*+ hash_agg()*/ count(*) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", "Plan": [ "HashAgg 1.00 root funcs:count(Column#7)->Column#6", "└─TableReader 1.00 root data:HashAgg", @@ -4964,7 +4965,7 @@ ] }, { - "SQL": "desc format = 'brief' select /*+ hash_agg()*/ sum(b) from (select id + 1 as b from t)A", + "SQL": "desc format = 'brief' select /*+ hash_agg()*/ sum(b) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", "Plan": [ "HashAgg 1.00 root funcs:sum(Column#8)->Column#6", "└─TableReader 1.00 root data:HashAgg", @@ -4974,7 +4975,7 @@ ] }, { - "SQL": "desc format = 'brief' select /*+ stream_agg()*/ count(b) from (select id + 1 as b from t)A", + "SQL": "desc format = 'brief' select /*+ stream_agg()*/ count(b) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", "Plan": [ "StreamAgg 1.00 root funcs:count(Column#8)->Column#6", "└─TableReader 1.00 root data:StreamAgg", @@ -4984,7 +4985,7 @@ ] }, { - "SQL": "desc format = 'brief' select /*+ stream_agg()*/ count(*) from (select id + 1 as b from t)A", + "SQL": "desc format = 'brief' select /*+ stream_agg()*/ count(*) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", "Plan": [ "StreamAgg 1.00 root funcs:count(Column#7)->Column#6", "└─TableReader 1.00 root data:StreamAgg", @@ -4993,7 +4994,7 @@ ] }, { - "SQL": "desc format = 'brief' select /*+ stream_agg()*/ sum(b) from (select id + 1 as b from t)A", + "SQL": "desc format = 'brief' select /*+ stream_agg()*/ sum(b) from (select /*+ read_from_storage(tiflash[t]) */ id + 1 as b from t)A", "Plan": [ "StreamAgg 1.00 root funcs:sum(Column#8)->Column#6", "└─TableReader 1.00 root data:StreamAgg", @@ -5045,11 +5046,11 @@ "SQL": "desc format = 'brief' select * from t right join (select id-2 as b from t) A on A.b=t.id", "Plan": [ "HashJoin 12487.50 root right outer join, equal:[eq(test.t.id, Column#9)]", - "├─TableReader(Build) 9990.00 root data:Selection", - "│ └─Selection 9990.00 cop[tiflash] not(isnull(test.t.id))", + "├─Projection(Build) 10000.00 root minus(test.t.id, 2)->Column#9", + "│ └─TableReader 10000.00 root data:TableFullScan", "│ └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo", - "└─Projection(Probe) 10000.00 root minus(test.t.id, 2)->Column#9", - " └─TableReader 10000.00 root data:TableFullScan", + "└─TableReader(Probe) 9990.00 root data:Selection", + " └─Selection 9990.00 cop[tiflash] not(isnull(test.t.id))", " └─TableFullScan 10000.00 cop[tiflash] table:t keep order:false, stats:pseudo" ] }, @@ -5277,12 +5278,13 @@ "└─TableReader 8000.00 root data:ExchangeSender", " └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: PassThrough", " └─Projection 8000.00 mpp[tiflash] mul(Column#5, 2)->Column#6, test.t.id", - " └─Projection 8000.00 mpp[tiflash] div(Column#5, cast(case(eq(Column#19, 0), 1, Column#19), decimal(20,0) BINARY))->Column#5, test.t.id", - " └─HashAgg 8000.00 mpp[tiflash] group by:Column#27, funcs:count(Column#24)->Column#19, funcs:sum(Column#25)->Column#5, funcs:firstrow(Column#26)->test.t.id", - " └─Projection 10000.00 mpp[tiflash] plus(test.t.value, 2)->Column#24, plus(test.t.value, 2)->Column#25, test.t.id, test.t.id", - " └─ExchangeReceiver 10000.00 mpp[tiflash] ", - " └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.t.id, collate: binary]", - " └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" + " └─Projection 8000.00 mpp[tiflash] div(Column#5, cast(case(eq(Column#20, 0), 1, Column#20), decimal(20,0) BINARY))->Column#5, test.t.id", + " └─HashAgg 8000.00 mpp[tiflash] group by:test.t.id, funcs:sum(Column#21)->Column#20, funcs:sum(Column#22)->Column#5, funcs:firstrow(test.t.id)->test.t.id", + " └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.t.id, collate: binary]", + " └─HashAgg 8000.00 mpp[tiflash] group by:Column#26, funcs:count(Column#24)->Column#21, funcs:sum(Column#25)->Column#22", + " └─Projection 10000.00 mpp[tiflash] plus(test.t.value, 2)->Column#24, plus(test.t.value, 2)->Column#25, test.t.id", + " └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" ] }, { @@ -5306,10 +5308,11 @@ "└─ExchangeSender 6400.00 mpp[tiflash] ExchangeType: PassThrough", " └─Selection 6400.00 mpp[tiflash] gt(test.t.id, Column#5)", " └─Projection 8000.00 mpp[tiflash] Column#5, test.t.id", - " └─HashAgg 8000.00 mpp[tiflash] group by:test.t.id, funcs:count(1)->Column#5, funcs:firstrow(test.t.id)->test.t.id", - " └─ExchangeReceiver 10000.00 mpp[tiflash] ", - " └─ExchangeSender 10000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.t.id, collate: binary]", - " └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" + " └─HashAgg 8000.00 mpp[tiflash] group by:test.t.id, funcs:sum(Column#12)->Column#5, funcs:firstrow(test.t.id)->test.t.id", + " └─ExchangeReceiver 8000.00 mpp[tiflash] ", + " └─ExchangeSender 8000.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: test.t.id, collate: binary]", + " └─HashAgg 8000.00 mpp[tiflash] group by:test.t.id, funcs:count(1)->Column#12", + " └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo" ] }, {