prestodb/presto · error · PrestoException

NOT_FOUND

NOT_FOUND

Error message

Materialized view not found: 

What it means

The incremental materialized-view refresh rule resolves the view definition from metadata before planning the incremental refresh. If the referenced materialized view no longer exists in the catalog, it throws NOT_FOUND with the qualified view name.

Source

Thrown at presto-main-base/src/main/java/com/facebook/presto/sql/planner/iterative/rule/materializedview/IncrementalRefreshRule.java:135

    {
        Session session = context.getSession();
        PlanNodeIdAllocator idAllocator = context.getIdAllocator();
        VariableAllocator variableAllocator = context.getVariableAllocator();

        SchemaTableName materializedViewName = node.getMaterializedViewName();
        TableHandle storageTableHandle = node.getStorageTableHandle();
        String catalogName = storageTableHandle.getConnectorId().getCatalogName();

        QualifiedObjectName qualifiedViewName = new QualifiedObjectName(
                catalogName,
                materializedViewName.getSchemaName(),
                materializedViewName.getTableName());

        MetadataResolver metadataResolver = metadata.getMetadataResolver(session);

        Optional<MaterializedViewDefinition> materializedViewDefinition = metadataResolver.getMaterializedView(qualifiedViewName);
        if (!materializedViewDefinition.isPresent()) {
            throw new PrestoException(NOT_FOUND, "Materialized view not found: " + qualifiedViewName);
        }

        MaterializedViewRefreshType refreshType = materializedViewDefinition.get().getRefreshType()
                .orElseGet(() -> getMaterializedViewDefaultRefreshType(session));
        if (refreshType != MaterializedViewRefreshType.INCREMENTAL) {
            return Result.ofPlanNode(node.getSource());
        }

        MaterializedViewStatus status = metadataResolver.getMaterializedViewStatus(qualifiedViewName, TupleDomain.all());

        // If fully materialized, nothing to refresh - return empty result
        if (status.isFullyMaterialized()) {
            return Result.ofPlanNode(new ValuesNode(
                    node.getSourceLocation(),
                    idAllocator.getNextId(),
                    node.getOutputVariables(),
                    ImmutableList.of(),
                    Optional.empty()));

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Verify the materialized view exists: SHOW CREATE TABLE <catalog.schema.view>
  2. Recreate the materialized view if it was dropped
  3. Check the qualified name (catalog/schema/table) for typos or wrong catalog in the connection

Example fix

// before
SELECT * FROM hive.sales.mv_daily_revenue; -- dropped
// after
CREATE MATERIALIZED VIEW hive.sales.mv_daily_revenue AS SELECT ...;
SELECT * FROM hive.sales.mv_daily_revenue;
Defensive patterns

Strategy: validation

Validate before calling

SELECT * FROM system.metadata.materialized_views WHERE name = '<view>'; -- check existence first

Type guard

null

Try / catch

try {
    return query("SELECT * FROM mv");
} catch (PrestoException e) {
    if (e.getErrorCode() == NOT_FOUND.toErrorCode()) {
        recreateMaterializedView();
        return retryQuery("SELECT * FROM mv");
    }
    throw e;
}

Prevention

When it happens

Trigger: Querying a materialized view whose definition was dropped/renamed between planning steps, or when a stale plan/cache references a view that no longer resolves via metadata.getMaterializedView.

Common situations: Materialized view dropped while a query against it was in flight; typo'd schema/table in the name; connect privilege issues causing lookup to miss the view.

Understand the failure class

Background: NOT_FOUND error code: why tRPC, Harbor, Nacos and other libraries return 404 "not found" errors for resources that may still exist — this error's family across 11 libraries.

Related errors


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