hashJoin method

CostEstimate hashJoin({
  1. required CostEstimate outerPlan,
  2. required CostEstimate innerPlan,
  3. required double joinSelectivity,
})

Implementation

CostEstimate hashJoin({
  required CostEstimate outerPlan,
  required CostEstimate innerPlan,
  required double joinSelectivity,
}) {
  // Build phase: hash the inner relation
  final buildCost = innerPlan.totalCost +
      innerPlan.rows * CostConstants.cpuOpCost;

  // Probe phase: for each outer row, probe the hash table
  final probeCost = outerPlan.totalCost +
      outerPlan.rows * CostConstants.cpuOpCost;

  final outputRows =
      (outerPlan.rows * innerPlan.rows * joinSelectivity).clamp(1.0, 1e9);

  return CostEstimate(
    totalCost: buildCost + probeCost,
    rows: outputRows,
    method:
        'HashJoin(${outerPlan.method} ⋈ ${innerPlan.method})',
  );
}