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

Function plan_drop_schema

src/sql/src/plan/statement/ddl.rs:5486–5522  ·  view source on GitHub ↗
(
    scx: &StatementContext,
    if_exists: bool,
    name: &UnresolvedSchemaName,
    cascade: bool,
)

Source from the content-addressed store, hash-verified

5484}
5485
5486fn plan_drop_schema(
5487 scx: &StatementContext,
5488 if_exists: bool,
5489 name: &UnresolvedSchemaName,
5490 cascade: bool,
5491) -> Result<Option<(ResolvedDatabaseSpecifier, SchemaSpecifier)>, PlanError> {
5492 // Special case for mz_temp: with lazy temporary schema creation, the temp
5493 // schema may not exist yet, but we still need to return the correct error.
5494 // Check the schema name directly against MZ_TEMP_SCHEMA.
5495 let normalized = normalize::unresolved_schema_name(name.clone())?;
5496 if normalized.database.is_none() && normalized.schema == mz_repr::namespaces::MZ_TEMP_SCHEMA {
5497 sql_bail!("cannot drop schema {name} because it is a temporary schema",)
5498 }
5499
5500 Ok(match resolve_schema(scx, name.clone(), if_exists)? {
5501 Some((database_spec, schema_spec)) => {
5502 if let ResolvedDatabaseSpecifier::Ambient = database_spec {
5503 sql_bail!(
5504 "cannot drop schema {name} because it is required by the database system",
5505 );
5506 }
5507 if let SchemaSpecifier::Temporary = schema_spec {
5508 sql_bail!("cannot drop schema {name} because it is a temporary schema",)
5509 }
5510 let schema = scx.get_schema(&database_spec, &schema_spec);
5511 if !cascade && schema.has_items() {
5512 let full_schema_name = scx.catalog.resolve_full_schema_name(schema.name());
5513 sql_bail!(
5514 "schema '{}' cannot be dropped without CASCADE while it contains objects",
5515 full_schema_name
5516 );
5517 }
5518 Some((database_spec, schema_spec))
5519 }
5520 None => None,
5521 })
5522}
5523
5524fn plan_drop_role(
5525 scx: &StatementContext,

Callers 1

plan_drop_objectsFunction · 0.85

Calls 8

unresolved_schema_nameFunction · 0.85
resolve_schemaFunction · 0.85
is_noneMethod · 0.80
cloneMethod · 0.45
get_schemaMethod · 0.45
has_itemsMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected