(
pcx: Option<&PlanContext>,
catalog: &dyn SessionCatalog,
stmt: Statement<Aug>,
params: &Params,
resolved_ids: &ResolvedIds,
)
| 286 | /// statements as not necessarily depending on external state. |
| 287 | #[mz_ore::instrument(level = "debug")] |
| 288 | pub fn plan( |
| 289 | pcx: Option<&PlanContext>, |
| 290 | catalog: &dyn SessionCatalog, |
| 291 | stmt: Statement<Aug>, |
| 292 | params: &Params, |
| 293 | resolved_ids: &ResolvedIds, |
| 294 | ) -> Result<(Plan, ResolvedIds), PlanError> { |
| 295 | let param_types = params |
| 296 | // We need the `expected_types` here, not the `actual_types`! This is because |
| 297 | // `expected_types` is how the parameter expression (e.g. `$1`) looks "from the outside": |
| 298 | // `bind_parameters` will insert a cast from the actual type to the expected type. |
| 299 | .expected_types |
| 300 | .iter() |
| 301 | .enumerate() |
| 302 | .map(|(i, ty)| (i + 1, ty.clone())) |
| 303 | .collect(); |
| 304 | |
| 305 | let kind: StatementKind = (&stmt).into(); |
| 306 | let permitted_plans = Plan::generated_from(&kind); |
| 307 | |
| 308 | let scx = &mut StatementContext { |
| 309 | pcx, |
| 310 | catalog, |
| 311 | param_types: RefCell::new(param_types), |
| 312 | ambiguous_columns: RefCell::new(false), |
| 313 | sql_impl_resolved_ids: Arc::new(Mutex::new(ResolvedIds::empty())), |
| 314 | }; |
| 315 | |
| 316 | if resolved_ids |
| 317 | .items() |
| 318 | // Filter out items that may not have been created yet, such as sub-sources. |
| 319 | .filter_map(|id| catalog.try_get_item(id)) |
| 320 | .any(|item| { |
| 321 | item.func().is_ok() |
| 322 | && item.name().qualifiers.schema_spec |
| 323 | == SchemaSpecifier::Id(catalog.get_mz_unsafe_schema_id()) |
| 324 | }) |
| 325 | { |
| 326 | scx.require_feature_flag(&vars::UNSAFE_ENABLE_UNSAFE_FUNCTIONS)?; |
| 327 | } |
| 328 | |
| 329 | let plan = match stmt { |
| 330 | // DDL statements. |
| 331 | Statement::AlterCluster(stmt) => ddl::plan_alter_cluster(scx, stmt), |
| 332 | Statement::AlterConnection(stmt) => ddl::plan_alter_connection(scx, stmt), |
| 333 | Statement::AlterIndex(stmt) => ddl::plan_alter_index_options(scx, stmt), |
| 334 | Statement::AlterMaterializedViewApplyReplacement(stmt) => { |
| 335 | ddl::plan_alter_materialized_view_apply_replacement(scx, stmt) |
| 336 | } |
| 337 | Statement::AlterObjectRename(stmt) => ddl::plan_alter_object_rename(scx, stmt), |
| 338 | Statement::AlterObjectSwap(stmt) => ddl::plan_alter_object_swap(scx, stmt), |
| 339 | Statement::AlterRetainHistory(stmt) => ddl::plan_alter_retain_history(scx, stmt), |
| 340 | Statement::AlterRole(stmt) => ddl::plan_alter_role(scx, stmt), |
| 341 | Statement::AlterSecret(stmt) => ddl::plan_alter_secret(scx, stmt), |
| 342 | Statement::AlterSetCluster(stmt) => ddl::plan_alter_item_set_cluster(scx, stmt), |
| 343 | Statement::AlterSink(stmt) => ddl::plan_alter_sink(scx, stmt), |
| 344 | Statement::AlterSource(stmt) => ddl::plan_alter_source(scx, stmt), |
| 345 | Statement::AlterSystemSet(stmt) => ddl::plan_alter_system_set(scx, stmt), |
nothing calls this directly
no test coverage detected