{"record":{"id":"3c170823dfe9a1d4","repo":"apache/cassandra","slug":"cannot-index-value-of-size-d-for-index-s-on-s","errorCode":null,"errorMessage":"Cannot index value of size %d for index %s on %s(%s) (maximum allowed size=%d)","messagePattern":"Cannot index value of size (.+?) for index (.+?) on (.+?)\\((.+?)\\) \\(maximum allowed size=(.+?)\\)","errorType":"validation","errorClass":"InvalidRequestException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/index/internal/CassandraIndex.java","lineNumber":636,"sourceCode":"                if (data != null)\n                {\n                    for (Cell<?> cell : data)\n                    {\n                        validateIndexedValue(getIndexedValue(null, null, cell.path(), cell.buffer()));\n                    }\n                }\n            }\n            else\n            {\n                validateIndexedValue(getIndexedValue(null, null, row.getCell(indexedColumn)));\n            }\n        }\n    }\n\n    private void validateIndexedValue(ByteBuffer value)\n    {\n        if (value != null && value.remaining() >= FBUtilities.MAX_UNSIGNED_SHORT)\n            throw new InvalidRequestException(String.format(\n                                                           \"Cannot index value of size %d for index %s on %s(%s) (maximum allowed size=%d)\",\n                                                           value.remaining(),\n                                                           metadata.name,\n                                                           baseCfs.metadata,\n                                                           indexedColumn.name.toString(),\n                                                           FBUtilities.MAX_UNSIGNED_SHORT));\n    }\n\n    private ByteBuffer getIndexedValue(ByteBuffer rowKey,\n                                       Clustering<?> clustering,\n                                       Cell<?> cell)\n    {\n        return getIndexedValue(rowKey,\n                               clustering,\n                               cell == null ? null : cell.path(),\n                               cell == null ? null : cell.buffer()\n        );\n    }","sourceCodeStart":618,"sourceCodeEnd":654,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/index/internal/CassandraIndex.java#L618-L654","documentation":"CassandraIndex.validateIndexedValue rejects any indexed value whose serialized size is >= FBUtilities.MAX_UNSIGNED_SHORT (65535 bytes), because secondary index entries store the value in a length-prefixed structure limited to unsigned-short size. Thrown as InvalidRequestException during statement validation before execution.","triggerScenarios":"INSERT/UPDATE where the value of an indexed column is >= 65535 bytes serialized (large text/blob, big frozen collection); validatePartitionKey, validateClusterings, or validateRows hit it depending on which part is indexed.","commonSituations":"Indexing a blob or free-text column that grows large in production; indexing frozen collections that exceed 64KB; writes that previously passed before data grew.","solutions":["Remove the index from the large column and query it by other means","Reduce the size of the indexed value (truncate, hash it, or store out-of-band and index a reference key)","Use Storage-Attached Indexes (SAI), which have different size constraints, if appropriate","Split the data into a separate table keyed by the large value"],"exampleFix":"// before\nCREATE INDEX ON messages (payload); // payload blob often >64KB\n// after\nCREATE INDEX ON messages (payload_hash); // index a small derived key instead","handlingStrategy":"validation","validationCode":"if (value != null && value.remaining() >= 65535) throw new IllegalArgumentException(\"Indexed value too large: \" + value.remaining());","typeGuard":null,"tryCatchPattern":"try { session.execute(insert); } catch (InvalidRequestException e) { if (e.getMessage().contains(\"Cannot index value of size\")) { /* drop index or shrink value */ } else throw e; }","preventionTips":["Do not index free-form blob/text columns that can exceed 64KB","Index a hash or short derived key instead of the raw large value","Add application-side size checks before writing indexed columns"],"tags":["cassandra","index","size-limit","invalid-request"],"backgroundTag":"value-out-of-range","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"}