linkrs_query/optimizer/analysis.rs
1//! Plan Analysis Module
2//!
3//! Provides an analysis of query plans, supporting decision-making processes related to optimization.
4//! Quote Count Analysis: Identifying Sub-plans That Are Cited Multiple Times
5//! Expression analysis: Examining the characteristics of an expression (such as determinacy, complexity, etc.)
6//! Fingerprint calculation: Calculating the structural fingerprint of the planning nodes
7//!
8//! # Explanation of the module locations
9//!
10//! This module is located in `src/query/optimizer/analysis/` and is at the same level as the `cost` module.
11//! Reason for placing it in the optimizer rather than the planner:
12//! Separation of responsibilities: The planner is responsible for generating plans, while the optimizer is responsible for optimizing these plans.
13//! 2. Calculation on demand: Analysis is only performed during the optimization phase, as and when necessary.
14//! 3. Dependency relationships: The optimizer already depends on the planner; therefore, no circular dependencies will be introduced.
15//!
16//! # Usage Examples
17//!
18//! ```rust
19//! use linkrs_query::optimizer::analysis::{
20//! ExpressionAnalyzer,
21//! ReferenceCountAnalyzer,
22//! };
23//!
24//! let ref_analyzer = ReferenceCountAnalyzer::new();
25//! let expr_analyzer = ExpressionAnalyzer::new();
26//!
27//! // Count how many times sub-plans are referenced (needs a full plan):
28//! // let ref_analysis = ref_analyzer.analyze(plan.root());
29//! // Analyze an expression's characteristics (determinism, complexity, etc.):
30//! // let expr_analysis = expr_analyzer.analyze(condition);
31//! ```
32
33pub mod batch;
34pub mod expression;
35pub mod fingerprint;
36pub mod reference_count;
37pub mod required_properties;
38
39// Re-export the main types
40pub use batch::{AggregatedExpressionAnalysis, BatchPlanAnalysis, BatchPlanAnalyzer};
41pub use expression::{
42 AnalysisMode, AnalysisOptions, ExpressionAnalysis, ExpressionAnalyzer, NondeterministicChecker,
43};
44pub use fingerprint::{FingerprintCalculator, PlanFingerprint};
45pub use reference_count::{
46 ReferenceCountAnalysis, ReferenceCountAnalyzer, SubplanId, SubplanReferenceInfo,
47};
48pub use required_properties::{
49 binding_var, PropertyRequirement, RequiredPropertiesMap, RequiredPropertyAnalyzer,
50};
51
52#[cfg(test)]
53mod integration_test;