Skip to content

Commit

Permalink
plan: make the cost more resonable. (#6608) (#6989)
Browse files Browse the repository at this point in the history
  • Loading branch information
winoros authored and shenli committed Jul 5, 2018
1 parent 14552af commit c28a7a7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 11 additions & 3 deletions plan/cbo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,20 +264,28 @@ 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",
best: "IndexLookUp(Index(t.b)[[-inf,40]], Table(t))",
},
{
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",
Expand Down
7 changes: 3 additions & 4 deletions plan/physical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

0 comments on commit c28a7a7

Please sign in to comment.