{"record":{"id":"1d51e16eede2eb57","repo":"apache/cassandra","slug":"cannot-execute-this-query-as-it-might-involve-data","errorCode":null,"errorMessage":"Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING","messagePattern":"Cannot execute this query as it might involve data filtering and thus may have unpredictable performance\\. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java","lineNumber":377,"sourceCode":"            else\n            {\n                // We do not support indexed vector restrictions that are not part of an ANN ordering\n                Optional<ColumnMetadata> vectorColumn = nonPrimaryKeyRestrictions.columns()\n                                                                                 .stream()\n                                                                                 .filter(c -> c.type.isVector())\n                                                                                 .findFirst();\n                if (vectorColumn.isPresent() && indexRegistry.listIndexes().stream().anyMatch(i -> i.dependsOn(vectorColumn.get())))\n                    throw invalidRequest(StatementRestrictions.VECTOR_INDEXES_ANN_ONLY_MESSAGE);\n            }\n\n            if (hasQueriableIndex)\n            {\n                usesSecondaryIndexing = true;\n            }\n            else\n            {\n                if (!allowFiltering && requiresAllowFilteringIfNotSpecified(table, false))\n                    throw invalidRequest(allowFilteringMessage(state));\n            }\n\n            filterRestrictions.add(nonPrimaryKeyRestrictions);\n        }\n\n        if (usesSecondaryIndexing)\n            validateSecondaryIndexSelections();\n    }\n\n    public static boolean requiresAllowFilteringIfNotSpecified(TableMetadata metadata, boolean isPrimaryKey)\n    {\n        if (!metadata.isVirtual())\n            return true;\n\n        VirtualTable tableNullable = VirtualKeyspaceRegistry.instance.getTableNullable(metadata.id);\n        assert tableNullable != null;\n        return isPrimaryKey ? !tableNullable.allowFilteringPrimaryKeysImplicitly() : !tableNullable.allowFilteringImplicitly();\n    }","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/StatementRestrictions.java#L359-L395","documentation":"Cassandra refuses queries whose restrictions would require scanning and filtering non-key rows without an index, because performance is unpredictable. When non-primary-key column restrictions exist, no queriable index covers them, and ALLOW FILTERING was not specified, StatementRestrictions throws this error.","triggerScenarios":"SELECT * FROM t WHERE regular_col = 'x' with no index on regular_col and no ALLOW FILTERING; also clustering-column slices in statements that don't allow them without filtering.","commonSituations":"New developers querying by non-key columns as if it were SQL; schema changes that dropped an index the query relied on; ad-hoc debugging queries in cqlsh.","solutions":["Create an index on the filtered column: CREATE INDEX / CREATE CUSTOM INDEX ... USING 'StorageAttachedIndex'","Denormalize: add the column to the primary key in a query table","Append ALLOW FILTERING if the filtered dataset is provably small and performance is acceptable","Use a separate search system (e.g. SAI + vector or external index) for high-cardinality filters"],"exampleFix":"// before\nSELECT * FROM users WHERE email = 'a@b.com';\n// after\nCREATE CUSTOM INDEX users_email_idx ON users (email) USING 'StorageAttachedIndex';\nSELECT * FROM users WHERE email = 'a@b.com';","handlingStrategy":"validation","validationCode":"// Check every WHERE column is part of the primary key or has an index before executing;\n// consult system_schema.indexes for the table.","typeGuard":null,"tryCatchPattern":"catch (InvalidRequestException e) {\n  if (e.getMessage().contains(\"ALLOW FILTERING\")) {\n    // create index or rewrite query; do not blindly append ALLOW FILTERING\n  }\n}","preventionTips":["Index or denormalize columns used in WHERE clauses","Never add ALLOW FILTERING reflexively — quantify the scanned data first","Keep data model and query patterns aligned (query-driven modeling)"],"tags":["cql","cassandra","filtering","indexing"],"backgroundTag":"database-query-failed","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"}