diff --git a/plan/cbo_test.go b/plan/cbo_test.go index cd88ae4d623d4..455ecc64b2cd1 100644 --- a/plan/cbo_test.go +++ b/plan/cbo_test.go @@ -264,7 +264,11 @@ func (s *testAnalyzeSuite) TestIndexRead(c *C) { }, { sql: "select count(e) from t where t.b <= 50", - best: "TableReader(Table(t)->Sel([le(test.t.b, 50)])->StreamAgg)->StreamAgg", + best: "IndexLookUp(Index(t.b)[[-inf,50]], Table(t)->HashAgg)->HashAgg", + }, + { + sql: "select count(e) from t where t.b <= 100000000000", + best: "TableReader(Table(t)->Sel([le(test.t.b, 100000000000)])->StreamAgg)->StreamAgg", }, { sql: "select * from t where t.b <= 40", @@ -272,12 +276,16 @@ func (s *testAnalyzeSuite) TestIndexRead(c *C) { }, { sql: "select * from t where t.b <= 50", - best: "TableReader(Table(t)->Sel([le(test.t.b, 50)]))", + best: "IndexLookUp(Index(t.b)[[-inf,50]], Table(t))", + }, + { + sql: "select * from t where t.b <= 10000000000", + best: "TableReader(Table(t)->Sel([le(test.t.b, 10000000000)]))", }, // test panic { sql: "select * from t where 1 and t.b <= 50", - best: "TableReader(Table(t)->Sel([le(test.t.b, 50)]))", + best: "IndexLookUp(Index(t.b)[[-inf,50]], Table(t))", }, { sql: "select * from t where t.b <= 100 order by t.a limit 1", diff --git a/plan/physical_plan_builder.go b/plan/physical_plan_builder.go index 096df9a23c0d8..4926106e18fb2 100644 --- a/plan/physical_plan_builder.go +++ b/plan/physical_plan_builder.go @@ -400,6 +400,7 @@ func (is *PhysicalIndexScan) addPushedDownSelection(copTask *copTask, p *DataSou // Add filter condition to table plan now. indexConds, tableConds := path.indexFilters, path.tableFilters if indexConds != nil { + copTask.cst += copTask.count() * cpuFactor count := path.countAfterAccess if count >= 1.0 { selectivity := path.countAfterIndex / path.countAfterAccess @@ -409,14 +410,13 @@ func (is *PhysicalIndexScan) addPushedDownSelection(copTask *copTask, p *DataSou indexSel := PhysicalSelection{Conditions: indexConds}.init(is.ctx, stats) indexSel.SetChildren(is) copTask.indexPlan = indexSel - copTask.cst += copTask.count() * cpuFactor } if tableConds != nil { copTask.finishIndexPlan() + copTask.cst += copTask.count() * cpuFactor tableSel := PhysicalSelection{Conditions: tableConds}.init(is.ctx, p.statsAfterSelect.scaleByExpectCnt(expectedCnt)) tableSel.SetChildren(copTask.tablePlan) copTask.tablePlan = tableSel - copTask.cst += copTask.count() * cpuFactor } } @@ -568,10 +568,9 @@ func (ds *DataSource) convertToTableScan(prop *requiredProp, path *accessPath) ( func (ts *PhysicalTableScan) addPushedDownSelection(copTask *copTask, stats *statsInfo) { // Add filter condition to table plan now. if len(ts.filterCondition) > 0 { + copTask.cst += copTask.count() * cpuFactor sel := PhysicalSelection{Conditions: ts.filterCondition}.init(ts.ctx, stats) sel.SetChildren(ts) copTask.tablePlan = sel - // FIXME: It seems wrong... - copTask.cst += copTask.count() * cpuFactor } }