diff --git a/planner/core/find_best_task.go b/planner/core/find_best_task.go index 13c559d9c66c5..00c5099388e08 100644 --- a/planner/core/find_best_task.go +++ b/planner/core/find_best_task.go @@ -1917,7 +1917,7 @@ func (ds *DataSource) convertToTableScan(prop *property.PhysicalProperty, candid ColumnNames: ds.names, } ts.cost = cost - mppTask = ts.addPushedDownSelectionToMppTask(mppTask, ds.stats) + mppTask = ts.addPushedDownSelectionToMppTask(mppTask, ds.stats.ScaleByExpectCnt(prop.ExpectedCnt)) return mppTask, nil } copTask := &copTask{ diff --git a/planner/core/integration_test.go b/planner/core/integration_test.go index e059d97711560..49a8b012705f6 100644 --- a/planner/core/integration_test.go +++ b/planner/core/integration_test.go @@ -6989,3 +6989,31 @@ func TestIssue25813(t *testing.T) { " └─TableReader(Probe) 10000.00 root data:TableFullScan", " └─TableFullScan 10000.00 cop[tikv] table:t1 keep order:false, stats:pseudo")) } + +func TestIssue36194(t *testing.T) { + store, dom, clean := testkit.CreateMockStoreAndDomain(t) + defer clean() + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("drop table if exists t") + tk.MustExec("create table t(a int)") + // create virtual tiflash replica. + is := dom.InfoSchema() + db, exists := is.SchemaByName(model.NewCIStr("test")) + require.True(t, exists) + for _, tblInfo := range db.Tables { + if tblInfo.Name.L == "t" { + tblInfo.TiFlashReplica = &model.TiFlashReplicaInfo{ + Count: 1, + Available: true, + } + } + } + tk.MustQuery("explain format = 'brief' select * from t where a + 1 > 20 limit 100;;").Check(testkit.Rows( + "Limit 100.00 root offset:0, count:100", + "└─TableReader 100.00 root data:ExchangeSender", + " └─ExchangeSender 100.00 mpp[tiflash] ExchangeType: PassThrough", + " └─Limit 100.00 mpp[tiflash] offset:0, count:100", + " └─Selection 100.00 mpp[tiflash] gt(plus(test.t.a, 1), 20)", + " └─TableFullScan 125.00 mpp[tiflash] table:t keep order:false, stats:pseudo")) +} diff --git a/planner/core/testdata/integration_suite_out.json b/planner/core/testdata/integration_suite_out.json index aeff80fd103ea..22e3d3d4f582d 100644 --- a/planner/core/testdata/integration_suite_out.json +++ b/planner/core/testdata/integration_suite_out.json @@ -5952,7 +5952,7 @@ " │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast", " │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.t.id))", " │ └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo", - " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.t.id))", + " └─Selection(Probe) 0.80 mpp[tiflash] not(isnull(test.t.id))", " └─TableFullScan 0.80 mpp[tiflash] table:t1 keep order:false, stats:pseudo" ] }, @@ -5968,7 +5968,7 @@ " │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast", " │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.t.id))", " │ └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo", - " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.t.id))", + " └─Selection(Probe) 0.80 mpp[tiflash] not(isnull(test.t.id))", " └─TableFullScan 0.80 mpp[tiflash] table:t1 keep order:false, stats:pseudo" ] }, @@ -5985,7 +5985,7 @@ " │ └─ExchangeSender 9990.00 mpp[tiflash] ExchangeType: Broadcast", " │ └─Selection 9990.00 mpp[tiflash] not(isnull(test.t.id))", " │ └─TableFullScan 10000.00 mpp[tiflash] table:t keep order:false, stats:pseudo", - " └─Selection(Probe) 9990.00 mpp[tiflash] not(isnull(test.t.id))", + " └─Selection(Probe) 16.00 mpp[tiflash] not(isnull(test.t.id))", " └─TableFullScan 16.02 mpp[tiflash] table:t1 keep order:false, stats:pseudo" ] }