Skip to content

Commit

Permalink
Merge branch 'master' into fix-dpanic
Browse files Browse the repository at this point in the history
  • Loading branch information
D3Hunter authored Aug 23, 2022
2 parents ff10dd7 + cfd4ddd commit 2cd38fd
Showing 1 changed file with 29 additions and 48 deletions.
77 changes: 29 additions & 48 deletions planner/core/logical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,31 @@ func (ds *DataSource) Convert2Gathers() (gathers []LogicalPlan) {
return gathers
}

func (ds *DataSource) detachCondAndBuildRangeForPath(path *util.AccessPath, conds []expression.Expression) error {
if len(path.IdxCols) == 0 {
path.TableFilters = conds
return nil
}
res, err := ranger.DetachCondAndBuildRangeForIndex(ds.ctx, conds, path.IdxCols, path.IdxColLens)
if err != nil {
return err
}
path.Ranges = res.Ranges
path.AccessConds = res.AccessConds
path.TableFilters = res.RemainedConds
path.EqCondCount = res.EqCondCount
path.EqOrInCondCount = res.EqOrInCount
path.IsDNFCond = res.IsDNFCond
path.ConstCols = make([]bool, len(path.IdxCols))
if res.ColumnValues != nil {
for i := range path.ConstCols {
path.ConstCols[i] = res.ColumnValues[i] != nil
}
}
path.CountAfterAccess, err = ds.tableStats.HistColl.GetRowCountByIndexRanges(ds.ctx, path.Index.ID, path.Ranges)
return err
}

func (ds *DataSource) deriveCommonHandleTablePathStats(path *util.AccessPath, conds []expression.Expression, isIm bool) error {
path.CountAfterAccess = float64(ds.statisticTable.Count)
path.Ranges = ranger.FullNotNullRange()
Expand All @@ -1285,29 +1310,8 @@ func (ds *DataSource) deriveCommonHandleTablePathStats(path *util.AccessPath, co
if len(conds) == 0 {
return nil
}
if len(path.IdxCols) != 0 {
res, err := ranger.DetachCondAndBuildRangeForIndex(ds.ctx, conds, path.IdxCols, path.IdxColLens)
if err != nil {
return err
}
path.Ranges = res.Ranges
path.AccessConds = res.AccessConds
path.TableFilters = res.RemainedConds
path.EqCondCount = res.EqCondCount
path.EqOrInCondCount = res.EqOrInCount
path.IsDNFCond = res.IsDNFCond
path.ConstCols = make([]bool, len(path.IdxCols))
if res.ColumnValues != nil {
for i := range path.ConstCols {
path.ConstCols[i] = res.ColumnValues[i] != nil
}
}
path.CountAfterAccess, err = ds.tableStats.HistColl.GetRowCountByIndexRanges(ds.ctx, path.Index.ID, path.Ranges)
if err != nil {
return err
}
} else {
path.TableFilters = conds
if err := ds.detachCondAndBuildRangeForPath(path, conds); err != nil {
return err
}
if path.EqOrInCondCount == len(path.AccessConds) {
accesses, remained := path.SplitCorColAccessCondFromFilters(ds.ctx, path.EqOrInCondCount)
Expand Down Expand Up @@ -1439,31 +1443,8 @@ func (ds *DataSource) fillIndexPath(path *util.AccessPath, conds []expression.Ex
}
}
}
if len(path.IdxCols) != 0 {
res, err := ranger.DetachCondAndBuildRangeForIndex(ds.ctx, conds, path.IdxCols, path.IdxColLens)
if err != nil {
return err
}
path.Ranges = res.Ranges
path.AccessConds = res.AccessConds
path.TableFilters = res.RemainedConds
path.EqCondCount = res.EqCondCount
path.EqOrInCondCount = res.EqOrInCount
path.IsDNFCond = res.IsDNFCond
path.ConstCols = make([]bool, len(path.IdxCols))
if res.ColumnValues != nil {
for i := range path.ConstCols {
path.ConstCols[i] = res.ColumnValues[i] != nil
}
}
path.CountAfterAccess, err = ds.tableStats.HistColl.GetRowCountByIndexRanges(ds.ctx, path.Index.ID, path.Ranges)
if err != nil {
return err
}
} else {
path.TableFilters = conds
}
return nil
err := ds.detachCondAndBuildRangeForPath(path, conds)
return err
}

// deriveIndexPathStats will fulfill the information that the AccessPath need.
Expand Down

0 comments on commit 2cd38fd

Please sign in to comment.