use crate::db::{
direction::Direction,
query::{
builder::AggregateExpr,
plan::{AccessPlannedQuery, ExecutionOrderContract},
},
};
use crate::db::executor::route::{RouteCapabilities, aggregate_extrema_direction};
pub(in crate::db::executor) fn aggregate_non_count_streaming_allowed(
aggregate_expr: Option<&AggregateExpr>,
capabilities: RouteCapabilities,
secondary_pushdown_eligible: bool,
index_range_limit_enabled: bool,
) -> bool {
if let Some(aggregate) = aggregate_expr
&& aggregate.target_field().is_some()
{
return match aggregate_extrema_direction(aggregate.kind()) {
Some(Direction::Asc) => capabilities.field_min_fast_path_eligible,
Some(Direction::Desc) => capabilities.field_max_fast_path_eligible,
None => false,
};
}
if capabilities.stream_order_contract_safe || index_range_limit_enabled {
return true;
}
let _ = secondary_pushdown_eligible;
false
}
pub(in crate::db::executor) const fn load_streaming_allowed(
capabilities: RouteCapabilities,
index_range_limit_enabled: bool,
) -> bool {
capabilities.stream_order_contract_safe || index_range_limit_enabled
}
pub(in crate::db::executor::route) fn derive_load_route_direction(
plan: &AccessPlannedQuery,
) -> Direction {
ExecutionOrderContract::from_plan(
plan.grouped_plan().is_some(),
plan.scalar_plan().order.as_ref(),
)
.primary_scan_direction()
}
pub(in crate::db::executor::route) fn derive_aggregate_route_direction(
plan: &AccessPlannedQuery,
aggregate: &AggregateExpr,
) -> Direction {
if aggregate.target_field().is_some() {
return aggregate_extrema_direction(aggregate.kind())
.unwrap_or_else(|| derive_load_route_direction(plan));
}
derive_load_route_direction(plan)
}