risingwave_frontend/planner/
set_operation.rs1use risingwave_common::util::column_index_mapping::ColIndexMapping;
16
17use crate::binder::{BoundSetExpr, BoundSetOperation};
18use crate::error::Result;
19use crate::optimizer::plan_node::{
20 LogicalExcept, LogicalIntersect, LogicalPlanRef as PlanRef, LogicalProject, LogicalUnion,
21};
22use crate::planner::Planner;
23
24impl Planner {
25 pub(super) fn plan_set_operation(
26 &mut self,
27 op: BoundSetOperation,
28 all: bool,
29 corresponding_col_indices: Option<(ColIndexMapping, ColIndexMapping)>,
30 left: BoundSetExpr,
31 right: BoundSetExpr,
32 ) -> Result<PlanRef> {
33 let left = self.plan_set_expr(left, vec![], &[])?;
34 let right = self.plan_set_expr(right, vec![], &[])?;
35
36 let (left, right) = if let Some((mapping_l, mapping_r)) = corresponding_col_indices {
38 (
39 LogicalProject::with_mapping(left, mapping_l).into(),
40 LogicalProject::with_mapping(right, mapping_r).into(),
41 )
42 } else {
43 (left, right)
44 };
45
46 match op {
47 BoundSetOperation::Union => Ok(LogicalUnion::create(all, vec![left, right])),
48 BoundSetOperation::Intersect => Ok(LogicalIntersect::create(all, vec![left, right])),
49 BoundSetOperation::Except => Ok(LogicalExcept::create(all, vec![left, right])),
50 }
51 }
52}