{"record":{"id":"95913d69a7b245a7","repo":"apache/cassandra","slug":"allowfilteringmessage-state","errorCode":null,"errorMessage":"allowFilteringMessage(state)","messagePattern":"allowFilteringMessage\\(state\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java","lineNumber":600,"sourceCode":"            if (partitionKeyRestrictions.isOnToken())\n                isKeyRange = true;\n\n            if (partitionKeyRestrictions.isEmpty() && partitionKeyRestrictions.hasUnrestrictedPartitionKeyComponents())\n            {\n                isKeyRange = true;\n                usesSecondaryIndexing = hasQueriableIndex;\n            }\n\n            // If there is a queriable index, no special condition is required on the other restrictions.\n            // But we still need to know 2 things:\n            // - If we don't have a queriable index, is the query ok\n            // - Is it queriable without 2ndary index, which is always more efficient\n            // If a component of the partition key is restricted by a relation, all preceding\n            // components must have a EQ. Only the last partition key component can be in IN relation.\n            if (partitionKeyRestrictions.needFiltering())\n            {\n                if (!allowFiltering && !forView && !hasQueriableIndex && requiresAllowFilteringIfNotSpecified(table, true))\n                    throw new InvalidRequestException(allowFilteringMessage(state));\n\n                isKeyRange = true;\n                usesSecondaryIndexing = hasQueriableIndex;\n            }\n        }\n    }\n\n    public boolean hasPartitionKeyRestrictions()\n    {\n        return !partitionKeyRestrictions.isEmpty();\n    }\n\n    /**\n     * Checks if the restrictions contain any non-primary key restrictions\n     * @return <code>true</code> if the restrictions contain any non-primary key restrictions, <code>false</code> otherwise.\n     */\n    public boolean hasNonPrimaryKeyRestrictions()\n    {","sourceCodeStart":582,"sourceCodeEnd":618,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java#L582-L618","documentation":"When the partition key restrictions require filtering (e.g. partial prefix or non-EQ on a key component) and ALLOW FILTERING was not specified, the statement is rejected with the dynamic allowFilteringMessage(state) text. Such queries would require an unbounded full scan, so Cassandra demands explicit opt-in (or a queriable secondary index, or being a view definition).","triggerScenarios":"A SELECT whose partition key restrictions need filtering (needFiltering() true), with allowFiltering == false, not for a view, no queriable index on the restricted columns, and the table requires allow-filtering unless specified.","commonSituations":"Queries like 'WHERE pk > x' or restricted only on the second component of a composite partition key without ALLOW FILTERING; common when porting SQL habits or after key schema changes.","solutions":["Add ALLOW FILTERING to the statement (accepting the performance cost).","Restrict the full partition key with EQ (and IN on the last component only) so filtering is unnecessary.","Create/use a secondary index on the filtered column so hasQueriableIndex becomes true.","Redesign the table so the query matches the partition key layout."],"exampleFix":"// before\nSELECT * FROM sensor_data WHERE device_id > 100;\n// after\nSELECT * FROM sensor_data WHERE device_id = 123; // or\nSELECT * FROM sensor_data WHERE device_id > 100 ALLOW FILTERING;","handlingStrategy":"validation","validationCode":"if (!isFullPartitionKeyEquality(whereClause) && !allowFilteringRequested)\n    throw new IllegalArgumentException(\"this query needs ALLOW FILTERING or a full partition key\");","typeGuard":null,"tryCatchPattern":"try { session.execute(stmt); }\ncatch (InvalidRequestException e) {\n    if (e.getMessage().toLowerCase().contains(\"allow filtering\")) { /* retry with ALLOW FILTERING or fix the predicate */ }\n    else throw e;\n}","preventionTips":["Design tables around the queries: use EQ on the full partition key.","Add ALLOW FILTERING only knowingly, never by default in query builders.","Create secondary indexes for columns that need non-key filtering."],"tags":["cassandra","cql","allow-filtering","partition-key"],"backgroundTag":"feature-not-enabled","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}