mod aggregate;
mod authority;
mod continuation;
mod delete;
pub(in crate::db::executor) mod diagnostics;
mod executable_plan;
mod explain;
pub(in crate::db) mod group;
mod kernel;
mod mutation;
mod order;
mod pipeline;
mod plan_metrics;
mod plan_validate;
mod preparation;
mod projection;
pub(super) mod route;
mod runtime_context;
mod scan;
mod stream;
mod terminal;
#[cfg(test)]
mod tests;
mod traversal;
mod util;
mod window;
use crate::db::access::{
LoweredIndexPrefixSpec, LoweredIndexRangeSpec, LoweredKey, lower_index_prefix_specs,
lower_index_range_specs,
};
pub(in crate::db) use crate::db::access::{
ExecutableAccessNode, ExecutableAccessPath, ExecutableAccessPlan,
};
pub(in crate::db) use aggregate::{
ScalarNumericFieldBoundaryRequest, ScalarProjectionBoundaryRequest,
ScalarTerminalBoundaryRequest,
};
pub use authority::EntityAuthority;
pub(in crate::db::executor) use continuation::{
AccessWindow, ContinuationCapabilities, ContinuationEngine, ContinuationMode,
GroupedContinuationCapabilities, GroupedContinuationContext, GroupedPaginationWindow,
LoadCursorInput, PreparedLoadCursor, RequestedLoadExecutionShape, ResolvedLoadCursorContext,
ResolvedScalarContinuationContext, RouteContinuationPlan, ScalarContinuationBindings,
ScalarRouteContinuationInvariantProjection,
};
pub(super) use delete::DeleteExecutor;
#[cfg(feature = "sql")]
pub(in crate::db) use delete::execute_sql_delete_projection_for_canister;
pub(in crate::db::executor) use diagnostics::{ExecutionOptimization, ExecutionTrace};
pub(in crate::db) use executable_plan::{BytesByProjectionMode, ExecutablePlan, ExecutionStrategy};
pub(in crate::db::executor) use executable_plan::{PreparedAggregatePlan, PreparedLoadPlan};
pub(in crate::db) use explain::{
assemble_aggregate_terminal_execution_descriptor_with_model,
assemble_load_execution_node_descriptor_with_model,
assemble_load_execution_verbose_diagnostics_with_model,
};
pub(in crate::db::executor) use kernel::ExecutionKernel;
pub use mutation::save::MutationMode;
pub(super) use mutation::save::SaveExecutor;
pub(in crate::db::executor) use order::{
OrderReadableRow, apply_structural_order_window, compare_orderable_row_with_boundary,
resolve_structural_order,
};
pub(super) use pipeline::contracts::LoadExecutor;
pub(in crate::db::executor) use plan_validate::validate_executor_plan_for_authority;
pub(in crate::db::executor) use preparation::ExecutionPreparation;
#[cfg(feature = "sql")]
pub(in crate::db) use projection::execute_sql_projection_rows_for_canister;
pub(in crate::db) use runtime_context::*;
pub(super) use stream::access::*;
pub(in crate::db::executor) use stream::key::{
BudgetedOrderedKeyStream, KeyOrderComparator, KeyStreamLoopControl, OrderedKeyStream,
OrderedKeyStreamBox, VecOrderedKeyStream, drive_key_stream_with_control_flow,
};
#[cfg(feature = "sql")]
pub(in crate::db) use terminal::KernelRow;
pub(in crate::db::executor) use util::saturating_row_len;
pub(in crate::db) use window::compute_page_keep_count;
pub(in crate::db::executor) type ExecutionPlan = route::ExecutionRoutePlan;
use crate::{
db::{CompiledQuery, cursor::CursorPlanError, data::DataKey},
error::{ErrorClass, ErrorOrigin, InternalError},
traits::EntityKind,
};
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub(in crate::db) enum ExecutorPlanError {
#[error("{0}")]
Cursor(Box<CursorPlanError>),
}
impl ExecutorPlanError {
pub(in crate::db) fn continuation_cursor_invariant(message: impl Into<String>) -> Self {
Self::from(CursorPlanError::continuation_cursor_invariant(message))
}
pub(in crate::db) fn continuation_cursor_requires_load_plan() -> Self {
Self::continuation_cursor_invariant(
"continuation cursors are only supported for load plans",
)
}
pub(in crate::db) fn grouped_cursor_preparation_requires_grouped_plan() -> Self {
Self::continuation_cursor_invariant(
"grouped cursor preparation requires grouped logical plans",
)
}
pub(in crate::db) fn grouped_cursor_revalidation_requires_grouped_plan() -> Self {
Self::continuation_cursor_invariant(
"grouped cursor revalidation requires grouped logical plans",
)
}
pub(in crate::db) fn grouped_cursor_boundary_arity_requires_grouped_plan() -> Self {
Self::continuation_cursor_invariant(
"grouped cursor boundary arity requires grouped logical plans",
)
}
pub(in crate::db) fn continuation_contract_requires_load_plan() -> Self {
Self::continuation_cursor_invariant(
"continuation contracts are only supported for load plans",
)
}
pub(in crate::db) fn load_execution_descriptor_requires_load_plan() -> Self {
Self::continuation_cursor_invariant(
"load execution descriptor requires load-mode executable plans",
)
}
pub(in crate::db) fn lowered_index_prefix_spec_invalid() -> Self {
Self::continuation_cursor_invariant(LoweredIndexPrefixSpec::invalid_reason())
}
pub(in crate::db) fn lowered_index_range_spec_invalid() -> Self {
Self::continuation_cursor_invariant(LoweredIndexRangeSpec::invalid_reason())
}
pub(in crate::db) fn into_internal_error(self) -> InternalError {
match self {
Self::Cursor(err) => err.into_internal_error(),
}
}
}
impl From<CursorPlanError> for ExecutorPlanError {
fn from(err: CursorPlanError) -> Self {
Self::Cursor(Box::new(err))
}
}
#[derive(Debug, ThisError)]
pub(in crate::db::executor) enum ExecutorError {
#[error("corruption detected ({origin}): {message}")]
Corruption {
origin: ErrorOrigin,
message: String,
},
#[error("data key exists: {0}")]
KeyExists(DataKey),
}
impl ExecutorError {
pub(in crate::db::executor) const fn class(&self) -> ErrorClass {
match self {
Self::KeyExists(_) => ErrorClass::Conflict,
Self::Corruption { .. } => ErrorClass::Corruption,
}
}
pub(in crate::db::executor) const fn origin(&self) -> ErrorOrigin {
match self {
Self::KeyExists(_) => ErrorOrigin::Store,
Self::Corruption { origin, .. } => *origin,
}
}
pub(in crate::db::executor) fn corruption(
origin: ErrorOrigin,
message: impl Into<String>,
) -> Self {
Self::Corruption {
origin,
message: message.into(),
}
}
pub(in crate::db::executor) fn store_corruption(message: impl Into<String>) -> Self {
Self::corruption(ErrorOrigin::Store, message)
}
pub(in crate::db::executor) fn missing_row(key: &DataKey) -> Self {
Self::store_corruption(format!("missing row: {key}"))
}
pub(in crate::db::executor) fn persisted_row_invariant_violation(
data_key: &DataKey,
detail: impl AsRef<str>,
) -> Self {
Self::store_corruption(format!(
"persisted row invariant violation: {data_key} ({})",
detail.as_ref(),
))
}
}
impl From<ExecutorError> for InternalError {
fn from(err: ExecutorError) -> Self {
Self::classified(err.class(), err.origin(), err.to_string())
}
}
impl<E> From<CompiledQuery<E>> for ExecutablePlan<E>
where
E: EntityKind,
{
fn from(value: CompiledQuery<E>) -> Self {
value.into_executable()
}
}