(&mut self, expr: HirRelationExpr)
| 88 | type To = OptimizedMirRelationExpr; |
| 89 | |
| 90 | fn optimize(&mut self, expr: HirRelationExpr) -> Result<Self::To, OptimizerError> { |
| 91 | let time = Instant::now(); |
| 92 | |
| 93 | // Trace the pipeline input under `optimize/raw`. |
| 94 | trace_plan!(at: "raw", &expr); |
| 95 | |
| 96 | // HIR ⇒ MIR lowering and decorrelation |
| 97 | let mut expr = expr.lower(&self.config, self.metrics.as_ref())?; |
| 98 | |
| 99 | let mut df_meta = DataflowMetainfo::default(); |
| 100 | let mut transform_ctx = TransformCtx::local( |
| 101 | &self.config.features, |
| 102 | &self.typecheck_ctx, |
| 103 | &mut df_meta, |
| 104 | self.metrics.as_mut(), |
| 105 | None, |
| 106 | ); |
| 107 | |
| 108 | // First, we run a very simple optimizer pipeline, which only folds constants. This takes |
| 109 | // care of constant INSERTs. (This optimizer is also used for INSERTs, not just VIEWs.) |
| 110 | expr = optimize_mir_constant(expr, &mut transform_ctx, self.fold_constants_limit)?; |
| 111 | |
| 112 | // MIR ⇒ MIR optimization (local) |
| 113 | let expr = if expr.as_const().is_some() { |
| 114 | // No need to optimize further, because we already have a constant. |
| 115 | // But trace this at "local", so that `EXPLAIN LOCALLY OPTIMIZED PLAN` can pick it up. |
| 116 | trace_plan!(at: "local", &expr); |
| 117 | OptimizedMirRelationExpr(expr) |
| 118 | } else { |
| 119 | // Do the real optimization (starting with `expr_prep_style`). |
| 120 | let mut opt_expr = OptimizedMirRelationExpr(expr); |
| 121 | self.expr_prep_style.prep_relation_expr(&mut opt_expr)?; |
| 122 | expr = opt_expr.into_inner(); |
| 123 | optimize_mir_local(expr, &mut transform_ctx)? |
| 124 | }; |
| 125 | |
| 126 | if let Some(metrics) = &self.metrics { |
| 127 | metrics.observe_e2e_optimization_time("view", time.elapsed()); |
| 128 | } |
| 129 | |
| 130 | // TODO: Handle the `optimizer_notices` in `df_meta`. |
| 131 | // https://github.com/MaterializeInc/database-issues/issues/10012 |
| 132 | |
| 133 | // Return the resulting OptimizedMirRelationExpr. |
| 134 | Ok(expr) |
| 135 | } |
| 136 | } |
no test coverage detected