Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plan: make the cost more resonable. (#6608) #6989

Merged
merged 2 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}