{"record":{"id":"ce9ef818e2ee1847","repo":"apache/cassandra","slug":"s-is-only-supported-on-properly-indexed-columns-o","errorCode":null,"errorMessage":"%s is only supported on properly indexed columns or with ALLOW FILTERING","messagePattern":"(.+?) is only supported on properly indexed columns or with ALLOW FILTERING","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java","lineNumber":397,"sourceCode":"        ColumnMetadata column = firstColumn();\n        switch (columnsExpression.kind())\n        {\n            case SINGLE_COLUMN:\n                List<ByteBuffer> buffers = bindAndGet(context);\n                if (operator.kind() != Operator.Kind.BINARY)\n                {\n                    if (operator == Operator.IN && !column.type.isCounter())\n                        buffers.sort(column.type);\n                    filter.add(column, operator, multiInputOperatorValues(column, buffers));\n                }\n                else if (operator == Operator.LIKE)\n                {\n                    LikePattern pattern = LikePattern.parse(buffers.get(0));\n                    \n                    RowFilter.SimpleExpression expression = filter.add(column, pattern.kind().operator(), pattern.value());\n                    Optional<Index> index = indexRegistry.getBestIndexFor(expression, indexHints);\n                    if(!index.isPresent() && !allowFiltering)\n                        throw invalidRequest(\"%s is only supported on properly indexed columns or with ALLOW FILTERING\", expression);\n                }\n                else\n                {\n                    filter.add(column, operator, buffers.get(0));\n                }\n                break;\n            case MULTI_COLUMN:\n                checkFalse(isSlice(), \"Multi-column slice restrictions cannot be used for filtering.\");\n\n                if (isEQ())\n                {\n                    List<ByteBuffer> elements = bindAndGetElements(context).get(0);\n\n                    for (int i = 0, m = columns().size(); i < m; i++)\n                    {\n                        ColumnMetadata columnDef = columns().get(i);\n                        filter.add(columnDef, Operator.EQ, elements.get(i));\n                    }","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/cql3/restrictions/SimpleRestriction.java#L379-L415","documentation":"When a LIKE restriction is added to the RowFilter, Cassandra looks for a suitable index for the LIKE expression; if none exists and ALLOW FILTERING was not specified, the query is rejected. LIKE must be backed by a compatible index (e.g. SASI/SAI) or the user must opt into unindexed filtering.","triggerScenarios":"SELECT ... WHERE text_col LIKE '%foo%' without a LIKE-capable index on text_col and without ALLOW FILTERING.","commonSituations":"Full-text-style search added after the fact with no SAI/SASI index created; schema migrations where the index was dropped; assumptions that LIKE works like SQL on any text column.","solutions":["Create a supporting index (e.g. SAI LIKE-capable index) on the column","Append ALLOW FILTERING to the query (full scan; use cautiously on large tables)","Replace LIKE with an indexed equality/prefix strategy (e.g. dedicated search column)"],"exampleFix":"// before\nSELECT * FROM users WHERE name LIKE '%son%';\n// after\nCREATE INDEX IF NOT EXISTS users_name_idx ON users (name) USING 'sai' WITH OPTIONS = {'case_sensitive': false};\nSELECT * FROM users WHERE name LIKE '%son%';","handlingStrategy":"validation","validationCode":"// check schema before issuing LIKE\nIndexMetadata idx = schema.getIndex(column);\nif (idx == null || !idx.supportsLike()) requireAllowFilteringOrReject();","typeGuard":null,"tryCatchPattern":"catch (InvalidRequestException e) { if (e.getMessage().contains(\"only supported on properly indexed\")) createIndexOrAddAllowFiltering(); }","preventionTips":["Create a LIKE-capable index (SAI) before deploying LIKE queries","Avoid ALLOW FILTERING as a default on large tables","Include schema checks in query-layer tests"],"tags":["cql","like-operator","secondary-index","allow-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"}