Skip to main content

linkrs_query/
planning.rs

1//! Planner module for generating execution plans from AST
2//! Contains the Planner trait, ExecutionPlan structure, and various specific planners
3//!
4//! # Planning Pipeline
5//!
6//! The planning process consists of:
7//! 1. AST to Execution Plan conversion
8//! 2. Heuristic optimization (via `optimizer::heuristic`)
9//! 3. Cost-based optimization (via `optimizer::cost_based`)
10//!
11//! Note: The heuristic rewrite module has been moved to `optimizer::heuristic`.
12
13// Core modules
14pub mod connector;
15pub mod context;
16pub mod physical_mapper;
17pub mod physical_planner;
18pub mod plan;
19pub mod planner;
20pub mod template_extractor;
21
22// Planner modules
23pub mod fulltext_planner;
24#[cfg(feature = "vector")]
25pub mod vector_planner;
26
27// Modules organized by function
28pub mod join_order;
29pub mod scan_predicate;
30pub mod statements;
31
32// DML shape normalization for plan-cache reuse.
33pub mod dml_shape;
34
35// Re-export the main types.
36pub use connector::SegmentsConnector;
37pub use plan::execution_plan::{ExecutionPlan, SubPlan};
38pub use planner::{Planner, PlannerConfig, PlannerError};
39pub use template_extractor::{ParameterizedResult, ParameterizingTransformer, TemplateExtractor};
40
41// Re-export the JoinType from the core module.
42pub use linkrs_core::types::JoinType;
43pub use statements::MatchStatementPlanner;
44
45// Export related to static registration
46pub use planner::PlannerEnum;
47
48use std::sync::atomic::{AtomicI64, Ordering};
49
50pub struct PlanIdGenerator {
51    counter: AtomicI64,
52}
53
54impl PlanIdGenerator {
55    pub fn instance() -> &'static Self {
56        static INSTANCE: PlanIdGenerator = PlanIdGenerator {
57            counter: AtomicI64::new(0),
58        };
59        &INSTANCE
60    }
61
62    pub fn next_id(&self) -> i64 {
63        self.counter.fetch_add(1, Ordering::SeqCst)
64    }
65}