(&mut self, index: Index)
| 138 | type To = GlobalMirPlan; |
| 139 | |
| 140 | fn optimize(&mut self, index: Index) -> Result<Self::To, OptimizerError> { |
| 141 | let time = Instant::now(); |
| 142 | |
| 143 | let on_entry = self.catalog.get_entry(&index.on); |
| 144 | let full_name = self |
| 145 | .catalog |
| 146 | .resolve_full_name(&index.name, on_entry.conn_id()); |
| 147 | let on_desc = on_entry |
| 148 | .relation_desc() |
| 149 | .expect("can only create indexes on items with a valid description"); |
| 150 | |
| 151 | let mut df_builder = { |
| 152 | let compute = self.compute_instance.clone(); |
| 153 | DataflowBuilder::new(&*self.catalog, compute).with_config(&self.config) |
| 154 | }; |
| 155 | let mut df_desc = MirDataflowDescription::new(full_name.to_string()); |
| 156 | |
| 157 | df_builder.import_into_dataflow(&index.on, &mut df_desc, &self.config.features)?; |
| 158 | df_builder.maybe_reoptimize_imported_views(&mut df_desc, &self.config)?; |
| 159 | |
| 160 | let index_desc = IndexDesc { |
| 161 | on_id: index.on, |
| 162 | key: index.keys.clone(), |
| 163 | }; |
| 164 | df_desc.export_index( |
| 165 | self.exported_index_id, |
| 166 | index_desc, |
| 167 | ReprRelationType::from(on_desc.typ()), |
| 168 | ); |
| 169 | |
| 170 | // Prepare expressions in the assembled dataflow. |
| 171 | let style = ExprPrepMaintained; |
| 172 | df_desc.visit_children( |
| 173 | |r| style.prep_relation_expr(r), |
| 174 | |s| style.prep_scalar_expr(s), |
| 175 | )?; |
| 176 | |
| 177 | // Construct TransformCtx for global optimization. |
| 178 | let mut df_meta = DataflowMetainfo::default(); |
| 179 | let mut transform_ctx = TransformCtx::global( |
| 180 | &df_builder, |
| 181 | &mz_transform::EmptyStatisticsOracle, // TODO: wire proper stats |
| 182 | &self.config.features, |
| 183 | &self.typecheck_ctx, |
| 184 | &mut df_meta, |
| 185 | Some(&mut self.metrics), |
| 186 | ); |
| 187 | // Run global optimization. |
| 188 | mz_transform::optimize_dataflow(&mut df_desc, &mut transform_ctx, false)?; |
| 189 | |
| 190 | if self.config.mode == OptimizeMode::Explain { |
| 191 | // Collect the list of indexes used by the dataflow at this point. |
| 192 | trace_plan!(at: "global", &df_meta.used_indexes(&df_desc)); |
| 193 | } |
| 194 | |
| 195 | // Emit a notice if we are trying to create an empty index. |
| 196 | if index.keys.is_empty() { |
| 197 | df_meta.push_optimizer_notice_dedup(IndexKeyEmpty); |
nothing calls this directly
no test coverage detected