1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
910//! Transformations that fuse together others of their kind.
1112pub mod filter;
13pub mod join;
14pub mod map;
15pub mod negate;
16pub mod project;
17pub mod reduce;
18pub mod top_k;
19pub mod union;
2021use mz_expr::MirRelationExpr;
2223use crate::TransformCtx;
2425/// Fuses multiple like operators together when possible.
26#[derive(Debug)]
27pub struct Fusion;
2829impl crate::Transform for Fusion {
30fn name(&self) -> &'static str {
31"Fusion"
32}
3334#[mz_ore::instrument(
35 target = "optimizer",
36 level = "debug",
37 fields(path.segment = "fusion")
38 )]
39fn actually_perform_transform(
40&self,
41 relation: &mut MirRelationExpr,
42_: &mut TransformCtx,
43 ) -> Result<(), crate::TransformError> {
44use mz_expr::visit::Visit;
45 relation.visit_mut_post(&mut Self::action)?;
46 mz_repr::explain::trace_plan(&*relation);
47Ok(())
48 }
49}
5051impl Fusion {
52/// Apply fusion action for variants we know how to fuse.
53pub(crate) fn action(expr: &mut MirRelationExpr) {
54match expr {
55 MirRelationExpr::Filter { .. } => filter::Filter::action(expr),
56 MirRelationExpr::Map { .. } => map::Map::action(expr),
57 MirRelationExpr::Project { .. } => project::Project::action(expr),
58 MirRelationExpr::Negate { .. } => negate::Negate::action(expr),
59 MirRelationExpr::TopK { .. } => top_k::TopK::action(expr),
60 MirRelationExpr::Union { .. } => union::Union::action(expr),
61_ => {}
62 }
63 }
64}