{"record":{"id":"9ad14d6dd1f1d297","repo":"apache/cassandra","slug":"materialized-view-s-s-doesn-t-exist-9ad14d","errorCode":null,"errorMessage":"Materialized view '%s.%s' doesn't exist","messagePattern":"Materialized view '(.+?)\\.(.+?)' doesn't exist","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/DropViewStatement.java","lineNumber":70,"sourceCode":"        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);\n    }\n\n    @Override\n    public Keyspaces apply(ClusterMetadata metadata)\n    {\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n\n        ViewMetadata view = null == keyspace\n                          ? null\n                          : keyspace.views.getNullable(viewName);\n\n        if (null == view)\n        {\n            if (ifExists)\n                return schema;\n\n            throw ire(\"Materialized view '%s.%s' doesn't exist\", keyspaceName, viewName);\n        }\n\n        return schema.withAddedOrUpdated(keyspace.withSwapped(keyspace.views.without(viewName)));\n    }\n\n    SchemaChange schemaChangeEvent(KeyspacesDiff diff)\n    {\n        return new SchemaChange(Change.DROPPED, Target.TABLE, keyspaceName, viewName);\n    }\n\n    public void authorize(ClientState client)\n    {\n        ViewMetadata view = Schema.instance.getView(keyspaceName, viewName);\n        if (null != view)\n            client.ensureTablePermission(keyspaceName, view.baseTableName, Permission.ALTER);\n    }\n\n    @Override","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/DropViewStatement.java#L52-L88","documentation":"Existence guard in DropViewStatement.apply(): the materialized view named in DROP MATERIALIZED VIEW cannot be resolved — the keyspace is missing or keyspace.views has no entry for viewName. Unless IF EXISTS is given, the statement fails with InvalidRequestException naming the nonexistent view.","triggerScenarios":"Executing DROP MATERIALIZED VIEW <ks>.<view> when keyspace.views has no entry with that name; typo in view name; script re-run after the view was already dropped; using a table name instead of the view name.","commonSituations":"Confusing base table names with view names; typos; running cleanup twice; environments where the view was never created.","solutions":["Add IF EXISTS to make the drop idempotent; verify the view name and keyspace with DESCRIBE MATERIALIZED VIEWS; check whether the view was already dropped or is a plain table sharing the name."],"exampleFix":"// before\nDROP MATERIALIZED VIEW ks.metrics;\n// after\nDROP MATERIALIZED VIEW IF EXISTS ks.metrics_by_day;","handlingStrategy":"validation","validationCode":"var exists = session.execute(\"SELECT view_name FROM system_schema.views WHERE keyspace_name=? AND view_name=?\", ks, view).iterator().hasNext();\nif (exists) session.execute(\"DROP MATERIALIZED VIEW IF EXISTS \" + ks + \".\" + view);","typeGuard":null,"tryCatchPattern":"try { session.execute(ddl); } catch (InvalidRequest e) { if (e.getMessage().contains(\"doesn't exist\")) log.info(\"View already absent\"); else throw e; }","preventionTips":["Always use the view name, not the base table name","Use IF EXISTS in cleanup scripts","List views with system_schema.views before drops"],"tags":["cassandra","cql","ddl","materialized-views"],"backgroundTag":"entity-not-found","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}