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

Method memoize_expressions

src/expr/src/linear.rs:1141–1197  ·  view source on GitHub ↗

Place each certainly evaluated expression in its own column. This method places each non-trivial, certainly evaluated expression in its own column, and deduplicates them so that all references to the same expression reference the same column. This transformation is restricted to expressions we are certain will be evaluated, which does not include expressions in `if` statements. # Example This

(&mut self)

Source from the content-addressed store, hash-verified

1139 /// );
1140 /// ```
1141 pub fn memoize_expressions(&mut self) {
1142 // Record the mapping from starting column references to new column
1143 // references.
1144 let mut remaps = BTreeMap::new();
1145 for index in 0..self.input_arity {
1146 remaps.insert(index, index);
1147 }
1148 let mut new_expressions = Vec::new();
1149
1150 // We follow the same order as for evaluation, to ensure that all
1151 // column references exist in time for their evaluation. We could
1152 // prioritize predicates, but we would need to be careful to chase
1153 // down column references to expressions and memoize those as well.
1154 let mut expression = 0;
1155 for (support, predicate) in self.predicates.iter_mut() {
1156 while self.input_arity + expression < *support {
1157 self.expressions[expression].permute_map(&remaps);
1158 memoize_expr(
1159 &mut self.expressions[expression],
1160 &mut new_expressions,
1161 self.input_arity,
1162 );
1163 remaps.insert(
1164 self.input_arity + expression,
1165 self.input_arity + new_expressions.len(),
1166 );
1167 new_expressions.push(self.expressions[expression].clone());
1168 expression += 1;
1169 }
1170 predicate.permute_map(&remaps);
1171 memoize_expr(predicate, &mut new_expressions, self.input_arity);
1172 }
1173 while expression < self.expressions.len() {
1174 self.expressions[expression].permute_map(&remaps);
1175 memoize_expr(
1176 &mut self.expressions[expression],
1177 &mut new_expressions,
1178 self.input_arity,
1179 );
1180 remaps.insert(
1181 self.input_arity + expression,
1182 self.input_arity + new_expressions.len(),
1183 );
1184 new_expressions.push(self.expressions[expression].clone());
1185 expression += 1;
1186 }
1187
1188 self.expressions = new_expressions;
1189 for proj in self.projection.iter_mut() {
1190 *proj = remaps[proj];
1191 }
1192
1193 // Restore predicate order invariants.
1194 for (pos, pred) in self.predicates.iter_mut() {
1195 *pos = pred.support().last().map(|x| *x + 1).unwrap_or(0);
1196 }
1197 }
1198

Callers 2

extract_commonMethod · 0.80
optimizeMethod · 0.80

Calls 9

memoize_exprFunction · 0.85
permute_mapMethod · 0.80
lastMethod · 0.80
insertMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
mapMethod · 0.45
supportMethod · 0.45

Tested by

no test coverage detected