(
scx: &mut StatementContext,
DropObjectsStatement {
object_type,
if_exists,
names,
cascade,
}: DropObjectsStatement,
)
| 5407 | } |
| 5408 | |
| 5409 | pub fn plan_drop_objects( |
| 5410 | scx: &mut StatementContext, |
| 5411 | DropObjectsStatement { |
| 5412 | object_type, |
| 5413 | if_exists, |
| 5414 | names, |
| 5415 | cascade, |
| 5416 | }: DropObjectsStatement, |
| 5417 | ) -> Result<Plan, PlanError> { |
| 5418 | if object_type == mz_sql_parser::ast::ObjectType::Func { |
| 5419 | bail_unsupported!("DROP FUNCTION"); |
| 5420 | } |
| 5421 | let object_type = object_type.into(); |
| 5422 | |
| 5423 | let mut referenced_ids = Vec::new(); |
| 5424 | for name in names { |
| 5425 | let id = match &name { |
| 5426 | UnresolvedObjectName::Cluster(name) => { |
| 5427 | plan_drop_cluster(scx, if_exists, name, cascade)?.map(ObjectId::Cluster) |
| 5428 | } |
| 5429 | UnresolvedObjectName::ClusterReplica(name) => { |
| 5430 | plan_drop_cluster_replica(scx, if_exists, name)?.map(ObjectId::ClusterReplica) |
| 5431 | } |
| 5432 | UnresolvedObjectName::Database(name) => { |
| 5433 | plan_drop_database(scx, if_exists, name, cascade)?.map(ObjectId::Database) |
| 5434 | } |
| 5435 | UnresolvedObjectName::Schema(name) => { |
| 5436 | plan_drop_schema(scx, if_exists, name, cascade)?.map(ObjectId::Schema) |
| 5437 | } |
| 5438 | UnresolvedObjectName::Role(name) => { |
| 5439 | plan_drop_role(scx, if_exists, name)?.map(ObjectId::Role) |
| 5440 | } |
| 5441 | UnresolvedObjectName::Item(name) => { |
| 5442 | // Defer the dependency check until all names are resolved, so a |
| 5443 | // dependent that is itself being dropped in this same statement |
| 5444 | // does not block a non-cascade drop. |
| 5445 | plan_drop_item_name(scx, object_type, if_exists, name.clone())?.map(ObjectId::Item) |
| 5446 | } |
| 5447 | UnresolvedObjectName::NetworkPolicy(name) => { |
| 5448 | plan_drop_network_policy(scx, if_exists, name)?.map(ObjectId::NetworkPolicy) |
| 5449 | } |
| 5450 | }; |
| 5451 | match id { |
| 5452 | Some(id) => referenced_ids.push(id), |
| 5453 | None => scx.catalog.add_notice(PlanNotice::ObjectDoesNotExist { |
| 5454 | name: name.to_ast_string_simple(), |
| 5455 | object_type, |
| 5456 | }), |
| 5457 | } |
| 5458 | } |
| 5459 | |
| 5460 | // Now that the full set of explicitly-named items is known, run the |
| 5461 | // non-cascade dependency check. A dependent that is itself being dropped in |
| 5462 | // this statement does not block the drop, matching PostgreSQL. |
| 5463 | if !cascade { |
| 5464 | let dropped_items: BTreeSet<CatalogItemId> = referenced_ids |
| 5465 | .iter() |
| 5466 | .filter_map(|id| match id { |
no test coverage detected