{"record":{"id":"3885b61f8f8f51e1","repo":"prestodb/presto","slug":"missing-table-3885b6","errorCode":"MISSING_TABLE","errorMessage":"Table does not exist","messagePattern":"Table does not exist","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/MaterializedViewQueryOptimizer.java","lineNumber":909,"sourceCode":"                if (coercion != null) {\n                    rewritten = new Cast(\n                            original.getLocation(),\n                            rewritten,\n                            coercion.getTypeSignature().toString(),\n                            false,\n                            analysis.isTypeOnlyCoercion(original));\n                }\n                return rewritten;\n            }\n        }\n\n        private Scope extractScope(Table table, QuerySpecification node, Expression whereClause)\n        {\n            QualifiedObjectName baseTableName = createQualifiedObjectName(session, table, table.getName(), metadata);\n\n            Optional<TableHandle> tableHandle = metadata.getMetadataResolver(session).getTableHandle(baseTableName);\n            if (!tableHandle.isPresent()) {\n                throw new SemanticException(MISSING_TABLE, node, \"Table does not exist\");\n            }\n\n            ImmutableList.Builder<Field> fields = ImmutableList.builder();\n\n            for (ColumnHandle columnHandle : metadata.getColumnHandles(session, tableHandle.get()).values()) {\n                ColumnMetadata columnMetadata = metadata.getColumnMetadata(session, tableHandle.get(), columnHandle);\n                fields.add(Field.newUnqualified(whereClause.getLocation(), columnMetadata.getName(), columnMetadata.getType()));\n            }\n\n            return Scope.builder()\n                    .withRelationType(RelationId.anonymous(), new RelationType(fields.build()))\n                    .build();\n        }\n\n        private MaterializedViewStatus getMaterializedViewStatus(QuerySpecification querySpecification)\n        {\n            TupleDomain<String> baseQueryDomain = TupleDomain.all();\n","sourceCodeStart":891,"sourceCodeEnd":927,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/MaterializedViewQueryOptimizer.java#L891-L927","documentation":"extractScope in MaterializedViewQueryOptimizer resolves the base table of a materialized view via the metadata resolver. If the catalog/schema/table name of the base table does not resolve to a TableHandle, the optimizer throws MISSING_TABLE because it cannot build a Scope over a nonexistent base table to rewrite the query.","triggerScenarios":"Querying a materialized view whose underlying base table was dropped, renamed, or lives in a catalog that is not registered in the current session; also when the materialized view definition references a table name that the connector cannot resolve.","commonSituations":"Base table dropped or renamed after the materialized view was created; stale materialized view definitions after schema migrations; missing catalog configuration in the coordinator's catalog directory.","solutions":["Verify the base table exists: run SHOW TABLES / SELECT from the base table directly in the same catalog/schema.","Recreate the missing/renamed base table, or drop and recreate the materialized view pointing at a valid table.","Check the catalog is configured on the coordinator (etc/catalog/<name>.properties) and the connector is loaded."],"exampleFix":"// before (mv_definition references dropped table)\nCREATE MATERIALIZED VIEW mv AS SELECT * FROM staging.events_old;\n// after\nDROP MATERIALIZED VIEW mv;\nCREATE MATERIALIZED VIEW mv AS SELECT * FROM staging.events;","handlingStrategy":"try-catch","validationCode":"// verify the MV's base table resolves before querying\n-- SHOW TABLES FROM <catalog>.<schema>;  -- confirm base table present\n-- SELECT 1 FROM <base_table> LIMIT 1;   -- probes resolution","typeGuard":null,"tryCatchPattern":"try {\n  runQuery(\"SELECT * FROM mv\");\n} catch (SemanticException e) {\n  if (\"MISSING_TABLE\".equals(e.getCode().name())) {\n    // recreate base table or drop/recreate the materialized view\n  } else throw e;\n}","preventionTips":["Run DROP TABLE checks in migration scripts before dropping tables that back materialized views.","Recreate or refresh MVs as part of any base-table rename/drop migration.","Keep catalog configuration consistent across coordinators."],"tags":["materialized-view","missing-table","metadata","catalog"],"backgroundTag":"table-does-not-exist","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}