Skip to content

Commit adbe99f

Browse files
committed
Avoid division by 0
1 parent 8fced15 commit adbe99f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

graphannis/src/annis/db/aql/operators/edge_op.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ impl BinaryOperatorBase for BaseEdgeOp {
329329
return Ok(EstimationType::Selectivity(0.0));
330330
}
331331

332-
let max_nodes: f64 = self.max_nodes_estimate as f64;
332+
let mut max_nodes: f64 = self.max_nodes_estimate as f64;
333+
// Avoid division by 0
334+
if max_nodes == 0.0 {
335+
max_nodes = 1.0;
336+
}
333337

334338
let mut worst_sel: f64 = 0.0;
335339

@@ -369,7 +373,6 @@ impl BinaryOperatorBase for BaseEdgeOp {
369373
let reachable = reachable_max - reachable_min;
370374

371375
gs_selectivity = reachable / max_nodes;
372-
dbg!(gs_selectivity, reachable, max_nodes);
373376
} else {
374377
// We can't use the formula for complete k-ary trees because
375378
// we can't divide by zero and don't want negative numbers.
@@ -381,7 +384,6 @@ impl BinaryOperatorBase for BaseEdgeOp {
381384
(stats.avg_fan_out * f64::from(min_path_length)).ceil();
382385

383386
gs_selectivity = (reachable_max - reachable_min) / max_nodes;
384-
dbg!(gs_selectivity, reachable_min, reachable_max, max_nodes);
385387
}
386388
}
387389

@@ -390,7 +392,6 @@ impl BinaryOperatorBase for BaseEdgeOp {
390392
}
391393
} // end for
392394

393-
dbg!(worst_sel);
394395
Ok(EstimationType::Selectivity(worst_sel))
395396
}
396397

0 commit comments

Comments
 (0)