risingwave_frontend/planner/
mod.rs1use std::collections::HashMap;
16
17use crate::binder::{BoundStatement, ShareId};
18use crate::error::Result;
19use crate::optimizer::{OptimizerContextRef, PlanRoot};
20
21mod changelog;
22mod delete;
23mod insert;
24mod query;
25mod recursive_union;
26mod relation;
27mod select;
28mod set_expr;
29mod set_operation;
30mod statement;
31mod update;
32mod values;
33pub use query::LIMIT_ALL_COUNT;
34
35use crate::PlanRef;
36
37pub struct Planner {
39 ctx: OptimizerContextRef,
40 share_cache: HashMap<ShareId, PlanRef>,
43 plan_for: PlanFor,
45}
46
47#[derive(Debug, Copy, Clone)]
48pub enum PlanFor {
49 Stream,
50 Batch,
51 BatchDql,
54}
55
56impl Planner {
57 pub fn new_for_batch_dql(ctx: OptimizerContextRef) -> Planner {
58 Planner {
59 ctx,
60 share_cache: Default::default(),
61 plan_for: PlanFor::BatchDql,
62 }
63 }
64
65 pub fn new_for_batch(ctx: OptimizerContextRef) -> Planner {
66 Planner {
67 ctx,
68 share_cache: Default::default(),
69 plan_for: PlanFor::Batch,
70 }
71 }
72
73 pub fn new_for_stream(ctx: OptimizerContextRef) -> Planner {
74 Planner {
75 ctx,
76 share_cache: Default::default(),
77 plan_for: PlanFor::Stream,
78 }
79 }
80
81 pub fn plan(&mut self, stmt: BoundStatement) -> Result<PlanRoot> {
83 self.plan_statement(stmt)
84 }
85
86 pub fn ctx(&self) -> OptimizerContextRef {
87 self.ctx.clone()
88 }
89
90 pub fn plan_for(&self) -> PlanFor {
91 self.plan_for
92 }
93}