Skip to main content

oxirs_arq/executor/
stats.rs

1//! Execution Statistics
2//!
3//! This module provides statistics collection for query execution.
4
5use std::time::Duration;
6
7/// Join algorithm selection
8#[derive(Debug, Clone, Copy, PartialEq)]
9pub enum JoinAlgorithm {
10    NestedLoop,
11    Hash,
12    SortMerge,
13    IndexNestedLoop,
14}
15
16/// Query execution statistics
17#[derive(Debug, Clone, Default)]
18pub struct ExecutionStats {
19    /// Execution time
20    pub execution_time: Duration,
21    /// Number of intermediate results
22    pub intermediate_results: usize,
23    /// Number of final results
24    pub final_results: usize,
25    /// Memory used (estimated)
26    pub memory_used: usize,
27    /// Number of operations performed
28    pub operations: usize,
29    /// Number of property path evaluations
30    pub property_path_evaluations: usize,
31    /// Time spent on property path evaluations
32    pub time_spent_on_paths: Duration,
33    /// Number of service calls
34    pub service_calls: usize,
35    /// Time spent on service calls
36    pub time_spent_on_services: Duration,
37    /// Warnings during execution
38    pub warnings: Vec<String>,
39}
40
41impl ExecutionStats {
42    /// Create a new empty ExecutionStats instance
43    pub fn new() -> Self {
44        Self::default()
45    }
46
47    /// Merge statistics from another ExecutionStats instance
48    pub fn merge_from(&mut self, other: &ExecutionStats) {
49        self.execution_time += other.execution_time;
50        self.intermediate_results += other.intermediate_results;
51        self.final_results += other.final_results;
52        self.memory_used += other.memory_used;
53        self.operations += other.operations;
54        self.property_path_evaluations += other.property_path_evaluations;
55        self.time_spent_on_paths += other.time_spent_on_paths;
56        self.service_calls += other.service_calls;
57        self.time_spent_on_services += other.time_spent_on_services;
58        self.warnings.extend(other.warnings.clone());
59    }
60
61    /// Add a warning message
62    pub fn add_warning(&mut self, warning: String) {
63        self.warnings.push(warning);
64    }
65
66    /// Increment operations counter
67    pub fn increment_operations(&mut self) {
68        self.operations += 1;
69    }
70
71    /// Add memory usage
72    pub fn add_memory_usage(&mut self, bytes: usize) {
73        self.memory_used += bytes;
74    }
75}