Skip to content

Commit c28a7a7

Browse files
winorosshenli
authored andcommitted
plan: make the cost more resonable. (#6608) (#6989)
1 parent 14552af commit c28a7a7

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

plan/cbo_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,20 +264,28 @@ func (s *testAnalyzeSuite) TestIndexRead(c *C) {
264264
},
265265
{
266266
sql: "select count(e) from t where t.b <= 50",
267-
best: "TableReader(Table(t)->Sel([le(test.t.b, 50)])->StreamAgg)->StreamAgg",
267+
best: "IndexLookUp(Index(t.b)[[-inf,50]], Table(t)->HashAgg)->HashAgg",
268+
},
269+
{
270+
sql: "select count(e) from t where t.b <= 100000000000",
271+
best: "TableReader(Table(t)->Sel([le(test.t.b, 100000000000)])->StreamAgg)->StreamAgg",
268272
},
269273
{
270274
sql: "select * from t where t.b <= 40",
271275
best: "IndexLookUp(Index(t.b)[[-inf,40]], Table(t))",
272276
},
273277
{
274278
sql: "select * from t where t.b <= 50",
275-
best: "TableReader(Table(t)->Sel([le(test.t.b, 50)]))",
279+
best: "IndexLookUp(Index(t.b)[[-inf,50]], Table(t))",
280+
},
281+
{
282+
sql: "select * from t where t.b <= 10000000000",
283+
best: "TableReader(Table(t)->Sel([le(test.t.b, 10000000000)]))",
276284
},
277285
// test panic
278286
{
279287
sql: "select * from t where 1 and t.b <= 50",
280-
best: "TableReader(Table(t)->Sel([le(test.t.b, 50)]))",
288+
best: "IndexLookUp(Index(t.b)[[-inf,50]], Table(t))",
281289
},
282290
{
283291
sql: "select * from t where t.b <= 100 order by t.a limit 1",

plan/physical_plan_builder.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ func (is *PhysicalIndexScan) addPushedDownSelection(copTask *copTask, p *DataSou
400400
// Add filter condition to table plan now.
401401
indexConds, tableConds := path.indexFilters, path.tableFilters
402402
if indexConds != nil {
403+
copTask.cst += copTask.count() * cpuFactor
403404
count := path.countAfterAccess
404405
if count >= 1.0 {
405406
selectivity := path.countAfterIndex / path.countAfterAccess
@@ -409,14 +410,13 @@ func (is *PhysicalIndexScan) addPushedDownSelection(copTask *copTask, p *DataSou
409410
indexSel := PhysicalSelection{Conditions: indexConds}.init(is.ctx, stats)
410411
indexSel.SetChildren(is)
411412
copTask.indexPlan = indexSel
412-
copTask.cst += copTask.count() * cpuFactor
413413
}
414414
if tableConds != nil {
415415
copTask.finishIndexPlan()
416+
copTask.cst += copTask.count() * cpuFactor
416417
tableSel := PhysicalSelection{Conditions: tableConds}.init(is.ctx, p.statsAfterSelect.scaleByExpectCnt(expectedCnt))
417418
tableSel.SetChildren(copTask.tablePlan)
418419
copTask.tablePlan = tableSel
419-
copTask.cst += copTask.count() * cpuFactor
420420
}
421421
}
422422

@@ -568,10 +568,9 @@ func (ds *DataSource) convertToTableScan(prop *requiredProp, path *accessPath) (
568568
func (ts *PhysicalTableScan) addPushedDownSelection(copTask *copTask, stats *statsInfo) {
569569
// Add filter condition to table plan now.
570570
if len(ts.filterCondition) > 0 {
571+
copTask.cst += copTask.count() * cpuFactor
571572
sel := PhysicalSelection{Conditions: ts.filterCondition}.init(ts.ctx, stats)
572573
sel.SetChildren(ts)
573574
copTask.tablePlan = sel
574-
// FIXME: It seems wrong...
575-
copTask.cst += copTask.count() * cpuFactor
576575
}
577576
}

0 commit comments

Comments
 (0)