Skip to main content

hirn_exec/rules/
mod.rs

1//! Optimizer rules for the DataFusion execution engine.
2
3pub mod activation_fusion;
4pub mod depth_scheduling;
5pub mod namespace_partition_prune;
6pub mod policy_pushdown;
7pub mod prospective_short_circuit;
8pub mod temporal_index;
9
10pub use activation_fusion::ActivationFusionRule;
11pub use depth_scheduling::DepthSchedulingRule;
12pub use namespace_partition_prune::NamespacePartitionPruneRule;
13pub use policy_pushdown::PolicyPushdownRule;
14pub use prospective_short_circuit::{DEFAULT_PROSPECTIVE_THRESHOLD, ProspectiveShortCircuitExec};
15pub use temporal_index::TemporalIndexRule;
16
17use std::sync::Arc;
18
19use datafusion_physical_optimizer::PhysicalOptimizerRule;
20
21/// Returns all hirn physical optimizer rules.
22///
23/// These should be appended to the default DataFusion rules when constructing
24/// the `SessionState` for `HirnDB`. Called during `HirnDB::open_with_config()`
25/// setup to build a `SessionContext` with hirn-specific optimizations.
26///
27/// Rule ordering:
28/// 1. `PolicyPushdownRule` — inject namespace filters (must run first)
29/// 2. `NamespacePartitionPruneRule` — simplify IN to = for single namespace
30/// 3. `ActivationFusionRule` — fuse adjacent graph activation operators
31/// 4. `TemporalIndexRule` — rewrite temporal predicates for index usage
32/// 5. `DepthSchedulingRule` — prune operators based on query complexity (runs last)
33pub fn all_rules() -> Vec<Arc<dyn PhysicalOptimizerRule + Send + Sync>> {
34    vec![
35        Arc::new(PolicyPushdownRule::new()),
36        Arc::new(NamespacePartitionPruneRule::new()),
37        Arc::new(ActivationFusionRule::new()),
38        Arc::new(TemporalIndexRule::new()),
39        Arc::new(DepthSchedulingRule::new()),
40    ]
41}