risingwave_frontend/optimizer/rule/
union_to_distinct_rule.rs1use super::{BoxedRule, Rule};
16use crate::optimizer::PlanRef;
17use crate::optimizer::plan_node::generic::{Agg, GenericPlanRef};
18use crate::optimizer::plan_node::{LogicalUnion, PlanTreeNode};
19
20pub struct UnionToDistinctRule {}
22impl Rule for UnionToDistinctRule {
23 fn apply(&self, plan: PlanRef) -> Option<PlanRef> {
24 let union: &LogicalUnion = plan.as_logical_union()?;
25 if !union.all() {
26 let union_all = LogicalUnion::create(true, union.inputs().into_iter().collect());
27 let distinct = Agg::new(vec![], (0..union.base.schema().len()).collect(), union_all)
28 .with_enable_two_phase(false);
29 Some(distinct.into())
30 } else {
31 None
32 }
33 }
34}
35
36impl UnionToDistinctRule {
37 pub fn create() -> BoxedRule {
38 Box::new(UnionToDistinctRule {})
39 }
40}