prestodb/presto · error · SemanticException

MISSING_SCHEMA

MISSING_SCHEMA

Error message

Schema '%s' does not exist

What it means

Thrown by DropTableTask.execute when the catalog exists but the schema does not, and the statement does not tolerate it. The check uses metadataResolver.schemaExists(tableName.getCatalogSchemaName()) and fires before the table handle lookup.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/execution/DropTableTask.java:60

{
    @Override
    public String getName()
    {
        return "DROP TABLE";
    }

    @Override
    public ListenableFuture<?> execute(DropTable statement, TransactionManager transactionManager, Metadata metadata, AccessControl accessControl, Session session, List<Expression> parameters, WarningCollector warningCollector, String query)
    {
        QualifiedObjectName tableName = createQualifiedObjectName(session, statement, statement.getTableName(), metadata);
        MetadataResolver metadataResolver = metadata.getMetadataResolver(session);

        if (!metadataResolver.catalogExists(tableName.getCatalogName())) {
            throw new SemanticException(MISSING_CATALOG, "Catalog '%s' does not exist", tableName.getCatalogName());
        }

        if (!metadataResolver.schemaExists(tableName.getCatalogSchemaName())) {
            throw new SemanticException(MISSING_SCHEMA, statement, "Schema '%s' does not exist", tableName.getSchemaName());
        }

        Optional<TableHandle> tableHandle = metadataResolver.getTableHandle(tableName);
        if (!tableHandle.isPresent()) {
            if (!statement.isExists()) {
                throw new SemanticException(MISSING_TABLE, statement, "Table '%s' does not exist", tableName);
            }
            return immediateFuture(null);
        }

        Optional<MaterializedViewDefinition> optionalMaterializedView = metadataResolver.getMaterializedView(tableName);
        if (optionalMaterializedView.isPresent()) {
            if (!statement.isExists()) {
                throw new SemanticException(NOT_SUPPORTED, statement, "'%s' is a materialized view, not a table. Use DROP MATERIALIZED VIEW to drop.", tableName);
            }
            return immediateFuture(null);
        }

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Run SHOW SCHEMAS FROM <catalog> and correct the schema name.
  2. Guard with explicit existence checks in scripts before issuing DROP TABLE.
  3. Verify the schema/database still exists in the underlying system (e.g. hive metastore).

Example fix

// before
DROP TABLE hive.wrong_schema.events;
// after
DROP TABLE hive.default.events;
Defensive patterns

Strategy: validation

Validate before calling

-- verify schema exists before DROP TABLE
SELECT schema_name FROM information_schema.schemata
WHERE catalog_name = 'hive' AND schema_name = 'default';
-- skip the DROP TABLE if no row returned

Prevention

When it happens

Trigger: DROP TABLE catalog.schema.table where schemaExists is false; note the message prints tableName.getSchemaName() so the catalog prefix is absent from the error text.

Common situations: Typo in schema name; schema dropped by cleanup jobs; Hive database deleted externally; default-schema assumptions (e.g. script assumes 'default' exists in all catalogs).

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/0802e01dffa35e89. Report an issue: GitHub.