use crate::db::{
cursor::{CursorBoundary, effective_page_offset_for_window},
executor::ExecutionKernel,
query::plan::AccessPlannedQuery,
};
fn compute_page_fetch_count(offset: u32, limit: u32) -> usize {
let offset = usize::try_from(offset).unwrap_or(usize::MAX);
let limit = usize::try_from(limit).unwrap_or(usize::MAX);
let keep_count = offset.saturating_add(limit);
keep_count.saturating_add(1)
}
impl ExecutionKernel {
#[must_use]
pub(in crate::db::executor) fn effective_page_offset(
plan: &AccessPlannedQuery,
cursor_boundary: Option<&CursorBoundary>,
) -> u32 {
effective_page_offset_for_window(plan, cursor_boundary.is_some())
}
#[must_use]
pub(in crate::db::executor) fn bounded_order_keep_count(
plan: &AccessPlannedQuery,
cursor_boundary: Option<&CursorBoundary>,
) -> Option<usize> {
let logical = plan.scalar_plan();
if !logical.mode.is_load() || cursor_boundary.is_some() {
return None;
}
let page = logical.page.as_ref()?;
let limit = page.limit?;
if limit == 0 {
return None;
}
Some(compute_page_fetch_count(page.offset, limit))
}
}