{"record":{"id":"aaa244f3f2e5484f","repo":"apache/cassandra","slug":"cannot-use-s-with-s","errorCode":null,"errorMessage":"Cannot use %s with %s","messagePattern":"Cannot use (.+?) with (.+?)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java","lineNumber":224,"sourceCode":"                                            ? IndexRegistry.obtain(table)\n                                            : null;\n        /*\n         * WHERE clause. For a given entity, rules are:\n         *   - EQ relation conflicts with anything else (including a 2nd EQ)\n         *   - Can't have more than one LT(E) relation (resp. GT(E) relation)\n         *   - IN relation are restricted to row keys (for now) and conflicts with anything else (we could\n         *     allow two IN for the same entity but that doesn't seem very useful)\n         *   - The value_alias cannot be restricted in any way (we don't support wide rows with indexed value\n         *     in CQL so far)\n         *   - CONTAINS and CONTAINS_KEY cannot be used with UPDATE or DELETE\n         */\n        for (Relation relation : whereClause.relations)\n        {\n\n            Operator operator = relation.operator();\n            if (operator.requiresFilteringOrIndexingFor(ColumnMetadata.Kind.CLUSTERING) && (type.isUpdate() || type.isDelete()))\n            {\n                throw invalidRequest(\"Cannot use %s with %s\", type, operator);\n            }\n\n            if (operator == Operator.IS_NOT)\n            {\n                if (!forView)\n                    throw new InvalidRequestException(\"Unsupported restriction: \" + relation);\n\n                this.notNullColumns.addAll(relation.toRestriction(table, boundNames, owner, allowFiltering).columns());\n            }\n            else if (operator.requiresIndexing())\n            {\n                Restriction restriction = relation.toRestriction(table, boundNames, owner, allowFiltering);\n\n                if (!type.allowUseOfSecondaryIndices() || !restriction.hasSupportingIndex(indexRegistry, indexHints))\n                    throw invalidRequest(\"%s restriction is only supported on properly \" +\n                                                        \"indexed columns. %s is not valid.\", operator, relation);\n\n                addRestriction(restriction, indexRegistry, indexHints);","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java#L206-L242","documentation":"Thrown from the StatementRestrictions constructor when an UPDATE or DELETE WHERE clause uses an operator that requires filtering/indexing on clustering columns (e.g. non-equality operators like >, <, IN on non-full primary key). Modifications only support exact primary-key restrictions; such operators would need a scan to pick rows, which is disallowed.","triggerScenarios":"`UPDATE t SET v=1 WHERE k=0 AND c>1`, `DELETE FROM t WHERE k=0 AND c IN (1,2)` on non-full clustering key, or any ALLOW FILTERING-style relation in an UPDATE/DELETE WHERE clause.","commonSituations":"Porting SELECT patterns (range/IN restrictions) directly to UPDATE/DELETE; trying to bulk-delete a range of clustering rows; scripts generated from SELECT queries reused for cleanup.","solutions":["Restrict the WHERE clause to full equality on all primary key columns (partition key + clustering key).","To delete a range, first SELECT the exact primary keys (with ALLOW FILTERING if needed), then issue one DELETE per key.","Redesign the schema so the rows you want to modify share a directly addressable primary key, or use a secondary table.","Use TTL or partition deletion if the intent is bulk expiry of data."],"exampleFix":"// before\nUPDATE t SET v = 1 WHERE k = 0 AND c > 1;\n// after\nSELECT k, c FROM t WHERE k = 0 AND c > 1 ALLOW FILTERING;\n-- then per row:\nUPDATE t SET v = 1 WHERE k = 0 AND c = ?;","handlingStrategy":"validation","validationCode":"// ensure every primary key column has an equality restriction before UPDATE/DELETE\nif (!hasFullPrimaryKeyEquality(restrictions)) throw new IllegalStateException(\"UPDATE/DELETE requires full primary key equality\");","typeGuard":null,"tryCatchPattern":"try { session.execute(update); } catch (InvalidRequestException e) { if (e.getMessage().startsWith(\"Cannot use\")) fallbackToSelectThenDelete(); else throw e; }","preventionTips":["Only issue modifications with fully-specified primary keys.","Implement range cleanup via select-then-delete loops.","Never copy SELECT WHERE clauses into UPDATE/DELETE."],"tags":["cql","invalid-request","update","delete","filtering"],"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"}