{"record":{"id":"b766eca5433554de","repo":"apache/cassandra","slug":"materialized-views-are-not-supported-on-transientl","errorCode":null,"errorMessage":"Materialized views are not supported on transiently replicated keyspaces","messagePattern":"Materialized views are not supported on transiently replicated keyspaces","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java","lineNumber":151,"sourceCode":"    @Override\n    public boolean compatibleWith(ClusterMetadata metadata)\n    {\n        return metadata.directory.commonSerializationVersion.isAtLeast(Version.V0);\n    }\n\n    @Override\n    public Keyspaces apply(ClusterMetadata metadata)\n    {\n        /*\n         * Basic dependency validations\n         */\n        Keyspaces schema = metadata.schema.getKeyspaces();\n        KeyspaceMetadata keyspace = schema.getNullable(keyspaceName);\n        if (null == keyspace)\n            throw ire(\"Keyspace '%s' doesn't exist\", keyspaceName);\n\n        if (keyspace.replicationStrategy.hasTransientReplicas())\n            throw new InvalidRequestException(\"Materialized views are not supported on transiently replicated keyspaces\");\n\n        TableMetadata table = keyspace.tables.getNullable(tableName);\n        if (null == table)\n            throw ire(\"Base table '%s' doesn't exist\", tableName);\n\n        if (keyspace.hasTable(viewName))\n            throw ire(\"Cannot create materialized view '%s' - a table with the same name already exists\", viewName);\n\n        if (keyspace.hasView(viewName))\n        {\n            if (ifNotExists)\n                return schema;\n\n            throw new AlreadyExistsException(keyspaceName, viewName);\n        }\n\n        /*\n         * Base table validation","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java#L133-L169","documentation":"Materialized views are not permitted on keyspaces that use transient replication. MV read/write path assumptions (full replicas for view maintenance) are incompatible with transient replicas, so `CREATE MATERIALIZED VIEW` checks `keyspace.replicationStrategy.hasTransientReplicas()` and throws InvalidRequestException.","triggerScenarios":"`CREATE MATERIALIZED VIEW ks.view AS SELECT ... FROM ks.base WHERE ...;` where the keyspace's replication includes transient replicas (e.g. RF written as `3/1` in NetworkTopologyStrategy).","commonSituations":"Adopting transient replication to cut storage cost, then attempting MV-based denormalization; migration scripts that create views on all keyspaces regardless of replication settings.","solutions":["Remove transient replication: ALTER the keyspace to full replicas and run `nodetool repair -pr -full`, then create the MV.","Create the materialized view in a keyspace with only full replicas.","Replace the MV with application-side denormalization writing to a regular table."],"exampleFix":"-- before\nCREATE MATERIALIZED VIEW ks.v AS SELECT * FROM ks.t WHERE col IS NOT NULL PRIMARY KEY (col, pk);\n\n-- after\nALTER KEYSPACE ks WITH replication = {'class':'NetworkTopologyStrategy','dc1':3};\n-- nodetool repair -full ks\nCREATE MATERIALIZED VIEW ks.v AS SELECT * FROM ks.t WHERE col IS NOT NULL PRIMARY KEY (col, pk);","handlingStrategy":"validation","validationCode":"Row r = session.execute(\"SELECT replication FROM system_schema.keyspaces WHERE keyspace_name='ks'\").one();\nMap<String,String> repl = r.getMap(\"replication\", String.class, String.class);\nif (repl.values().stream().anyMatch(v -> v.contains(\"/\")))\n    throw new IllegalStateException(\"keyspace uses transient replicas; MVs unsupported\");","typeGuard":null,"tryCatchPattern":"try { session.execute(createMv); }\ncatch (InvalidQueryException e) {\n  if (e.getMessage().contains(\"transiently replicated\"))\n      throw new IllegalStateException(\"remove transient replication (ALTER KEYSPACE + repair) before creating MV\", e);\n  throw e;\n}","preventionTips":["Check system_schema.keyspaces.replication for transient RF values before MV DDL","Keep denormalization for transiently-replicated keyspaces application-managed (regular tables)","Standardize on full replicas unless transient savings are explicitly required"],"tags":["cassandra","materialized-view","transient-replication","replication"],"backgroundTag":"unsupported-operation","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"}