Skip to main content

hawdb_relational/
read_profile.rs

1// Copyright 2026 Nowledge
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use hawdb_executor::{BlockingOperatorMemoryReport, QueryOutput};
16use hawdb_optimizer::{RelationalJoinPlanningOutcome, RelationalOperatorCardinalityProfile};
17use hawdb_sql::RelationalSqlStageTimings;
18
19/// Output and execution evidence for a relational SQL read.
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct ProfiledRelationalSqlQueryOutput {
22    pub output: QueryOutput,
23    pub profile: RelationalSqlReadProfile,
24}
25
26/// Relational execution evidence collected while producing a query result.
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct RelationalSqlReadProfile {
29    pub stage_timings: RelationalSqlStageTimings,
30    pub join_planning: RelationalJoinPlanningOutcome,
31    /// Base access followed by join operators in plan execution order.
32    pub operator_cardinality_profiles: Vec<RelationalOperatorCardinalityProfile>,
33    pub intermediate_rows: usize,
34    pub hydrated_rows: usize,
35    pub hydrated_compressed_bytes: usize,
36    pub hydrated_decompressed_bytes: usize,
37    pub index_reads: Vec<RelationalSqlIndexReadProfile>,
38    pub row_read: RelationalSqlRowReadProfile,
39    /// Memory and spill evidence for blocking relational operators.
40    pub blocking_operator_memory_reports: Vec<BlockingOperatorMemoryReport>,
41    /// Postings and blocks a `text_search` scan visited and skipped.
42    pub search_index_scan: Option<crate::query::text_search::SearchIndexScanEvidence>,
43}
44
45/// I/O counters for one relational index access path.
46#[derive(Debug, Clone, PartialEq, Eq)]
47pub struct RelationalSqlIndexReadProfile {
48    pub table: String,
49    pub index: String,
50    /// All admitted index operations, including planning metadata counts.
51    pub lookups: usize,
52    /// Planning counts do not establish an execution runtime path. Their I/O
53    /// remains included in every counter below, including count-cache reuse.
54    pub metadata_count_lookups: usize,
55    /// Execution authority only; metadata-only reads report `not_executed`.
56    pub runtime_path: String,
57    pub logical_pages: usize,
58    pub logical_bytes: usize,
59    pub physical_pages: usize,
60    pub physical_bytes: usize,
61    pub cache_hits: usize,
62    pub cache_misses: usize,
63    pub cache_admission_rejections: usize,
64    pub rows_visited: usize,
65}
66
67/// I/O counters and snapshot identity for relational row-page reads.
68#[derive(Debug, Clone, PartialEq, Eq)]
69pub struct RelationalSqlRowReadProfile {
70    pub runtime_path: String,
71    pub projection_generation: Option<String>,
72    pub projection_source_watermark: Option<u64>,
73    pub projection_version: Option<u64>,
74    pub projection_publication_commit_epoch: Option<u64>,
75    pub base_generation: Option<u64>,
76    pub delta_generation: Option<u64>,
77    pub base_commit_epoch: Option<u64>,
78    pub visible_commit_epoch: Option<u64>,
79    pub root_set_digest: Option<String>,
80    pub descriptor_reads: usize,
81    pub logical_pages: usize,
82    pub logical_bytes: usize,
83    pub physical_pages: usize,
84    pub physical_bytes: usize,
85    pub cache_hits: usize,
86    pub cache_misses: usize,
87    pub cache_admission_rejections: usize,
88    pub rows_visited: usize,
89    pub overlay_entries: usize,
90    pub overlay_resident_bytes: usize,
91    /// Recursive-term evaluations completed by this statement.
92    pub recursive_iterations: usize,
93    /// Largest recursive working-table cardinality.
94    pub recursive_working_rows_peak: usize,
95    /// Rows retained by recursive unions before the outer query tail.
96    pub recursive_rows_emitted: usize,
97    /// Cumulative admitted seed and recursive-term work.
98    pub recursive_work: usize,
99}