MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / action

Method action

src/transform/src/fusion/join.rs:89–250  ·  view source on GitHub ↗

Fuses multiple `Join` operators into one `Join` operator. Return Ok(true) iff the action manipulated the tree after detecting the most general pattern.

(relation: &mut MirRelationExpr)

Source from the content-addressed store, hash-verified

87 /// Return Ok(true) iff the action manipulated the tree after detecting the
88 /// most general pattern.
89 pub fn action(relation: &mut MirRelationExpr) -> Result<bool, TransformError> {
90 if let MirRelationExpr::Join {
91 inputs,
92 equivalences,
93 ..
94 } = relation
95 {
96 // Local non-fusion tidying.
97 inputs.retain(|e| !e.is_constant_singleton());
98 if inputs.len() == 0 {
99 *relation = MirRelationExpr::constant(vec![vec![]], ReprRelationType::empty())
100 .filter(unpack_equivalences(equivalences));
101 return Ok(false);
102 }
103 if inputs.len() == 1 {
104 *relation = inputs
105 .pop()
106 .unwrap()
107 .filter(unpack_equivalences(equivalences));
108 return Ok(false);
109 }
110
111 // Bail early if no children are MFPs around a Join
112 if inputs.iter().any(|mut expr| {
113 let mut result = None;
114 while result.is_none() {
115 match expr {
116 MirRelationExpr::Map { input, .. }
117 | MirRelationExpr::Filter { input, .. }
118 | MirRelationExpr::Project { input, .. } => {
119 expr = &**input;
120 }
121 MirRelationExpr::Join { .. } => {
122 result = Some(true);
123 }
124 _ => {
125 result = Some(false);
126 }
127 }
128 }
129 result.unwrap()
130 }) {
131 // Each input is either an MFP around a Join, or just an expression.
132 let children = inputs
133 .iter()
134 .map(|expr| {
135 let (mfp, inner) = MapFilterProject::extract_from_expression(expr);
136 if let MirRelationExpr::Join {
137 inputs,
138 equivalences,
139 ..
140 } = inner
141 {
142 Ok((mfp, (inputs, equivalences)))
143 } else {
144 Err((mfp.projection.len(), expr))
145 }
146 })

Callers 1

Calls 15

unpack_equivalencesFunction · 0.85
is_constant_singletonMethod · 0.80
unwrapMethod · 0.80
anyMethod · 0.80
is_noneMethod · 0.80
sumMethod · 0.80
as_map_filter_projectMethod · 0.80
lenMethod · 0.45
filterMethod · 0.45
popMethod · 0.45
iterMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected