indexRangeScan method

CostEstimate indexRangeScan(
  1. String table,
  2. String column,
  3. dynamic low,
  4. dynamic high,
)

Implementation

CostEstimate indexRangeScan(
    String table, String column, dynamic low, dynamic high) {
  final ts = stats.get(table);
  if (ts == null) {
    return const CostEstimate(
        totalCost: 50.0, rows: 50.0, method: 'RangeScan(unknown)');
  }
  final cs = ts.column(column);
  final sel = cs?.rangeSelectivity(low, high) ?? 0.3;
  final rowCountSafe  = ts.rowCount  < 1 ? 1 : ts.rowCount;
  final pageCountSafe = ts.pageCount < 1 ? 1 : ts.pageCount;
  final maxRows  = rowCountSafe.toDouble();
  final maxPages = pageCountSafe.toDouble();
  final matchRows = (rowCountSafe * sel).clamp(1.0, maxRows);

  // Range scans read sequential pages for matched portion
  final pages = (pageCountSafe * sel).clamp(1.0, maxPages);
  final cost = CostConstants.indexFetchCost +
      pages * CostConstants.seqIoCost +
      matchRows * CostConstants.cpuTupleCost;
  return CostEstimate(
      totalCost: cost,
      rows: matchRows,
      method: 'RangeScan($table.$column)');
}