planner: not use DescScanFactor when rows is less than smallScanThreshold for compatibility (#36263)

This commit is contained in:
Yuanjia Zhang
2022-07-18 14:36:09 +08:00
committed by GitHub
parent 0d6741039a
commit 1acc178da5
3 changed files with 6 additions and 2 deletions

View File

@ -2198,6 +2198,7 @@ func (ds *DataSource) getOriginalPhysicalTableScan(prop *property.PhysicalProper
HandleCols: ds.handleCols,
tblCols: ds.TblCols,
tblColHists: ds.TblColHists,
prop: prop,
}.Init(ds.ctx, ds.blockOffset)
ts.filterCondition = make([]expression.Expression, len(path.TableFilters))
copy(ts.filterCondition, path.TableFilters)
@ -2267,6 +2268,7 @@ func (ds *DataSource) getOriginalPhysicalIndexScan(prop *property.PhysicalProper
physicalTableID: ds.physicalTableID,
tblColHists: ds.TblColHists,
pkIsHandleCol: ds.getPKIsHandleCol(),
prop: prop,
}.Init(ds.ctx, ds.blockOffset)
statsTbl := ds.statisticTable
if statsTbl.Indices[idx.ID] != nil {

View File

@ -468,6 +468,7 @@ type PhysicalIndexScan struct {
// tblColHists contains all columns before pruning, which are used to calculate row-size
tblColHists *statistics.HistColl
pkIsHandleCol *expression.Column
prop *property.PhysicalProperty
}
// Clone implements PhysicalPlan interface.
@ -569,6 +570,7 @@ type PhysicalTableScan struct {
// tblCols and tblColHists contains all columns before pruning, which are used to calculate row-size
tblCols []*expression.Column
tblColHists *statistics.HistColl
prop *property.PhysicalProperty
}
// Clone implements PhysicalPlan interface.

View File

@ -404,7 +404,7 @@ func (p *PhysicalTableScan) GetPlanCost(taskType property.TaskType, costFlag uin
switch p.ctx.GetSessionVars().CostModelVersion {
case modelVer1: // scan cost: rows * row-size * scan-factor
scanFactor := p.ctx.GetSessionVars().GetScanFactor(p.Table)
if p.Desc {
if p.Desc && p.prop != nil && p.prop.ExpectedCnt >= smallScanThreshold {
scanFactor = p.ctx.GetSessionVars().GetDescScanFactor(p.Table)
}
selfCost = getCardinality(p, costFlag) * p.getScanRowSize() * scanFactor
@ -441,7 +441,7 @@ func (p *PhysicalIndexScan) GetPlanCost(taskType property.TaskType, costFlag uin
switch p.ctx.GetSessionVars().CostModelVersion {
case modelVer1: // scan cost: rows * row-size * scan-factor
scanFactor := p.ctx.GetSessionVars().GetScanFactor(p.Table)
if p.Desc {
if p.Desc && p.prop != nil && p.prop.ExpectedCnt >= smallScanThreshold {
scanFactor = p.ctx.GetSessionVars().GetDescScanFactor(p.Table)
}
selfCost = getCardinality(p, costFlag) * p.getScanRowSize() * scanFactor