use crate::db::{
cursor::{CursorBoundary, effective_page_offset_for_window},
executor::ExecutionKernel,
query::plan::AccessPlannedQuery,
};
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
struct PageWindow {
fetch_count: usize,
}
fn compute_page_window(offset: u32, limit: u32) -> PageWindow {
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);
PageWindow {
fetch_count: 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_window(page.offset, limit).fetch_count)
}
}