risingwave_frontend/optimizer/plan_visitor/
sole_sys_table_visitor.rs

1// Copyright 2025 RisingWave Labs
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 super::{DefaultBehavior, LogicalPlanVisitor, Merge};
16use crate::optimizer::LogicalPlanRef;
17use crate::optimizer::plan_node::{LogicalSysScan, LogicalValues};
18use crate::optimizer::plan_visitor::PlanVisitor;
19
20#[derive(Debug, Clone, Default)]
21pub struct SoleSysTableVisitor {
22    has_sys_table: bool,
23}
24
25impl SoleSysTableVisitor {
26    pub fn sys_table_only(plan: LogicalPlanRef) -> bool {
27        let mut visitor = SoleSysTableVisitor {
28            has_sys_table: false,
29        };
30        visitor.visit(plan) && visitor.has_sys_table
31    }
32}
33
34impl LogicalPlanVisitor for SoleSysTableVisitor {
35    type Result = bool;
36
37    type DefaultBehavior = impl DefaultBehavior<Self::Result>;
38
39    fn default_behavior() -> Self::DefaultBehavior {
40        Merge(|a, b| a & b)
41    }
42
43    fn visit_logical_sys_scan(&mut self, _plan: &LogicalSysScan) -> bool {
44        self.has_sys_table = true;
45        true
46    }
47
48    fn visit_logical_values(&mut self, _plan: &LogicalValues) -> Self::Result {
49        // sys table together with values is ok
50        true
51    }
52}