risingwave_frontend/optimizer/rule/
trivial_project_to_values_rule.rs1use super::{BoxedRule, Rule};
16use crate::optimizer::plan_node::generic::GenericPlanRef;
17use crate::optimizer::plan_node::{LogicalValues, PlanTreeNodeUnary};
18use crate::optimizer::plan_visitor::{LogicalCardinalityExt, SideEffectVisitor};
19use crate::optimizer::{PlanRef, PlanVisitor};
20
21pub struct TrivialProjectToValuesRule {}
22impl Rule for TrivialProjectToValuesRule {
23 fn apply(&self, plan: PlanRef) -> Option<PlanRef> {
24 let project = plan.as_logical_project()?;
25
26 if !project.exprs().iter().all(|e| e.is_const()) {
27 return None;
28 }
29 if SideEffectVisitor.visit(project.input()) {
30 return None;
31 }
32
33 let row_count = project.input().row_count()?;
34 let values = LogicalValues::new(
35 vec![project.exprs().clone(); row_count],
36 project.schema().clone(),
37 project.ctx(),
38 );
39 Some(values.into())
40 }
41}
42
43impl TrivialProjectToValuesRule {
44 pub fn create() -> BoxedRule {
45 Box::new(TrivialProjectToValuesRule {})
46 }
47}