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

Function plan_drop_objects

src/sql/src/plan/statement/ddl.rs:5409–5484  ·  view source on GitHub ↗
(
    scx: &mut StatementContext,
    DropObjectsStatement {
        object_type,
        if_exists,
        names,
        cascade,
    }: DropObjectsStatement,
)

Source from the content-addressed store, hash-verified

5407}
5408
5409pub 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 {

Callers 1

planFunction · 0.85

Calls 15

plan_drop_clusterFunction · 0.85
plan_drop_databaseFunction · 0.85
plan_drop_schemaFunction · 0.85
plan_drop_roleFunction · 0.85
plan_drop_item_nameFunction · 0.85
plan_drop_network_policyFunction · 0.85
to_ast_string_simpleMethod · 0.80
mapMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected