{"record":{"id":"186eeee2ed61e1fe","repo":"apache/cassandra","slug":"cannot-set-default-time-to-live-for-a-materialized","errorCode":null,"errorMessage":"Cannot set default_time_to_live for a materialized view. Data in a materialized view always expire at the same time than the corresponding data in the parent table.","messagePattern":"Cannot set default_time_to_live for a materialized view\\. Data in a materialized view always expire at the same time than the corresponding data in the parent table\\.","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java","lineNumber":345,"sourceCode":"\n        // See CASSANDRA-13798\n        Set<ColumnMetadata> restrictedNonPrimaryKeyColumns = restrictions.nonPKRestrictedColumns(false);\n        if (!restrictedNonPrimaryKeyColumns.isEmpty() && !MV_ALLOW_FILTERING_NONKEY_COLUMNS_UNSAFE.getBoolean())\n        {\n            throw ire(\"Non-primary key columns can only be restricted with 'IS NOT NULL' (got: %s restricted illegally)\",\n                      join(\",\", transform(restrictedNonPrimaryKeyColumns, ColumnMetadata::toString)));\n        }\n\n        /*\n         * Validate WITH params\n         */\n\n        attrs.validate();\n\n        if (attrs.hasOption(TableParams.Option.DEFAULT_TIME_TO_LIVE)\n            && attrs.getInt(TableParams.Option.DEFAULT_TIME_TO_LIVE.toString(), 0) != 0)\n        {\n            throw ire(\"Cannot set default_time_to_live for a materialized view. \" +\n                      \"Data in a materialized view always expire at the same time than \" +\n                      \"the corresponding data in the parent table.\");\n        }\n\n        /*\n         * Build the thing\n         */\n\n        TableMetadata.Builder builder = TableMetadata.builder(keyspaceName, viewName);\n\n        if (attrs.hasProperty(TableAttributes.ID))\n            builder.id(attrs.getId());\n        else if (!builder.hasId())\n            builder.id(TableId.get(metadata));\n\n        builder.params(attrs.asNewTableParams(keyspaceName))\n               .kind(TableMetadata.Kind.VIEW);\n","sourceCodeStart":327,"sourceCodeEnd":363,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/statements/schema/CreateViewStatement.java#L327-L363","documentation":"default_time_to_live cannot be set on a materialized view. View rows are derived from base rows and must expire exactly when the corresponding base data expires; an independent TTL would create inconsistencies between base table and view.","triggerScenarios":"CREATE MATERIALIZED VIEW ... WITH default_time_to_live = N where N != 0.","commonSituations":"Users copy table WITH options (including default_time_to_live) onto a view definition, expecting per-view TTL control.","solutions":["Remove default_time_to_live from the view's WITH options.","Set default_time_to_live on the BASE table; view data will expire with the base data.","Use per-insert TTLs on base writes; they propagate to view rows automatically."],"exampleFix":"// before\nCREATE MATERIALIZED VIEW mv AS SELECT ... PRIMARY KEY (...) WITH default_time_to_live = 86400;\n// after\nCREATE MATERIALIZED VIEW mv AS SELECT ... PRIMARY KEY (...); // TTL comes from the base table","handlingStrategy":"validation","validationCode":"if (viewOptions.containsKey(\"default_time_to_live\") && !viewOptions.get(\"default_time_to_live\").equals(\"0\"))\n    throw new IllegalArgumentException(\"do not set default_time_to_live on a materialized view\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use view WITH options like CLUSTERING ORDER BY and compaction settings.","Apply TTL policy on the base table."],"tags":["cassandra","cql","ttl","materialized-view"],"backgroundTag":"conflicting-config-options","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T21:17:11.552Z"}