code: func (ds *DataSource) DeriveStats(childStats []*property.StatsInfo) (*property.StatsInfo, error) {
  	// PushDownNot here can convert query 'not (a != 1)' to 'a = 1'.
  	for i, expr := range ds.pushedDownConds {
  		ds.pushedDownConds[i] = expression.PushDownNot(nil, expr, false)
  	}
  	var finalHist *statistics.HistColl
  	ds.stats, finalHist = ds.getStatsByFilter(ds.pushedDownConds)
  	for _, path := range ds.possibleAccessPaths {
  		if path.isTablePath {
  			noIntervalRanges, err := ds.deriveTablePathStats(path)
  			if err != nil {
  				return nil, err
  			}
  			// If we have point or empty range, just remove other possible paths.
  			if noIntervalRanges || len(path.ranges) == 0 {
  				ds.possibleAccessPaths[0] = path
  				ds.possibleAccessPaths = ds.possibleAccessPaths[:1]
  				break
  			}
  			continue
  		}
  		noIntervalRanges, err := ds.deriveIndexPathStats(path)
  		if err != nil {
  			return nil, err
  		}
  		// If we have empty range, or point range on unique index, just remove other possible paths.
  		if (noIntervalRanges && path.index.Unique) || len(path.ranges) == 0 {
  			ds.possibleAccessPaths[0] = path
  			ds.possibleAccessPaths = ds.possibleAccessPaths[:1]
  			break
  		}
  	}
  	if ds.ctx.GetSessionVars().OptimizerSelectivityLevel >= 1 {
  		ds.stats.HistColl = finalHist
  	}
  	return ds.stats, nil
  }
docs: // DeriveStats implement LogicalPlan DeriveStats interface.