risingwave_frontend/optimizer/rule/
apply_share_eliminate_rule.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::prelude::{PlanRef, *};
16use crate::optimizer::plan_node::{LogicalApply, LogicalShare, PlanTreeNodeUnary};
17
18/// Eliminate `LogicalShare` for `LogicalApply`.
19pub struct ApplyShareEliminateRule {}
20impl Rule<Logical> for ApplyShareEliminateRule {
21    fn apply(&self, plan: PlanRef) -> Option<PlanRef> {
22        let apply: &LogicalApply = plan.as_logical_apply()?;
23        let (left, right, on, join_type, correlated_id, correlated_indices, max_one_row) =
24            apply.clone().decompose();
25
26        let share: &LogicalShare = right.as_logical_share()?;
27        // Eliminate the share operator
28        Some(LogicalApply::create(
29            left,
30            share.input(),
31            join_type,
32            on,
33            correlated_id,
34            correlated_indices,
35            max_one_row,
36        ))
37    }
38}
39
40impl ApplyShareEliminateRule {
41    pub fn create() -> BoxedRule {
42        Box::new(ApplyShareEliminateRule {})
43    }
44}