Skip to content

Commit 81fd266

Browse files
committed
implement cost computation for limit
1 parent 5d8d0c6 commit 81fd266

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

optd-cost-model/src/cost/limit.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use optd_persistent::CostModelStorageLayer;
2+
3+
use crate::{
4+
common::{
5+
nodes::{ArcPredicateNode, ReprPredicateNode},
6+
predicates::constant_pred::ConstantPred,
7+
},
8+
cost_model::CostModelImpl,
9+
CostModelResult, EstimatedStatistic,
10+
};
11+
12+
impl<S: CostModelStorageLayer> CostModelImpl<S> {
13+
pub(crate) fn get_limit_row_cnt(
14+
&self,
15+
child_row_cnt: EstimatedStatistic,
16+
fetch_expr: ArcPredicateNode,
17+
) -> CostModelResult<EstimatedStatistic> {
18+
let fetch = ConstantPred::from_pred_node(fetch_expr)
19+
.unwrap()
20+
.value()
21+
.as_u64();
22+
// u64::MAX represents None
23+
if fetch == u64::MAX {
24+
Ok(child_row_cnt)
25+
} else {
26+
Ok(EstimatedStatistic(child_row_cnt.0.min(fetch)))
27+
}
28+
}
29+
}

optd-cost-model/src/cost/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#![allow(unused)]
2+
13
pub mod agg;
24
pub mod filter;
35
pub mod join;
6+
pub mod limit;

0 commit comments

Comments
 (0)