use crate::analytics::{ProjectionLayout, ProjectionMemoryBudget};
#[cfg(test)]
use crate::cypher::RelationshipDirection;
#[cfg(test)]
use crate::error::HawDBError;
use crate::error::Result;
use crate::optimizer::PhysicalPlan;
#[cfg(test)]
use crate::planner::GraphAlgorithmKind;
#[cfg(test)]
use crate::planner::Predicate;
#[cfg(test)]
use crate::planner::{SetNodePropertiesReturnMode, SetValue};
use crate::schema::Catalog;
use crate::store::{GraphStore, MutationLimits, ProjectedGraphDefinition, ScanPruningReport};
use crate::value::Value;
use hawdb_core::RuntimeTaskContext;
use hawdb_executor::ExecutionLimit;
use std::collections::BTreeMap;
pub(crate) fn unsupported_scoring_input_error() -> crate::error::HawDBError {
crate::error::HawDBError::Semantic("scoring requires a batch-capable candidate query".into())
}
#[cfg(test)]
use std::num::NonZeroU64;
#[cfg(test)]
use std::num::NonZeroUsize;
#[allow(private_bounds)]
pub trait ExecutionStore:
hawdb_storage::graph_engine::GraphReadEngine
+ hawdb_storage::graph_engine::GraphMutationEngine
+ hawdb_executor::store::GraphExecutionWrite
+ crate::store::InternalGraphEngine
+ hawdb_relational::row_runtime::RelationalRowStoreReader
+ hawdb_relational::index_runtime::RelationalIndexStoreReader
{
}
impl<T> ExecutionStore for T where
T: hawdb_storage::graph_engine::GraphReadEngine
+ hawdb_storage::graph_engine::GraphMutationEngine
+ hawdb_executor::store::GraphExecutionWrite
+ crate::store::InternalGraphEngine
+ hawdb_relational::row_runtime::RelationalRowStoreReader
+ hawdb_relational::index_runtime::RelationalIndexStoreReader
{
}
#[cfg(test)]
use crate::planner::{Aggregation, Projection, RelationshipCountLeg, SortItem};
#[cfg(test)]
use crate::store::{NodeId, NodeRecord};
mod batch;
mod columnar;
mod entrypoint;
mod expression;
mod mutation;
mod observer;
mod read;
mod scan;
#[cfg(test)]
mod traversal;
mod vector;
use batch::*;
use entrypoint::*;
#[cfg(test)]
use expression::*;
#[cfg(feature = "tokio-runtime")]
pub(crate) use hawdb_executor::binding::map_memory_bytes;
#[cfg(test)]
pub(crate) use hawdb_executor::binding::map_payload_bytes;
use hawdb_executor::binding::Binding;
pub use hawdb_executor::execution_request::ExecutionRequest;
pub use hawdb_executor::external::NoExternalReadOperator;
pub use hawdb_executor::load_csv::{CsvImportLimits, CsvImportPolicy};
pub(crate) use hawdb_executor::memory::{
enforced_query_memory_budget, enforced_result_memory_budget,
enforced_result_memory_budget_with_option, estimated_execution_memory,
estimated_mutation_memory_bytes, max_external_read_parallelism,
};
pub(crate) use hawdb_executor::mutation::execute_mutation_with_store_output_limits;
pub(crate) use hawdb_executor::mutation::{
commit_staged_mutations_with_output, stage_row_mutations,
};
use hawdb_executor::pipeline::{runtime_checkpoint, BatchControl};
use hawdb_executor::QueryMemoryLedger;
#[cfg(test)]
use hawdb_executor::{pipeline::BindingBatch, QueryMemoryClass};
pub use hawdb_executor::{ExecutionMemoryConfig, SpillPoolSnapshot};
pub use hawdb_executor::{
ExternalReadOperator, ExternalReadResourceContract, ExternalReadResultBudget,
GroupedEvidenceExecutionReport, OperatorCardinalityProfile, TextSeedExecutionOutput,
TextSeedExecutionReport, TextSeedExecutionRequest, TextSeedExecutionRow, TextSeedSourceReport,
VectorCompressionMode, VectorExecutionBackend, VectorExecutionReport, VectorScoreSource,
VectorSeedExecutionOutput, VectorSeedExecutionRequest, VectorSeedExecutionRow,
};
pub(crate) use mutation::project_staged_mutation_return_rows;
pub(crate) use mutation::{execute_match_set, resolve_match_set};
pub use mutation::{
execute_mutation_with_limits, is_mutation_plan, materialize_unwind_mutations, mutation_command,
};
use observer::*;
use read::*;
#[cfg(test)]
use scan::*;
#[cfg(test)]
use traversal::*;
use vector::*;
pub type Row = hawdb_executor::Row;
pub type RowRef<'a> = hawdb_executor::RowRef<'a>;
pub type ProjectedRowRef<'a> = hawdb_executor::ProjectedRowRef<'a>;
pub type QueryRow = hawdb_executor::QueryRow;
pub type QueryRowRef<'a> = hawdb_executor::QueryRowRef<'a>;
pub type QueryRows = hawdb_executor::QueryRows;
pub type QueryRowsBuilder = hawdb_executor::QueryRowsBuilder;
pub type QueryValueRows<'a> = hawdb_executor::QueryValueRows<'a>;
pub type QuerySchema = hawdb_executor::QuerySchema;
pub type ReadExecutionProfile = hawdb_executor::ReadExecutionProfile<ScanPruningReport>;
pub type ProfiledQueryRows = hawdb_executor::ProfiledQueryRows<ScanPruningReport>;
pub type ProfiledQueryStream = hawdb_executor::ProfiledQueryStream<ScanPruningReport>;
pub(crate) use hawdb_executor::batch::SOURCE_SEGMENT_SCAN_IO_DEPTH;
pub(crate) use hawdb_executor::numeric::MAX_MORSEL_PARALLELISM;
pub(crate) use hawdb_executor::result_delivery::StreamDelivery;
pub use entrypoint::ExecutionResources;
pub(crate) fn requires_write_access(plan: &PhysicalPlan) -> bool {
let mut writes = false;
hawdb_plan_cypher::visit_plan(plan, &mut |node| {
writes |= matches!(node, PhysicalPlan::ProjectGraph { .. })
|| matches!(
node.class(),
hawdb_plan_cypher::PhysicalPlanClass::Schema
| hawdb_plan_cypher::PhysicalPlanClass::Mutation
);
});
writes
}
pub fn execute_with_request<S: ExecutionStore>(
request: ExecutionRequest<'_>,
resources: ExecutionResources<'_, S>,
) -> Result<ProfiledQueryRows> {
execute_profiled_rows(request, resources)
}
pub fn execute_with_request_consumer<S: ExecutionStore>(
request: ExecutionRequest<'_>,
resources: ExecutionResources<'_, S>,
consumer: &mut dyn FnMut(Row) -> Result<()>,
) -> Result<ProfiledQueryStream> {
execute_profiled_consumer(
request,
resources,
ConsumerMemoryMode::DeferredUntilValidated,
consumer,
)
}
pub(crate) enum QueryStreamConsumer<'a> {
Owned(&'a mut dyn FnMut(Row) -> Result<()>),
Borrowed(&'a mut hawdb_executor::result_delivery::BorrowedRowConsumer<'a>),
}
pub(crate) fn execute_with_request_stream<S: ExecutionStore>(
request: ExecutionRequest<'_>,
resources: ExecutionResources<'_, S>,
delivery: StreamDelivery,
consumer: QueryStreamConsumer<'_>,
) -> Result<ProfiledQueryStream> {
match consumer {
QueryStreamConsumer::Owned(consumer) => {
let limits = request.output_limits();
let bounded = limits.max_rows.is_some() || limits.max_payload_bytes.is_some();
execute_profiled_consumer(
request,
resources,
delivery.consumer_memory_mode(bounded),
consumer,
)
}
QueryStreamConsumer::Borrowed(consumer) => {
execute_profiled_borrowed_consumer(request, resources, delivery, consumer)
}
}
}
pub(crate) fn supports_default_morsel_parallelism(plan: &PhysicalPlan, catalog: &Catalog) -> bool {
columnar::supports_parallel_morsel_execution(plan, catalog)
}
pub(crate) fn default_morsel_parallelism(
plan: &PhysicalPlan,
catalog: &Catalog,
store: &dyn hawdb_executor::store::GraphExecutionRead,
memory: &ExecutionMemoryConfig,
) -> usize {
columnar::default_morsel_parallelism(plan, catalog, store, memory)
}
pub fn execute(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut GraphStore,
) -> Result<Vec<Row>> {
execute_with_row_limit_internal(plan, catalog, store, None, None)
}
#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
max_rows: Option<usize>,
) -> Result<Vec<Row>> {
execute_with_row_limit_internal(plan, catalog, store, max_rows, None)
}
#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_and_context(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
max_rows: Option<usize>,
task_context: &RuntimeTaskContext,
) -> Result<Vec<Row>> {
execute_with_row_limit_internal(plan, catalog, store, max_rows, Some(task_context))
}
fn execute_with_row_limit_internal(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
max_rows: Option<usize>,
task_context: Option<&RuntimeTaskContext>,
) -> Result<Vec<Row>> {
let parameters = BTreeMap::new();
let mut external = NoExternalReadOperator;
let memory = ExecutionMemoryConfig::default();
let mut rows = Vec::new();
execute_profiled_consumer(
ExecutionRequest::new(plan, ¶meters, &memory)
.with_output_limits(max_rows, None)
.with_optional_task_context(task_context),
ExecutionResources::new(catalog, store, &mut external),
ConsumerMemoryMode::Retained,
&mut |row| {
rows.push(row);
Ok(())
},
)?;
Ok(rows)
}
#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_profile(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
max_rows: Option<usize>,
) -> Result<ProfiledQueryRows> {
let mut external = NoExternalReadOperator;
let parameters = BTreeMap::new();
let memory = ExecutionMemoryConfig::default();
execute_profiled_rows(
ExecutionRequest::new(plan, ¶meters, &memory).with_output_limits(max_rows, None),
ExecutionResources::new(catalog, store, &mut external),
)
}
#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_profile_and_external(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
) -> Result<ProfiledQueryRows> {
let memory = ExecutionMemoryConfig::default();
execute_profiled_rows(
ExecutionRequest::new(plan, parameters, &memory).with_output_limits(max_rows, None),
ExecutionResources::new(catalog, store, external),
)
}
#[deprecated(note = "use execute_with_request")]
pub fn execute_with_output_limits_profile_and_external(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
) -> Result<ProfiledQueryRows> {
let memory = ExecutionMemoryConfig::default();
execute_profiled_rows(
ExecutionRequest::new(plan, parameters, &memory)
.with_output_limits(max_rows, max_payload_bytes),
ExecutionResources::new(catalog, store, external),
)
}
#[deprecated(note = "use execute_with_request")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_output_limits_profile_and_external_and_memory(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryRows> {
execute_with_request(
ExecutionRequest::new(plan, parameters, memory)
.with_output_limits(max_rows, max_payload_bytes),
ExecutionResources::new(catalog, store, external),
)
}
#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_profile_and_external_and_memory(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryRows> {
execute_with_request(
ExecutionRequest::new(plan, parameters, memory).with_output_limits(max_rows, None),
ExecutionResources::new(catalog, store, external),
)
}
#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_profile_and_external_and_context(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
task_context: &RuntimeTaskContext,
) -> Result<ProfiledQueryRows> {
let memory = ExecutionMemoryConfig::default();
execute_with_request(
ExecutionRequest::new(plan, parameters, &memory)
.with_output_limits(max_rows, None)
.with_task_context(task_context),
ExecutionResources::new(catalog, store, external),
)
}
#[deprecated(note = "use execute_with_request")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_output_limits_profile_and_external_and_context(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
task_context: &RuntimeTaskContext,
) -> Result<ProfiledQueryRows> {
let memory = ExecutionMemoryConfig::default();
execute_with_request(
ExecutionRequest::new(plan, parameters, &memory)
.with_output_limits(max_rows, max_payload_bytes)
.with_task_context(task_context),
ExecutionResources::new(catalog, store, external),
)
}
#[deprecated(note = "use execute_with_request")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_output_limits_profile_and_external_and_context_and_memory(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
task_context: &RuntimeTaskContext,
memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryRows> {
execute_with_request(
ExecutionRequest::new(plan, parameters, memory)
.with_output_limits(max_rows, max_payload_bytes)
.with_task_context(task_context),
ExecutionResources::new(catalog, store, external),
)
}
#[deprecated(note = "use execute_with_request_consumer")]
pub fn execute_with_row_consumer_profile(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
consumer: &mut dyn FnMut(Row) -> Result<()>,
) -> Result<ProfiledQueryStream> {
let mut external = NoExternalReadOperator;
let memory = ExecutionMemoryConfig::default();
execute_with_row_consumer_profile_with_delivery(
plan,
catalog,
store,
parameters,
&mut external,
max_rows,
max_payload_bytes,
consumer,
None,
&memory,
StreamDelivery::Validated,
)
}
#[deprecated(note = "use execute_with_request_consumer")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_row_consumer_profile_and_external(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
consumer: &mut dyn FnMut(Row) -> Result<()>,
) -> Result<ProfiledQueryStream> {
let memory = ExecutionMemoryConfig::default();
execute_with_row_consumer_profile_with_delivery(
plan,
catalog,
store,
parameters,
external,
max_rows,
max_payload_bytes,
consumer,
None,
&memory,
StreamDelivery::Validated,
)
}
#[deprecated(note = "use execute_with_request_consumer")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_row_consumer_profile_and_external_and_memory(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
consumer: &mut dyn FnMut(Row) -> Result<()>,
memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryStream> {
execute_with_row_consumer_profile_with_delivery(
plan,
catalog,
store,
parameters,
external,
max_rows,
max_payload_bytes,
consumer,
None,
memory,
StreamDelivery::Validated,
)
}
#[deprecated(note = "use execute_with_request_consumer")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_row_consumer_profile_and_external_and_context(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
consumer: &mut dyn FnMut(Row) -> Result<()>,
task_context: &RuntimeTaskContext,
) -> Result<ProfiledQueryStream> {
let memory = ExecutionMemoryConfig::default();
execute_with_row_consumer_profile_with_delivery(
plan,
catalog,
store,
parameters,
external,
max_rows,
max_payload_bytes,
consumer,
Some(task_context),
&memory,
StreamDelivery::Validated,
)
}
#[deprecated(note = "use execute_with_request_consumer")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_row_consumer_profile_and_external_and_context_and_memory(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
consumer: &mut dyn FnMut(Row) -> Result<()>,
task_context: &RuntimeTaskContext,
memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryStream> {
execute_with_row_consumer_profile_with_delivery(
plan,
catalog,
store,
parameters,
external,
max_rows,
max_payload_bytes,
consumer,
Some(task_context),
memory,
StreamDelivery::Validated,
)
}
#[allow(clippy::too_many_arguments)]
pub(crate) fn execute_with_row_consumer_profile_with_delivery(
plan: &PhysicalPlan,
catalog: &mut Catalog,
store: &mut impl ExecutionStore,
parameters: &BTreeMap<String, Value>,
external: &mut dyn ExternalReadOperator,
max_rows: Option<usize>,
max_payload_bytes: Option<usize>,
consumer: &mut dyn FnMut(Row) -> Result<()>,
task_context: Option<&RuntimeTaskContext>,
memory: &ExecutionMemoryConfig,
delivery: StreamDelivery,
) -> Result<ProfiledQueryStream> {
let bounded = max_rows.is_some() || max_payload_bytes.is_some();
execute_profiled_consumer(
ExecutionRequest::new(plan, parameters, memory)
.with_output_limits(max_rows, max_payload_bytes)
.with_optional_task_context(task_context),
ExecutionResources::new(catalog, store, external),
delivery.consumer_memory_mode(bounded),
consumer,
)
}
pub use hawdb_executor::observer::read_execution_profile;
#[cfg(test)]
#[path = "executor/tests.rs"]
mod tests;